Skip to content

Commit

Permalink
fix(YouTube - Hide interstitial ads): Prevent app crash if hiding int…
Browse files Browse the repository at this point in the history
…erstitial ads is not possible
  • Loading branch information
YT-Advanced committed Mar 26, 2024
1 parent f84f72b commit f0e5233
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public LayoutComponentsFilter() {
);

homeVideoWithContext = new StringFilterGroup(
SettingsEnum.HIDE_VIDEO_WITH_LOW_VIEW
|| SettingsEnum.HIDE_HOME_FEED_MEMBERSHIP_VIDEO,
null,
"home_video_with_context.eml"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.Instrumentation;
import android.view.KeyEvent;

import app.revanced.integrations.youtube.settings.SettingsEnum;
import app.revanced.integrations.youtube.utils.ReVancedUtils;

public class InterstitialBannerPatch {
Expand All @@ -21,8 +22,22 @@ public static void onBackPressed() {

lastTimeCalled = currentTime;
ReVancedUtils.runOnMainThreadDelayed(() -> {
// Must run off main thread (Odd, but whatever).
ReVancedUtils.runOnBackgroundThread(() -> instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK));
ReVancedUtils.runOnBackgroundThread(() -> {
try {
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
} catch (Exception ex) {
// Injecting user events on Android 10+ requires the manifest to include
// INJECT_EVENTS, and it's usage is heavily restricted
// and requires the user to manually approve the permission in the device settings.
//
// And no matter what, permissions cannot be added for root installations
// as manifest changes are ignored for mount installations.
//
// Instead, catch the SecurityException and turn off hide full screen ads
// since this functionality does not work for these devices.
SettingsEnum.CLOSE_INTERSTITIAL_ADS.saveValue(false);
}
});
}, 1000);
ReVancedUtils.runOnMainThreadDelayed(() -> ReVancedUtils.showToastShort(str("revanced_close_interstitial_ads_toast")), 1000);
}
Expand Down

0 comments on commit f0e5233

Please sign in to comment.