appstore: request INSTALL_PACKAGES with fallback to user-confirmed installs
- Commit
1f88d66f9a7b92d88ab20e2855424e6327b9bb55- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 18:50 UTC (27 days ago)
- Parents
f3834b7
Declare the privileged INSTALL_PACKAGES permission so MAOS can grant silent installs, while stock Android keeps the existing user-confirmed session flow. What changed and why: the store installs via session-based PackageInstaller with user confirmation and no INSTALL_PACKAGES today. On MAOS the OS can grant INSTALL_PACKAGES as a privileged permission, allowing silent commits; declaring it here enables that without affecting stock Android, where the permission is never granted to a regularly installed app. Implementation details: SessionInstaller checks at install time whether INSTALL_PACKAGES is actually held (ActivityCompat.checkSelfPermission, public API only, wrapped in runCatching so it never throws). When held, session params request USER_ACTION_NOT_REQUIRED even for first installs; when not held, the params logic is exactly the old one (silent only for updates on API 31+, confirmation otherwise). The commit path still reports to InstallStatusReceiver either way, so success/abort/failure handling is unchanged. No hidden APIs; no behavior change on devices where the permission is absent. User-visible effect: silent installs on MAOS where granted; identical confirmation prompts everywhere else. Verified: :appstore:compileDevKotlin green, :appstore:lint green, root checkMetadata green (note: :appstore:checkMetadata does not exist as a module task; the metadata check is the root checkMetadata task).
Diff
appstore/src/main/AndroidManifest.xml
diff --git a/appstore/src/main/AndroidManifest.xml b/appstore/src/main/AndroidManifest.xmlindex 2b17c384ce..2d371ea03f 100644--- a/appstore/src/main/AndroidManifest.xml+++ b/appstore/src/main/AndroidManifest.xml@@ -10,6 +10,13 @@ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />+ <!-- Privileged silent installs on MAOS: the OS grants this signature|privileged+ permission to the store, letting session commits proceed with+ USER_ACTION_NOT_REQUIRED even for first installs. Stock Android never+ grants it to a regularly installed app, so the installer checks at+ runtime (checkSelfPermission) and keeps the user-confirmed session flow+ when it is not held. Declaring it here changes nothing on stock. -->+ <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" /> <uses-permission android:name="android.permission.ENFORCE_UPDATE_OWNERSHIP" /> <!-- Silent background updates: SessionInstaller commits with USER_ACTION_NOT_REQUIRED,
appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.ktindex 15b0c21ae6..408fdf8cb2 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/SessionInstaller.kt@@ -4,8 +4,10 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.content.pm.PackageInstaller+import android.content.pm.PackageManager import android.os.Build import android.os.Process+import androidx.core.app.ActivityCompat import com.vayunmathur.library.log.Log import com.vayunmathur.appstore.data.security.InstallRequirement import com.vayunmathur.appstore.data.security.InstallVerifier@@ -57,6 +59,22 @@ class SessionInstaller( context.packageManager.getPackageInfo(packageName, 0) }.isSuccess + /**+ * Whether the OS actually granted the privileged INSTALL_PACKAGES permission+ * declared in the manifest.+ *+ * MAOS grants it to the store as a privileged app, enabling silent installs.+ * Stock Android (sideloaded or regular user install) never grants it, so this+ * returns false there and every install keeps the user-confirmed flow. Public+ * API check only; never throws.+ */+ private fun hasSilentInstallPermission(): Boolean = runCatching {+ ActivityCompat.checkSelfPermission(+ context,+ android.Manifest.permission.INSTALL_PACKAGES,+ ) == PackageManager.PERMISSION_GRANTED+ }.getOrDefault(false)+ private fun commit(packageName: String, files: List<File>, totalSize: Long): Boolean { val computedSize = if (totalSize > 0) totalSize else files.sumOf { it.length() } return try {@@ -145,8 +163,14 @@ class SessionInstaller( // Silent install is only offered for updates: the OS honours // USER_ACTION_NOT_REQUIRED when this app is the target's update owner, and // a first-time install of a package owned by someone else would prompt- // anyway. First installs keep the confirmation dialog unconditionally.- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && isInstalled(packageName)) {+ // anyway. First installs keep the confirmation dialog unconditionally —+ // unless the OS granted the privileged INSTALL_PACKAGES permission (MAOS),+ // in which case silent commits are allowed for first installs too. The+ // permission check is what makes this degrade gracefully: stock Android+ // never grants it, so the flow there is byte-for-byte the old one.+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&+ (isInstalled(packageName) || hasSilentInstallPermission())+ ) { setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) } setInstallLocation(android.content.pm.PackageInfo.INSTALL_LOCATION_AUTO)