mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-22 09:47:32 +01:00
fix(YouTube - Hide ads): Prevent app crash if hiding fullscreen ads is not possible (#590)
This commit is contained in:
parent
f47495ccd8
commit
4ec955fd01
@ -1,5 +1,7 @@
|
|||||||
package app.revanced.integrations.youtube.patches.components;
|
package app.revanced.integrations.youtube.patches.components;
|
||||||
|
|
||||||
|
import static app.revanced.integrations.shared.StringRef.str;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -170,7 +172,24 @@ public final class AdsFilter extends Filter {
|
|||||||
|
|
||||||
Utils.runOnMainThreadDelayed(() -> {
|
Utils.runOnMainThreadDelayed(() -> {
|
||||||
// Must run off main thread (Odd, but whatever).
|
// Must run off main thread (Odd, but whatever).
|
||||||
Utils.runOnBackgroundThread(() -> instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK));
|
Utils.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.
|
||||||
|
Logger.printInfo(() -> "Could not inject back button event", ex);
|
||||||
|
Settings.HIDE_FULLSCREEN_ADS.save(false);
|
||||||
|
Utils.showToastLong(str("revanced_hide_fullscreen_ads_feature_not_available_toast"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user