refactor: Fix and suppress warnings

This commit is contained in:
LisoUseInAIKyrios 2024-04-24 14:36:00 +04:00
parent 24e1c952d5
commit 003a84305d
37 changed files with 63 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import android.os.Build;
import androidx.annotation.RequiresApi;
@SuppressWarnings("unused")
public final class RemoveScreencaptureRestrictionPatch {
// Member of AudioAttributes.Builder
@RequiresApi(api = Build.VERSION_CODES.Q)

View File

@ -3,6 +3,7 @@ package app.revanced.integrations.all.screenshot.removerestriction;
import android.view.Window;
import android.view.WindowManager;
@SuppressWarnings("unused")
public class RemoveScreenshotRestrictionPatch {
public static void addFlags(Window window, int flags) {

View File

@ -5,8 +5,12 @@ import com.reddit.domain.model.ILink;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unused")
public final class FilterPromotedLinksPatch {
/**
* Injection point.
*
* Filters list from promoted links.
**/
public static List<?> filterChildren(final Iterable<?> links) {

View File

@ -138,7 +138,11 @@ public class GmsCoreSupport {
}
}
// Modified by a patch. Do not touch.
/**
* Modified by a patch. Do not touch.
*
* @noinspection SameReturnValue
*/
private static String getGmsCoreVendorGroupId() {
return "app.revanced";
}

View File

@ -52,6 +52,7 @@ public class Utils {
* Injection point.
*
* @return The manifest 'Version' entry of the patches.jar used during patching.
* @noinspection SameReturnValue
*/
public static String getPatchesReleaseVersion() {
return ""; // Value is replaced during patching.

View File

@ -6,7 +6,12 @@ import app.revanced.integrations.shared.Logger;
import java.net.HttpURLConnection;
import java.net.URL;
@SuppressWarnings("unused")
public final class FixSLinksPatch {
/**
* Injection point.
*/
public static String resolveSLink(String link) {
if (link.matches(".*reddit\\.com/r/[^/]+/s/[^/]+")) {
Logger.printInfo(() -> "Resolving " + link);

View File

@ -3,6 +3,7 @@ package app.revanced.integrations.tiktok.feedfilter;
import app.revanced.integrations.tiktok.settings.Settings;
import com.ss.android.ugc.aweme.feed.model.Aweme;
/** @noinspection unused*/
public class AdsFilter implements IFilter {
@Override
public boolean getEnabled() {

View File

@ -6,6 +6,7 @@ import com.ss.android.ugc.aweme.feed.model.FeedItemList;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("unused")
public final class FeedItemsFilter {
private static final List<IFilter> FILTERS = List.of(
new AdsFilter(),
@ -16,6 +17,9 @@ public final class FeedItemsFilter {
new LikeCountFilter()
);
/**
* Injection point.
*/
public static void filter(FeedItemList feedItemList) {
Iterator<Aweme> feedItemListIterator = feedItemList.items.iterator();
while (feedItemListIterator.hasNext()) {

View File

@ -3,6 +3,7 @@ package app.revanced.integrations.tiktok.feedfilter;
import app.revanced.integrations.tiktok.settings.Settings;
import com.ss.android.ugc.aweme.feed.model.Aweme;
@SuppressWarnings("unused")
public class ImageVideoFilter implements IFilter {
@Override
public boolean getEnabled() {

View File

@ -3,6 +3,7 @@ package app.revanced.integrations.tiktok.feedfilter;
import app.revanced.integrations.tiktok.settings.Settings;
import com.ss.android.ugc.aweme.feed.model.Aweme;
@SuppressWarnings("unused")
public class LiveFilter implements IFilter {
@Override
public boolean getEnabled() {

View File

@ -1,5 +1,6 @@
package app.revanced.integrations.tiktok.settings;
@SuppressWarnings("unused")
public class SettingsStatus {
public static boolean feedFilterEnabled = false;
public static boolean downloadEnabled = false;
@ -17,6 +18,7 @@ public class SettingsStatus {
simSpoofEnabled = true;
}
/** @noinspection EmptyMethod*/
public static void load() {
}

View File

@ -14,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Preference fragment for ReVanced settings
*/
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "unused"})
public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
@Override
@ -33,6 +33,7 @@ public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
}
@Override
@SuppressWarnings("unused")
protected void initialize() {
final var context = getContext();

View File

@ -4,7 +4,7 @@ import android.content.Context;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "unused"})
public abstract class ConditionalPreferenceCategory extends PreferenceCategory {
public ConditionalPreferenceCategory(Context context, PreferenceScreen screen) {
super(context);

View File

@ -7,7 +7,7 @@ import app.revanced.integrations.tiktok.settings.SettingsStatus;
import app.revanced.integrations.tiktok.settings.preference.DownloadPathPreference;
import app.revanced.integrations.tiktok.settings.preference.TogglePreference;
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "unused"})
public class DownloadsPreferenceCategory extends ConditionalPreferenceCategory {
public DownloadsPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);

View File

@ -7,7 +7,7 @@ import app.revanced.integrations.tiktok.settings.Settings;
import app.revanced.integrations.tiktok.settings.SettingsStatus;
import app.revanced.integrations.tiktok.settings.preference.TogglePreference;
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "unused"})
public class FeedFilterPreferenceCategory extends ConditionalPreferenceCategory {
public FeedFilterPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);

View File

@ -6,7 +6,7 @@ import android.preference.PreferenceScreen;
import app.revanced.integrations.shared.settings.BaseSettings;
import app.revanced.integrations.tiktok.settings.preference.TogglePreference;
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "unused"})
public class IntegrationsPreferenceCategory extends ConditionalPreferenceCategory {
public IntegrationsPreferenceCategory(Context context, PreferenceScreen screen) {
super(context, screen);

View File

@ -2,7 +2,9 @@ package app.revanced.integrations.tiktok.speed;
import app.revanced.integrations.tiktok.settings.Settings;
@SuppressWarnings("unused")
public class PlaybackSpeedPatch {
public static void rememberPlaybackSpeed(float newSpeed) {
Settings.REMEMBERED_SPEED.save(newSpeed);
}

View File

@ -7,6 +7,7 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
/** @noinspection unused*/
public class CustomPreferenceCategory extends PreferenceCategory {
public CustomPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);

View File

@ -10,6 +10,7 @@ import app.revanced.integrations.twitch.settings.Settings;
public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
@Override
@SuppressWarnings("unused")
protected void initialize() {
super.initialize();

View File

@ -4,7 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
@SuppressWarnings("unused")
public final class OpenLinksWithAppChooserPatch {
public static void openWithChooser(final Context context, final Intent intent) {
Log.d("ReVanced", "Opening intent with chooser: " + intent);

View File

@ -38,6 +38,7 @@ public class ThemeHelper {
/**
* Injection point.
* @noinspection SameReturnValue
*/
private static String darkThemeResourceName() {
// Value is changed by Theme patch, if included.
@ -57,6 +58,7 @@ public class ThemeHelper {
/**
* Injection point.
* @noinspection SameReturnValue
*/
private static String lightThemeResourceName() {
// Value is changed by Theme patch, if included.

View File

@ -380,7 +380,7 @@ public abstract class TrieSearch<T> {
throw new IllegalArgumentException("endIndex: " + endIndex
+ " is greater than texToSearchLength: " + textToSearchLength);
}
if (patterns.size() == 0) {
if (patterns.isEmpty()) {
return false; // No patterns were added.
}
for (int i = startIndex; i < endIndex; i++) {
@ -393,7 +393,7 @@ public abstract class TrieSearch<T> {
* @return Estimated memory size (in kilobytes) of this instance.
*/
public int getEstimatedMemorySize() {
if (patterns.size() == 0) {
if (patterns.isEmpty()) {
return 0;
}
// Assume the device has less than 32GB of ram (and can use pointer compression),

View File

@ -18,7 +18,7 @@ public class BypassURLRedirectsPatch {
public static Uri parseRedirectUri(String uri) {
final var parsed = Uri.parse(uri);
if (Settings.BYPASS_URL_REDIRECTS.get() && parsed.getPath().equals(YOUTUBE_REDIRECT_PATH)) {
if (Settings.BYPASS_URL_REDIRECTS.get() && YOUTUBE_REDIRECT_PATH.equals(parsed.getPath())) {
var query = Uri.parse(Uri.decode(parsed.getQueryParameter("q")));
Logger.printDebug(() -> "Bypassing YouTube redirect URI: " + query);

View File

@ -7,6 +7,7 @@ import app.revanced.integrations.youtube.patches.playback.speed.CustomPlaybackSp
/**
* Abuse LithoFilter for {@link CustomPlaybackSpeedPatch}.
*/
@SuppressWarnings("unused")
public final class PlaybackSpeedMenuFilterPatch extends Filter {
// Must be volatile or synchronized, as litho filtering runs off main thread and this field is then access from the main thread.
public static volatile boolean isPlaybackSpeedMenuVisible;

View File

@ -26,6 +26,7 @@ import app.revanced.integrations.youtube.TrieSearch;
*
* Once a way to asynchronously update litho text is found, this strategy will no longer be needed.
*/
@SuppressWarnings("unused")
public final class ReturnYouTubeDislikeFilterPatch extends Filter {
/**

View File

@ -69,7 +69,7 @@ public class ReturnYouTubeDislike {
* Maximum amount of time to block the UI from updates while waiting for network call to complete.
*
* Must be less than 5 seconds, as per:
* https://developer.android.com/topic/performance/vitals/anr
* <a href="https://developer.android.com/topic/performance/vitals/anr">...</a>
*/
private static final long MAX_MILLISECONDS_TO_BLOCK_UI_WAITING_FOR_FETCH = 4000;

View File

@ -147,6 +147,7 @@ public class ReturnYouTubeDislikeApi {
*/
private static void randomlyWaitIfLocallyDebugging() {
final boolean DEBUG_RANDOMLY_DELAY_NETWORK_CALLS = false; // set true to debug UI
//noinspection ConstantValue
if (DEBUG_RANDOMLY_DELAY_NETWORK_CALLS) {
final long amountOfTimeToWaste = (long) (Math.random()
* (API_GET_VOTES_TCP_TIMEOUT_MILLISECONDS + API_GET_VOTES_HTTP_TIMEOUT_MILLISECONDS));
@ -187,6 +188,7 @@ public class ReturnYouTubeDislikeApi {
*/
private static boolean checkIfRateLimitWasHit(int httpResponseCode) {
final boolean DEBUG_RATE_LIMIT = false; // set to true, to verify rate limit works
//noinspection ConstantValue
if (DEBUG_RATE_LIMIT) {
final double RANDOM_RATE_LIMIT_PERCENTAGE = 0.2; // 20% chance of a triggering a rate limit
if (Math.random() < RANDOM_RATE_LIMIT_PERCENTAGE) {
@ -569,7 +571,11 @@ public class ReturnYouTubeDislikeApi {
throw new IllegalStateException("Failed to solve puzzle challenge: " + challenge + " difficulty: " + difficulty);
}
// https://stackoverflow.com/a/157202
/**
* <a href="https://stackoverflow.com/a/157202">...</a>
*
* @noinspection SameParameterValue
*/
private static String randomString(int len) {
String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
SecureRandom rnd = new SecureRandom();

View File

@ -3,13 +3,11 @@ package app.revanced.integrations.youtube.settings.preference;
import android.os.Build;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import androidx.annotation.RequiresApi;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment;
import app.revanced.integrations.youtube.patches.DownloadsPatch;
import app.revanced.integrations.youtube.patches.playback.speed.CustomPlaybackSpeedPatch;
import app.revanced.integrations.youtube.settings.Settings;
@ -21,6 +19,7 @@ import app.revanced.integrations.youtube.settings.Settings;
public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
@RequiresApi(api = Build.VERSION_CODES.O)
@SuppressWarnings("unused")
@Override
protected void initialize() {
super.initialize();

View File

@ -46,7 +46,7 @@ enum class PlayerType {
companion object {
private val nameToPlayerType = values().associateBy { it.name }
private val nameToPlayerType = entries.associateBy { it.name }
@JvmStatic
fun setFromString(enumName: String) {

View File

@ -22,7 +22,7 @@ enum class VideoState {
companion object {
private val nameToVideoState = values().associateBy { it.name }
private val nameToVideoState = entries.associateBy { it.name }
@JvmStatic
fun setFromString(enumName: String) {

View File

@ -182,6 +182,7 @@ public class SegmentPlaybackController {
* Injection point.
* Initializes SponsorBlock when the video player starts playing a new video.
*/
@SuppressWarnings("unused")
public static void initialize(Object ignoredPlayerController) {
try {
Utils.verifyOnMainThread();

View File

@ -113,6 +113,7 @@ public class SBRequester {
// Could benefit from:
// 1) collection of YouTube videos with test segment times (verify client skip timing matches the video, verify seekbar draws correctly)
// 2) unit tests (verify everything else)
//noinspection ConstantValue
if (false) {
segments.clear();
// Test auto-hide skip button:

View File

@ -14,6 +14,7 @@ import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.videoplayer.BottomControlButton;
/** @noinspection unused*/
public class CreateSegmentButtonController {
private static WeakReference<ImageView> buttonReference = new WeakReference<>(null);
private static boolean isShowing;

View File

@ -92,6 +92,7 @@ public class SkipSponsorButton extends FrameLayout {
public boolean updateSkipButtonText(@NonNull SponsorSegment segment) {
this.segment = segment;
CharSequence newText = segment.getSkipButtonText();
//noinspection StringEqualsCharSequence
if (newText.equals(skipSponsorTextView.getText())) {
return false;
}

View File

@ -29,9 +29,7 @@ public class VotingButtonController {
ImageView imageView = Objects.requireNonNull(youtubeControlsLayout.findViewById(
getResourceIdentifier("revanced_sb_voting_button", "id")));
imageView.setVisibility(View.GONE);
imageView.setOnClickListener(v -> {
SponsorBlockUtils.onVotingClicked(v.getContext());
});
imageView.setOnClickListener(v -> SponsorBlockUtils.onVotingClicked(v.getContext()));
buttonReference = new WeakReference<>(imageView);
} catch (Exception ex) {

View File

@ -9,6 +9,7 @@ import app.revanced.integrations.youtube.patches.CopyVideoUrlPatch;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;
/** @noinspection unused*/
public class CopyVideoUrlButton extends BottomControlButton {
@Nullable
private static CopyVideoUrlButton instance;

View File

@ -9,6 +9,7 @@ import app.revanced.integrations.youtube.patches.CopyVideoUrlPatch;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;
/** @noinspection unused*/
public class CopyVideoUrlTimestampButton extends BottomControlButton {
@Nullable
private static CopyVideoUrlTimestampButton instance;