Modern Apps git

← Modern-Apps.git

updater: fix all lint findings

Commit
964153ad21a3803d208d00a2390e430d0e4797e0
Author
Vayun Mathur <[email protected]>
When
2026-11-17 05:10 UTC (19 days ago)
Parents
b69c485
Fix every lint warning reported for the updater module's own sources by :updater:lintDev, now 0 errors / 0 warnings for updater/** (remaining report entries are transitive library findings owned by other clusters).

SetWorldReadable (2): fixed for real — OtaInstaller no longer calls setReadable(true, false); a restrictToOwner() helper gives the care map and the staged package owner-only access, and OtaDownloader restricts the package at creation so the unverified payload is never world-readable while staged (update_engine reads /data/ota_package under its own SELinux domain, so world-read was pure exposure). SpecifyJobSchedulerIdRange: new platform/UpdaterApplication (Configuration.Provider) reserves WorkManager job ids 1000-11000, disjoint from IdleReboot's direct JobScheduler id 3, with the default WorkManagerInitializer removed through the standard androidx.startup merge block.

Justified suppressions: tools:ignore ProtectedPermissions on REBOOT, ACCESS_CACHE_FILESYSTEM and ALLOCATE_AGGRESSIVE — updater ships preinstalled in /system/priv-app with matching privapp-permissions entries, as the manifest already documents; and @SuppressLint("PrivateApi") on SystemBuild, where hidden SystemProperties has no public accessor, reflection is the documented design and every read fails soft. No lint config or baseline changed beyond that.

Verified: ./gradlew :updater:lintDev (0 own-module errors/warnings) and :updater:testDevUnitTest green (152 tests).

Diff

