parentalcontrols: the master-switch toggle survives first-time PIN setup
- Commit
edd5da1b7dde97757e77695298c8fce9deab395b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 02:00 UTC (5 days ago)
- Parents
c67ea62
The dashboard switch is fully controlled, so toggling it only fires a callback. With a PIN set, the intent was stored in pendingControls and applied by the Controls gate after verify; without a PIN, requestSetup was called with after = null and pendingControls was never set — PIN setup popped straight back to a dashboard whose switch had never moved, and the parent had to toggle a second time. Every other dashboard action preserves its intent across setup via pendingAfterSetup; Controls was the one action whose payload (a value, not a screen) bypassed the mechanism built to carry exactly that. The no-PIN path now stores pendingControls and hands setup to the Controls gate, which applies the stored value on verify, identical to the PIN-set branch. The regression test drives toggle -> PIN setup and asserts the gate appears (failed pre-fix, timing out at the dashboard; it stops at the gate deliberately, since passing it needs the MAOS SupervisionManager class absent on the host JVM). Windows, enforcement precedence, schedulers and usage totals were audited and cleared. Verified: :parentalcontrols:testDevUnitTest 97 tests pass; the one lint error is pre-existing on an untouched file.
Diff
parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt
diff --git a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.ktindex 7330eeb2e0..b6e4c1a737 100644--- a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt+++ b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt@@ -39,7 +39,13 @@ internal fun EntryProviderScope<Route>.dashboardEntry( actions = DashboardActions( onSetControls = { desired -> if (!pin.isSet()) {- requestSetup(backStack, pendingAfterSetup, null)+ // Store the desired value before setup, exactly as the+ // PIN-set branch stores it before the gate: setup hands+ // over to the Controls gate, which applies it on verify.+ // Passing null here dropped the toggle entirely - the+ // parent returned to a dashboard with the switch unmoved.+ pendingControls.value = desired+ requestSetup(backStack, pendingAfterSetup, PinGateTarget.Controls) } else { pendingControls.value = desired backStack.add(Route.PinGate(PinGateTarget.Controls))
parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt
diff --git a/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt b/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.ktindex ed54702190..18f58e0b0c 100644--- a/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt+++ b/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt@@ -18,6 +18,7 @@ import com.vayunmathur.library.util.databases import com.vayunmathur.parentalcontrols.auth.ParentPin import com.vayunmathur.parentalcontrols.data.ParentalControlsDatabase import com.vayunmathur.parentalcontrols.platform.FakeAndroidKeyStore+import com.vayunmathur.parentalcontrols.platform.SupervisionMaster import com.vayunmathur.parentalcontrols.platform.SupervisionViewModel import com.vayunmathur.parentalcontrols.platform.UsageAccess import com.vayunmathur.parentalcontrols.data.AppRule@@ -245,6 +246,44 @@ class RouteAndUsageAccessTest { } } + @Test fun navigationControlsToggleWithoutPinHandsSetupToGate() {+ val pin = ParentPin.get(app)+ pin.clear()+ SupervisionMaster.setEnabled(app, true)+ try {+ val vm = SupervisionViewModel(app)+ rule.setContent { Navigation(vm, initialRoute = Route.Dashboard) }+ rule.waitForIdle()+ // No PIN yet: toggling the master switch must not lose the desired+ // value across PIN setup. Regression: the no-PIN branch passed a+ // null after-setup target and never stored pendingControls, so the+ // parent came back from setup to a switch that had never moved.+ rule.onNodeWithText("Controls for this phone").performClick()+ rule.waitUntil(timeoutMillis = 8000) {+ runCatching { rule.onNodeWithText("Set parent PIN").assertIsDisplayed(); true }+ .getOrDefault(false)+ }+ rule.onNodeWithText("New PIN").performTextInput("1234")+ rule.onNodeWithText("Repeat PIN").performTextInput("1234")+ rule.onNodeWithText("Save").performClick()+ // Setup hands over to the Controls gate, not straight back to the dashboard.+ rule.waitUntil(timeoutMillis = 8000) {+ runCatching {+ rule.onNodeWithText("Enter the parent PIN to change these settings.").assertIsDisplayed(); true+ }.getOrDefault(false)+ }+ // Stopping at the gate is deliberate: passing it applies the stored+ // value through SupervisionViewModel.setControlsEnabled, whose+ // reconcile needs the MaOS SupervisionManager class that does not+ // exist on this host JVM (see SupervisionViewModelTest). The gate's+ // appearance is the regression point - before the fix, setup popped+ // straight back to the dashboard and no gate ever showed.+ } finally {+ SupervisionMaster.setEnabled(app, true)+ pin.clear()+ }+ }+ @Test fun navigationDashboardIsUngated() { ParentPin.get(app).clear() val vm = SupervisionViewModel(app)