Modern Apps git

← Modern-Apps.git

setupwizard: guard restore launch and bootloader reboot

Commit
fe1e46e45bdd1d720003860bf70aef5cc75cb332
Author
Vayun Mathur <[email protected]>
When
2026-11-19 01:53 UTC (17 days ago)
Parents
efd0293
Two runtime throw paths during first boot:

- MigrationStep launched the restore intent resolved at composition
  time with no guard; if the backup handler is disabled, removed or
  updated before the tap, launch throws ActivityNotFoundException.
  The sibling Gestures/Handoff paths already catch this. Catch it
  and leave Skip available.
- SystemSetup.rebootToBootloader called PowerManager.reboot bare.
  REBOOT is signature|privileged, so a build missing the priv-app
  grant throws SecurityException out of the OEM-unlock flow,
  violating this class's documented nothing-throws contract and
  wedging first boot. Catch and log it.

Verification: ./gradlew :setupwizard:testDevUnitTest and
./check setupwizard (run after this commit).

Diff

setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SystemSetup.kt
diff --git a/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SystemSetup.kt b/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SystemSetup.ktindex 6518af6680..2f69f4efff 100644--- a/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SystemSetup.kt+++ b/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SystemSetup.kt@@ -210,7 +210,14 @@ class SystemSetup(context: Context) {     private fun oemLockManager(): Any? = appContext.getSystemService("oem_lock")      fun rebootToBootloader() {-        appContext.getSystemService(PowerManager::class.java)?.reboot("bootloader")+        // REBOOT is signature|privileged: a build that misses the priv-app grant+        // throws SecurityException here, which must not break first boot (see the+        // class contract above: nothing here throws).+        try {+            appContext.getSystemService(PowerManager::class.java)?.reboot("bootloader")+        } catch (e: SecurityException) {+            Log.status(TAG, "reboot to bootloader not permitted on this build", e)+        }     }      // ---- location -------------------------------------------------------------------------
setupwizard/src/main/java/com/vayunmathur/setupwizard/ui/MigrationStep.kt
diff --git a/setupwizard/src/main/java/com/vayunmathur/setupwizard/ui/MigrationStep.kt b/setupwizard/src/main/java/com/vayunmathur/setupwizard/ui/MigrationStep.ktindex d6f1e8fab2..49e4f12c18 100644--- a/setupwizard/src/main/java/com/vayunmathur/setupwizard/ui/MigrationStep.kt+++ b/setupwizard/src/main/java/com/vayunmathur/setupwizard/ui/MigrationStep.kt@@ -1,6 +1,7 @@ package com.vayunmathur.setupwizard.ui  import android.app.Activity+import android.content.ActivityNotFoundException import android.content.Context import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult@@ -29,7 +30,15 @@ internal fun MigrationStep(             if (it.resultCode != Activity.RESULT_CANCELED) onAdvance(Route.Migration)         }         MigrationScreen(-            onRestore = { launcher.launch(restore) },+            onRestore = {+                // The intent was resolved at composition time; the handler can be+                // disabled or removed before the tap, and launch then throws.+                try {+                    launcher.launch(restore)+                } catch (_: ActivityNotFoundException) {+                    // No restore handler anymore; Skip remains available.+                }+            },             onSkip = { onAdvance(Route.Migration) },         )     }