Add Android 10/11 (API 29/30) support - #5
Open
dsingenalted wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The app required Android 12 (API 31) as minimum SDK because it relied exclusively on ISensorPrivacyManager, which only exists as a system service starting from Android 11 and was made a public API in Android 12.
Simply lowering minSdk to 29 is not sufficient - on stock Android 10, SystemServiceHelper.getSystemService("sensor_privacy") returns null, causing ShizukuBinderWrapper(null) to throw a NullPointerException on service startup. The app would crash immediately on first use.
This PR provides a proper compatibility implementation that handles each API level correctly.
Solution
SensorPrivacyCompatis implemented - a compatibility layer that selects the appropriate sensor-blocking mechanism based on the running Android version, with conditional initialization of ISensorPrivacyManager guarded by API version checks.How it works per API level
API 31+ (Android 12+) - unchanged behavior. Uses ISensorPrivacyManager.setSensorPrivacy() via Shizuku for a true global sensor kill-switch.
API 30 (Android 11) - ISensorPrivacyManager exists as a hidden API but with a simpler 4-method interface where setSensorPrivacy(boolean) is at transaction code
#4, different from the API 31 AIDL. Accessed via raw IBinder.transact() to avoid interface mismatch.API 29 (Android 10) - two-tier fallback:
#14per AOSP android-10.0.0 source) to revoke camera, microphone, and location ops per package.Implementation details
Op mode save/restore (API 29 AppOps path)
Before blocking, the current op mode of every package is read via IAppOpsService.checkOperation() (transaction
#1) and saved to SharedPreferences as a JSON map. On restore, exact saved values are written back. This ensures permissions previously denied by the user are not accidentally re-granted after disabling sensor privacy.Global vs per-app blocking on API 29
I have tested on Android 10 and 11 - the sensors disabled successfully.