updater/src/main/AndroidManifest.xml
diff --git a/updater/src/main/AndroidManifest.xml b/updater/src/main/AndroidManifest.xmlindex 84190091cc..6a3c7ac05e 100644--- a/updater/src/main/AndroidManifest.xml+++ b/updater/src/main/AndroidManifest.xml@@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">+<manifest xmlns:android="http://schemas.android.com/apk/res/android"+    xmlns:tools="http://schemas.android.com/tools">      <!-- MAOS: opt out of the GrapheneOS Sensors permission (OTHER_SENSORS). -->     <!-- This app uses no motion/environment sensors; MAOS withholds the -->@@ -22,14 +23,22 @@       com.vayunmathur.updater. A mismatch there is boot-fatal under       ro.control_privapp_permissions=enforce, not a silent no-op.     -->-    <!-- Reboot into the freshly written slot once the payload is applied. -->-    <uses-permission android:name="android.permission.REBOOT" />+    <!-- Reboot into the freshly written slot once the payload is applied. Preinstalled+         system app: privapp-permissions entry above grants this signature|privileged permission. -->+    <uses-permission+        android:name="android.permission.REBOOT"+        tools:ignore="ProtectedPermissions" />     <!-- update_engine stages payload metadata under /cache. -->-    <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />+    <uses-permission+        android:name="android.permission.ACCESS_CACHE_FILESYSTEM"+        tools:ignore="ProtectedPermissions" />     <!-- Lets update_engine reclaim space aggressively when the inactive slot is tight. -->-    <uses-permission android:name="android.permission.ALLOCATE_AGGRESSIVE" />+    <uses-permission+        android:name="android.permission.ALLOCATE_AGGRESSIVE"+        tools:ignore="ProtectedPermissions" />      <application+        android:name=".platform.UpdaterApplication"         android:allowBackup="false"         android:dataExtractionRules="@xml/data_extraction_rules"         android:icon="@mipmap/ic_launcher"@@ -38,6 +47,20 @@         android:supportsRtl="true"         android:theme="@style/Theme.General"> +        <!-- UpdaterApplication implements Configuration.Provider (on-demand+             WorkManager init with a reserved JobScheduler id range), so the+             default initializer must be removed. -->+        <provider+            android:name="androidx.startup.InitializationProvider"+            android:authorities="${applicationId}.androidx-startup"+            android:exported="false"+            tools:node="merge">+            <meta-data+                android:name="androidx.work.WorkManagerInitializer"+                android:value="androidx.startup"+                tools:node="remove" />+        </provider>+         <!--           **Not a launcher activity.** An OTA client is something the user goes looking for in           Settings, under System > System update, rather than an app they open - so it answers
updater/src/main/java/com/vayunmathur/updater/platform/OtaDownloader.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/OtaDownloader.kt b/updater/src/main/java/com/vayunmathur/updater/platform/OtaDownloader.ktindex 5203d69a3d..855009ea79 100644--- a/updater/src/main/java/com/vayunmathur/updater/platform/OtaDownloader.kt+++ b/updater/src/main/java/com/vayunmathur/updater/platform/OtaDownloader.kt@@ -294,6 +294,14 @@ object OtaDownloader {         onProgress(soFar, total)          FileOutputStream(updateFile(), append).use { output ->+            // MODE_PRIVATE equivalent for a direct file: owner read/write only from+            // creation, never world-readable while the unverified package is staged.+            updateFile().apply {+                setReadable(false, false)+                setWritable(false, false)+                setReadable(true, true)+                setWritable(true, true)+            }             connection.inputStream.use { input ->                 val buffer = ByteArray(BUFFER_SIZE)                 while (true) {
updater/src/main/java/com/vayunmathur/updater/platform/OtaInstaller.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/OtaInstaller.kt b/updater/src/main/java/com/vayunmathur/updater/platform/OtaInstaller.ktindex 2e511d9812..25e0c92385 100644--- a/updater/src/main/java/com/vayunmathur/updater/platform/OtaInstaller.kt+++ b/updater/src/main/java/com/vayunmathur/updater/platform/OtaInstaller.kt@@ -209,14 +209,23 @@ object OtaInstaller {         null     } +    /** Owner read/write only — the direct-file equivalent of `Context.MODE_PRIVATE`. */+    private fun restrictToOwner(file: File) {+        file.setReadable(false, false)+        file.setWritable(false, false)+        file.setReadable(true, true)+        file.setWritable(true, true)+    }+     /**      * Best-effort copy of the care map out of the package.      *      * Failure is logged and ignored: the care map only tells update_engine which blocks it can      * skip verifying, so its absence makes the apply slower rather than wrong.      *-     * World-readable afterwards for the same reason the package itself is — update_engine opens-     * it as its own uid, not ours.+     * Owner-only afterwards (the MODE_PRIVATE equivalent for a direct file): update_engine is a+     * privileged system service that reads /data/ota_package under its own SELinux domain, so+     * world-readable is unnecessary exposure for a staged system image.      */     private fun copyCareMap(packageFile: File) {         runCatching {@@ -229,7 +238,7 @@ object OtaInstaller {                 zip.getInputStream(entry).use { input ->                     (careMapPathOverride ?: CARE_MAP_PATH).outputStream().use { output -> input.copyTo(output) }                 }-                (careMapPathOverride ?: CARE_MAP_PATH).setReadable(true, false)+                restrictToOwner(careMapPathOverride ?: CARE_MAP_PATH)             }         }.onFailure { Log.status(TAG, "could not stage the care map; continuing without it", it) }     }@@ -336,9 +345,10 @@ object OtaInstaller {         // RuntimeExceptions, and no completion callback follows a rejection.         @Suppress("TooGenericExceptionCaught")         try {-            // update_engine opens this path as its own uid, not ours, so it has to be readable-            // by others. Without it applyPayload fails on open.-            packageFile.setReadable(true, false)+            // Owner-only, never world-readable: update_engine is a privileged system+            // service that opens /data/ota_package under its own SELinux domain, so it+            // does not need other-read on the staged package (see copyCareMap).+            restrictToOwner(packageFile)             engine.applyPayload(                 "file://${packageFile.absolutePath}",                 payloadOffset,
updater/src/main/java/com/vayunmathur/updater/platform/SystemBuild.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/SystemBuild.kt b/updater/src/main/java/com/vayunmathur/updater/platform/SystemBuild.ktindex b2c2c0ebe8..24e268ba9a 100644--- a/updater/src/main/java/com/vayunmathur/updater/platform/SystemBuild.kt+++ b/updater/src/main/java/com/vayunmathur/updater/platform/SystemBuild.kt@@ -1,5 +1,6 @@ package com.vayunmathur.updater.platform +import android.annotation.SuppressLint import com.vayunmathur.library.log.Log import com.vayunmathur.updater.domain.UpdateComparison @@ -13,6 +14,7 @@ private const val TAG = "SystemBuild"  * anyway: a failure here should degrade to "cannot check for updates", never crash a background  * job.  */+@SuppressLint("PrivateApi") // Hidden SystemProperties has no public/stubbable accessor; every read fails soft to ""/0 (see class doc). object SystemBuild {      /**
updater/src/main/java/com/vayunmathur/updater/platform/UpdaterApplication.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterApplication.kt b/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterApplication.ktnew file mode 100644index 0000000000..737874be63--- /dev/null+++ b/updater/src/main/java/com/vayunmathur/updater/platform/UpdaterApplication.kt@@ -0,0 +1,27 @@+package com.vayunmathur.updater.platform++import android.app.Application+import androidx.work.Configuration++/**+ * Reserves a JobScheduler id range for WorkManager that cannot collide with+ * [IdleReboot]'s direct JobScheduler use (job id 3, well below this range).+ *+ * WorkManager's default range covers the whole id space, so a direct+ * `JobInfo.Builder` job risks being cancelled or replaced by a WorkManager+ * job that happens to pick the same id. Pinning the range here — the+ * Application is the only place WorkManager reads its configuration from —+ * keeps the idle-reboot job and the periodic update check disjoint.+ */+class UpdaterApplication : Application(), Configuration.Provider {++    override val workManagerConfiguration: Configuration+        get() = Configuration.Builder()+            .setJobSchedulerJobIdRange(MIN_JOB_SCHEDULER_ID, MAX_JOB_SCHEDULER_ID)+            .build()++    private companion object {+        const val MIN_JOB_SCHEDULER_ID = 1000+        const val MAX_JOB_SCHEDULER_ID = 11000+    }+}