Common Android Utilities
Overview
The common Android library module is a small shared utility dependency for other Android modules. Its Gradle entry point, common/build.gradle, applies com.android.library, publishes the namespace rikka.shizuku.common, disables generated BuildConfig output with buildFeatures.buildConfig = false, and exposes libs.hidden.stub as a compileOnly dependency so code can compile against hidden Android APIs without packaging that stub into consumers. The module manifest at common/…/AndroidManifest.xml is intentionally empty (<manifest />), so depending on this library should not merge permissions, components, providers, or metadata into an app manifest.
Runtime utility code lives under common/src/main/java/moe/shizuku/common/util/. BuildUtils.java centralizes Android SDK feature checks using static snapshots of Build.VERSION.SDK_INT and, on Android M and newer, Build.VERSION.PREVIEW_SDK_INT. Most helpers are direct minimum-SDK predicates (atLeast23() through atLeast30()), while atLeast31() treats Android 12 preview builds running with SDK_INT == 30 and a positive preview SDK as API 31-capable.
OsUtils.java snapshots process identity at class-load time using android.system.Os.getuid() and android.system.Os.getpid(). It also snapshots the SELinux context once by calling android.os.SELinux.getContext() inside a broad Throwable catch; failures are represented as null rather than thrown to callers. Consumers using these helpers receive cached values for the current process rather than live system calls on every access.
Coupling
- If common/build.gradle changes the
compileOnly libs.hidden.stubdependency, verify OsUtils.java still compiles where it uses platform APIs such asandroid.system.Osandandroid.os.SELinux; the dependency is compile-only, so consumers must still rely on Android platform implementations at runtime. - If a consumer expects generated constants from this library, update common/build.gradle first:
buildConfig = falsemeans therikka.shizuku.common.BuildConfigclass is not generated for this module. - If API-level gates are added or changed in BuildUtils.java, keep preview handling explicit for APIs that may run as platform previews. The current
atLeast31()behavior is not equivalent to a plainSDK_INT >= 31check because it also accepts Android 12 previews on API 30.
Risks
- common/…/OsUtils.java caches UID, PID, and SELinux context in static fields. If code later needs to observe identity or SELinux context after process changes or privileged transitions, these helpers will return the class-load-time values and can make permission or diagnostics logic stale.
- common/…/BuildUtils.java has a TODO to replace it with
rikka.core.util.BuildUtils. If both utility classes are used in the project with different preview-SDK semantics, feature gates can diverge between modules.