setupwizard: a reboot-resumed wizard re-applies the status-bar lockdown
- Commit
3be8f97614697cb33dba8f80e9fb2b13b6af2ee3- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 04:54 UTC (5 days ago)
- Parents
b9424ff
The 'wizard cannot be escaped before provisioning' lockdown was attached to one step: the only setStatusBarHiddenForSetup(true) call lived in onEnterWelcome, reached via WelcomeStep's LaunchedEffect. Resume [Welcome, Location] after a reboot — the OEM-unlock step itself asks for such a reboot — and Welcome never composes, so the hook never runs; and unlike plain process death (system_server keeps the flags), a reboot clears the framework's setup-disable flags. The resumed wizard ran from Location to Finish with a live notification shade, Quick Settings, Home and Recents on an unprovisioned device. The lockdown is now owned at wizard entry: Navigation calls viewModel.onEnterWizard() from a LaunchedEffect at whichever step the flow starts or resumes on (idempotent; finishSetup still un-hides at completion), and onEnterWelcome keeps only its SIM-locale job. Two regression tests failed pre-fix: resuming after a simulated reboot asserts DISABLE_EXPAND is set with Welcome absent from the tree, plus a direct idempotency check. Flow order, handoffs, per-user state, OEM gating and completion gating were audited and cleared. Verified: :setupwizard:testDevUnitTest 51 tests pass; lint errors are pre-existing on untouched files.
Diff
setupwizard/src/main/java/com/vayunmathur/setupwizard/Navigation.kt
diff --git a/setupwizard/src/main/java/com/vayunmathur/setupwizard/Navigation.kt b/setupwizard/src/main/java/com/vayunmathur/setupwizard/Navigation.ktindex b8a0d1e1e4..00ef0612e7 100644--- a/setupwizard/src/main/java/com/vayunmathur/setupwizard/Navigation.kt+++ b/setupwizard/src/main/java/com/vayunmathur/setupwizard/Navigation.kt@@ -35,6 +35,11 @@ fun Navigation(viewModel: SetupViewModel) { LaunchedEffect(backStack) { snapshotFlow { backStack.backStack.toList() }.collect(viewModel::persistBackStack) }+ // The status-bar lockdown is the wizard's, not the welcome step's: a stack resumed+ // after a reboot starts at its top step and Welcome is never composed, and the+ // framework's setup-disable flags do not survive the reboot, so applying the+ // lockdown only from Welcome left the resumed wizard escapable through the shade.+ LaunchedEffect(viewModel) { viewModel.onEnterWizard() } val context = LocalContext.current val activity = LocalActivity.current val state = viewModel.state
setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SetupViewModel.kt
diff --git a/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SetupViewModel.kt b/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SetupViewModel.ktindex 06d5b3bacb..b9d4abc3db 100644--- a/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SetupViewModel.kt+++ b/setupwizard/src/main/java/com/vayunmathur/setupwizard/platform/SetupViewModel.kt@@ -94,12 +94,25 @@ class SetupViewModel(app: Application) : AndroidViewModel(app) { // ---- welcome -------------------------------------------------------------------------- /**- * Called when the welcome step is shown. Hides the status bar for the rest of setup and- * takes the SIM's language if there is one, which is the closest thing to a guess at what- * the user reads.+ * Called when the wizard itself is shown, at whichever step the flow starts (or resumes)+ * on. Hides the status bar for the rest of setup.+ *+ * This belongs to the wizard rather than to the welcome step: the persisted back stack+ * can resume at a later step after process death or a reboot (the bootloader step itself+ * asks for a reboot), the welcome step is then never composed, and the framework's+ * setup-disable flags do not survive a reboot - so a lockdown applied only from the+ * welcome step would leave the resumed wizard escapable through the shade. */- fun onEnterWelcome() {+ fun onEnterWizard() { system.setStatusBarHiddenForSetup(true)+ }++ /**+ * Called when the welcome step is shown. Takes the SIM's language if there is one, which+ * is the closest thing to a guess at what the user reads.+ */+ fun onEnterWelcome() {+ onEnterWizard() if (!APPLY_SIM_LANGUAGE_ON_ENTRY || simLocaleApplied) return val simLocale = system.simLocale() ?: return simLocaleApplied = true
setupwizard/src/test/java/com/vayunmathur/setupwizard/NavigationFlowTest.kt
diff --git a/setupwizard/src/test/java/com/vayunmathur/setupwizard/NavigationFlowTest.kt b/setupwizard/src/test/java/com/vayunmathur/setupwizard/NavigationFlowTest.ktindex 801db08613..d6180e8530 100644--- a/setupwizard/src/test/java/com/vayunmathur/setupwizard/NavigationFlowTest.kt+++ b/setupwizard/src/test/java/com/vayunmathur/setupwizard/NavigationFlowTest.kt@@ -2,6 +2,7 @@ package com.vayunmathur.setupwizard import android.app.Activity import android.app.Application+import android.app.StatusBarManager import android.provider.Settings import androidx.activity.ComponentActivity import androidx.activity.result.ActivityResult@@ -21,9 +22,12 @@ import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.Shadows+import org.robolectric.shadows.ShadowStatusBarManager+import org.robolectric.shadow.api.Shadow import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test+import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -130,6 +134,29 @@ class NavigationFlowTest { awaitText(R.string.swipe_gestures_title) } + @Test fun `resuming after a reboot re-applies the status bar lockdown`() {+ val vm = SetupViewModel(app)+ // Exact state a reboot leaves behind: progress persisted past Welcome (the+ // Wi-Fi handoff already replaced by Location), while the framework's+ // setup-disable flags - held in system_server - are gone.+ vm.system.saveSetupProgress("welcome,location")+ ShadowStatusBarManager.reset()+ val statusBar = ctx.getSystemService(StatusBarManager::class.java)+ val shadow = Shadow.extract<ShadowStatusBarManager>(statusBar)+ assertEquals(ShadowStatusBarManager.DISABLE_NONE, shadow.disableFlags)++ rule.setContent { Navigation(vm) }+ awaitText(R.string.location_services)+ awaitNoText(R.string.welcome_to_modern_apps_os)++ // The resumed wizard never composes Welcome, so a lockdown applied only from+ // that step would leave the shade/QS live for the rest of an unprovisioned setup.+ assertTrue(+ shadow.disableFlags and ShadowStatusBarManager.DISABLE_EXPAND != 0,+ "status bar should be disabled for setup after resume, flags=${shadow.disableFlags}",+ )+ }+ @Test fun `cancelling the wifi handoff returns to welcome`() { val vm = SetupViewModel(app) rule.setContent { Navigation(vm) }
setupwizard/src/test/java/com/vayunmathur/setupwizard/platform/SetupViewModelTest.kt
diff --git a/setupwizard/src/test/java/com/vayunmathur/setupwizard/platform/SetupViewModelTest.kt b/setupwizard/src/test/java/com/vayunmathur/setupwizard/platform/SetupViewModelTest.ktindex 9fe1da5ff6..7cd42c7438 100644--- a/setupwizard/src/test/java/com/vayunmathur/setupwizard/platform/SetupViewModelTest.kt+++ b/setupwizard/src/test/java/com/vayunmathur/setupwizard/platform/SetupViewModelTest.kt@@ -1,6 +1,7 @@ package com.vayunmathur.setupwizard.platform import android.app.Application+import android.app.StatusBarManager import android.content.Context import android.provider.Settings import androidx.test.core.app.ApplicationProvider@@ -10,6 +11,8 @@ import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.setMain import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner+import org.robolectric.shadows.ShadowStatusBarManager+import org.robolectric.shadow.api.Shadow import java.util.Locale import kotlin.test.AfterTest import kotlin.test.BeforeTest@@ -60,6 +63,20 @@ class SetupViewModelTest { assertEquals(vm.system.isWifiScanningAlwaysAvailable(), vm.state.wifiScanningEnabled) } + @Test fun `entering the wizard applies the status bar lockdown`() {+ ShadowStatusBarManager.reset()+ val shadow = Shadow.extract<ShadowStatusBarManager>(+ ctx.getSystemService(StatusBarManager::class.java),+ )+ assertEquals(ShadowStatusBarManager.DISABLE_NONE, shadow.disableFlags)+ val vm = SetupViewModel(app)+ vm.onEnterWizard()+ assertTrue(shadow.disableFlags and ShadowStatusBarManager.DISABLE_EXPAND != 0)+ // Idempotent: resuming/re-entering must keep, not toggle, the lockdown.+ vm.onEnterWizard()+ assertTrue(shadow.disableFlags and ShadowStatusBarManager.DISABLE_EXPAND != 0)+ }+ @Test fun `welcome does not divert to bootloader warning when locked`() { val vm = SetupViewModel(app) vm.onEnterWelcome() // applies SIM locale if any; must not crash either way