Modern Apps git

← Modern-Apps.git

screentime: convert activity-per-screen to Route host (#nav)

Commit
2696bb78e8bceb1a60685ba54e727acb1aa213c5
Author
Vayun Mathur <[email protected]>
When
2026-11-16 19:37 UTC (20 days ago)
Parents
d11b8b3
DashboardActivity, AppDetailsActivity and WindDownActivity each
owned a setContent shell, and the dashboard opened details with an
explicit Intent plus a package extra. Which screen was showing lived
in the activity stack, invisible to the Route system the owner
directive requires, and a second Settings entry stacked a second
activity instead of re-routing the running UI.

Add Route (Dashboard / AppDetails(packageName) / WindDown) and a
single MainActivity host (MaActivity) rendering Navigation.kt over a
rememberNavBackStack. The dashboard now pushes
Route.AppDetails(packageName); details bind to the route argument
via viewModel.openDetail, back is a plain pop, and WindDown is a
DetailPage destination. FrictionActivity stays an activity: it is a
system-triggered, showWhenLocked singleInstance surface shown over
the app being opened, not a screen the user navigates to.

Entry behaviour is preserved through activity-aliases: the old
component names keep their labels, exported flags, intent-filters
and Settings homepage meta-data (dashboard_summary, winddown_summary)
and point at the host, which is singleTask. MainActivity.routeFor
maps the dashboard action, BEDTIME_SETTINGS, the app-details action
(with its package extra) and SHOW_SUSPENDED_APP_DETAILS (package in
the data URI, now also declared on the alias so the paused treatment
can resolve it) to routes; onNewIntent re-routes a running host, and
the widget now starts the host. Direct editor entries stack
Dashboard below the destination so back returns to the dashboard.

Tests: ActivitiesAndReceiversTest and ActivitiesDeepTest launch the
host with the dashboard, bedtime and app-details (extra and
suspended-URI) intents instead of the removed activities.

Verified: ./gradlew :screentime:compileDevKotlin
:screentime:testDevUnitTest green.

Diff

screentime/AGENTS.md
diff --git a/screentime/AGENTS.md b/screentime/AGENTS.mdindex 605407ffb4..9f6e1960c8 100644--- a/screentime/AGENTS.md+++ b/screentime/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install screentime (dev by default)._ <!-- last-reviewed: 2026-10-16 --> - Gradle: :screentime / dir: screentime/ - Package roots present: ui, data, domain, platform, service, widget, notifications-- Entry files: ui/DashboardActivity.kt (activity-entry OS module; no MainActivity/Route)+- Entry files: MainActivity.kt + Route.kt + Navigation.kt (single host; FrictionActivity stays a system-triggered activity) - Deps: :library:room, :library:widgets - Metadata: metadata_data/screentime.md (present) - Rust: no / screenshotTest: no@@ -14,7 +14,7 @@ _Install: ./install screentime (dev by default)._ ## Overview **Purpose:** On-device screen-time dashboard — per-app usage, app timers + instant pauses, Wind Down (grayscale + DND), friction nudges, Glance widget. Sibling of `parentalcontrols/` (self-control vs supervised control). No account, nothing uploaded. **Key features:** `platform/UsageHistory` + `domain/HourBuckets` feed dashboard/charts; `AppTimers`/`Suspender`/`Coordinator` enforce limits; `WindDownApplier` + `WindowScheduler` run bedtime; widget mirrors the dashboard.-**Entry points:** `ui/DashboardActivity.kt` → `ui/DashboardScreen.kt` → `platform/ScreenTimeViewModel.kt` → `platform/Coordinator.kt` → `data/Rules.kt`.+**Entry points:** `MainActivity.kt` → `Navigation.kt` (`Route.Dashboard/AppDetails(packageName)/WindDown`) → `ui/DashboardScreen.kt` → `platform/ScreenTimeViewModel.kt` → `platform/Coordinator.kt` → `data/Rules.kt`. **Gotchas:** - `receiver/` is NOT a closed package root — pending migration; don't add more files there - Usage access is a special grant — behavior without it is an empty dashboard, not an error; handle gracefully@@ -40,7 +40,9 @@ _Install: ./install screentime (dev by default)._ - com/vayunmathur/screentime/receiver/Receivers.kt - com/vayunmathur/screentime/service/Services.kt ### ui/ + widget/ — dashboard + widget (the entries)-- com/vayunmathur/screentime/ui/DashboardActivity.kt+- com/vayunmathur/screentime/MainActivity.kt+- com/vayunmathur/screentime/Route.kt+- com/vayunmathur/screentime/Navigation.kt - com/vayunmathur/screentime/ui/DashboardScreen.kt - com/vayunmathur/screentime/ui/AppDetailsScreen.kt - com/vayunmathur/screentime/ui/FocusScreen.kt
screentime/src/main/AndroidManifest.xml
diff --git a/screentime/src/main/AndroidManifest.xml b/screentime/src/main/AndroidManifest.xmlindex 0b3d45c981..0bd7cd8e36 100644--- a/screentime/src/main/AndroidManifest.xml+++ b/screentime/src/main/AndroidManifest.xml@@ -59,18 +59,27 @@         android:supportsRtl="true"         android:theme="@style/Theme.General">         <!---          The dashboard. Reached from Settings only - no launcher icon. The intent-filter-          below registers the activity as a Settings row (ia.homepage + summary), so-          Settings > Digital Wellbeing and search land on the dashboard alongside-          Wind Down. Stock Wellbeing spreads its rows across homepage/apps/gestures/bedtime-          with summary URIs; ours registers the same homepage rows against our own activities.+          The single navigation host. Reached from Settings only - no launcher icon.+          Every former activity entry point below is an alias onto this host, keeping+          its own label, intent-filter and Settings meta-data, so Settings rows and+          external intents land exactly where they did; MainActivity.routeFor turns+          the arriving intent into the start route. singleTask so a second Settings+          tap re-routes the running host via onNewIntent instead of stacking hosts.         -->         <activity-            android:name=".ui.DashboardActivity"+            android:name=".MainActivity"             android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"             android:exported="true"             android:label="@string/app_name"-            android:theme="@style/Theme.General">+            android:launchMode="singleTask"+            android:theme="@style/Theme.General" />++        <!-- The dashboard Settings row (ia.homepage + summary). -->+        <activity-alias+            android:name=".ui.DashboardActivity"+            android:exported="true"+            android:label="@string/app_name"+            android:targetActivity=".MainActivity">             <intent-filter>                 <action android:name="com.vayunmathur.screentime.action.DASHBOARD" />                 <category android:name="android.intent.category.DEFAULT" />@@ -81,19 +90,14 @@             <meta-data                 android:name="com.android.settings.summary"                 android:resource="@string/dashboard_summary" />-        </activity>+        </activity-alias> -        <!---          Settings rows. Stock Wellbeing spreads these across the homepage, apps, gestures and-          bedtime categories with summary URIs; ours registers the same rows against our own-          activities so Settings > Digital Wellbeing (and search) lands here.-        -->-        <activity+        <!-- The Wind Down Settings row, answering the platform bedtime action. -->+        <activity-alias             android:name=".ui.WindDownActivity"-            android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"             android:exported="true"             android:label="@string/winddown_title"-            android:theme="@style/Theme.General">+            android:targetActivity=".MainActivity">             <intent-filter>                 <action android:name="android.settings.BEDTIME_SETTINGS" />                 <category android:name="android.intent.category.DEFAULT" />@@ -104,19 +108,25 @@             <meta-data                 android:name="com.android.settings.summary"                 android:resource="@string/winddown_summary" />-        </activity>+        </activity-alias> -        <activity+        <!-- Per-app details: our own action, plus the suspended-app details action+             the platform's paused treatment resolves (package in the data URI). -->+        <activity-alias             android:name=".ui.AppDetailsActivity"-            android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"             android:exported="true"             android:label="@string/details_title"-            android:theme="@style/Theme.General">+            android:targetActivity=".MainActivity">             <intent-filter>                 <action android:name="com.vayunmathur.screentime.action.APP_DETAILS" />                 <category android:name="android.intent.category.DEFAULT" />             </intent-filter>-        </activity>+            <intent-filter>+                <action android:name="android.intent.action.SHOW_SUSPENDED_APP_DETAILS" />+                <category android:name="android.intent.category.DEFAULT" />+                <data android:scheme="package" />+            </intent-filter>+        </activity-alias>          <!--           Friction sheets and the expired-timer notice. Started explicitly by our own
screentime/src/main/java/com/vayunmathur/screentime/MainActivity.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/MainActivity.kt b/screentime/src/main/java/com/vayunmathur/screentime/MainActivity.ktnew file mode 100644index 0000000000..5049367a96--- /dev/null+++ b/screentime/src/main/java/com/vayunmathur/screentime/MainActivity.kt@@ -0,0 +1,83 @@+package com.vayunmathur.screentime++import android.content.Intent+import androidx.activity.viewModels+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import com.vayunmathur.library.ui.MaActivity+import com.vayunmathur.screentime.platform.ScreenTimeViewModel++/**+ * The single Screen Time host, reached from Settings (no launcher icon).+ *+ * Every former activity entry point is an alias onto this host (see the+ * manifest): the Settings homepage rows for the dashboard and Wind Down and+ * the per-app details action all resolve here, and [routeFor] turns the+ * arriving intent into the start destination. Intents that arrive while the+ * host is already running are re-routed through [pendingRoute] instead of+ * stacking a second activity. FrictionActivity stays a separate activity:+ * it is a system-triggered surface shown over the app being opened.+ */+class MainActivity : MaActivity() {++    private val viewModel: ScreenTimeViewModel by viewModels()++    private var initialRoute: Route = Route.Dashboard+    private var pendingRoute by mutableStateOf<Route?>(null)++    override fun onCreateBeforeContent() {+        initialRoute = routeFor(intent)+    }++    @Composable+    override fun Content() {+        Navigation(+            viewModel = viewModel,+            initialRoute = initialRoute,+            externalRoute = pendingRoute,+            onExternalRouteConsumed = { pendingRoute = null },+        )+    }++    override fun onNewIntent(intent: Intent) {+        super.onNewIntent(intent)+        setIntent(intent)+        pendingRoute = routeFor(intent)+    }++    override fun onResume() {+        super.onResume()+        viewModel.refresh()+    }++    companion object {+        const val EXTRA_DETAILS_PACKAGE = "com.vayunmathur.screentime.extra.DETAILS_PACKAGE"++        const val ACTION_DASHBOARD = "com.vayunmathur.screentime.action.DASHBOARD"+        const val ACTION_APP_DETAILS = "com.vayunmathur.screentime.action.APP_DETAILS"+        const val ACTION_BEDTIME_SETTINGS = "android.settings.BEDTIME_SETTINGS"++        // String literal, not Intent.ACTION_SHOW_SUSPENDED_APP_DETAILS: the constant is absent+        // from this SDK's Intent, and the action string is stable platform surface.+        const val ACTION_SHOW_SUSPENDED_APP_DETAILS =+            "android.intent.action.SHOW_SUSPENDED_APP_DETAILS"++        /** The route an entry intent names; the dashboard is the default landing. */+        fun routeFor(intent: Intent?): Route = when (intent?.action) {+            ACTION_BEDTIME_SETTINGS -> Route.WindDown+            ACTION_APP_DETAILS -> Route.AppDetails(detailsPackage(intent) ?: "")+            ACTION_SHOW_SUSPENDED_APP_DETAILS -> Route.AppDetails(detailsPackage(intent) ?: "")+            else -> detailsPackage(intent)?.let { Route.AppDetails(it) } ?: Route.Dashboard+        }++        private fun detailsPackage(intent: Intent?): String? {+            intent ?: return null+            if (intent.action == ACTION_SHOW_SUSPENDED_APP_DETAILS) {+                intent.data?.schemeSpecificPart?.removePrefix("package:")?.let { return it }+            }+            return intent.getStringExtra(EXTRA_DETAILS_PACKAGE)+        }+    }+}
screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt b/screentime/src/main/java/com/vayunmathur/screentime/Navigation.ktnew file mode 100644index 0000000000..5f5dae4831--- /dev/null+++ b/screentime/src/main/java/com/vayunmathur/screentime/Navigation.kt@@ -0,0 +1,91 @@+package com.vayunmathur.screentime++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.lifecycle.compose.collectAsStateWithLifecycle+import com.vayunmathur.library.util.DetailPage+import com.vayunmathur.library.util.ListDetailPage+import com.vayunmathur.library.util.ListPage+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.rememberNavBackStack+import com.vayunmathur.screentime.platform.ScreenTimeViewModel+import com.vayunmathur.screentime.ui.AppDetailsScreen+import com.vayunmathur.screentime.ui.DashboardActions+import com.vayunmathur.screentime.ui.DashboardScreen+import com.vayunmathur.screentime.ui.WindDownScreen++/** Navigation host for Screen Time: the dashboard and everything it opens. */+@Composable+fun Navigation(+    viewModel: ScreenTimeViewModel,+    initialRoute: Route = Route.Dashboard,+    externalRoute: Route? = null,+    onExternalRouteConsumed: () -> Unit = {},+) {+    val backStack = if (initialRoute == Route.Dashboard) {+        rememberNavBackStack<Route>(Route.Dashboard)+    } else {+        rememberNavBackStack<Route>(Route.Dashboard, initialRoute)+    }++    LaunchedEffect(externalRoute) {+        val route = externalRoute ?: return@LaunchedEffect+        when (route) {+            Route.Dashboard -> backStack.reset(Route.Dashboard)+            Route.WindDown -> backStack.reset(Route.Dashboard, Route.WindDown)+            is Route.AppDetails -> when {+                backStack.last() == route -> Unit+                backStack.last() is Route.AppDetails -> backStack.setLast(route)+                else -> backStack.add(route)+            }+        }+        onExternalRouteConsumed()+    }++    MainNavigation(backStack) {+        entry<Route.Dashboard>(metadata = ListPage()) {+            val state by viewModel.state.collectAsStateWithLifecycle()+            DashboardScreen(+                state = state,+                actions = DashboardActions(+                    onSetPeriod = viewModel::setPeriod,+                    onStep = viewModel::stepAnchor,+                    onOpenApp = { packageName -> backStack.add(Route.AppDetails(packageName)) },+                ),+            )+        }+        entry<Route.AppDetails>(metadata = ListDetailPage() + DetailPage()) { route ->+            LaunchedEffect(route.packageName) {+                viewModel.openDetail(route.packageName.ifBlank { null })+            }+            val state by viewModel.detailState.collectAsStateWithLifecycle()+            AppDetailsScreen(+                state = state,+                onBack = { backStack.pop() },+                onSetPeriod = viewModel::setPeriod,+                onStep = viewModel::stepAnchor,+                onTimerChange = { minutes ->+                    state.packageName?.let { viewModel.setTimer(it, minutes) }+                },+                onPausedChange = { paused ->+                    state.packageName?.let { viewModel.setAppPaused(it, paused) }+                },+            )+        }+        entry<Route.WindDown>(metadata = DetailPage()) {+            val state by viewModel.state.collectAsStateWithLifecycle()+            WindDownScreen(+                state = state,+                onEnabledChange = { viewModel.setWindDown(enabled = it) },+                onStartChange = { h, m -> viewModel.setWindDown(startMinute = h * 60 + m) },+                onEndChange = { h, m -> viewModel.setWindDown(endMinute = h * 60 + m) },+                onToggleDay = { day ->+                    viewModel.setWindDown(daysMask = state.windDown.daysMask xor (1 shl day))+                },+                onGrayscaleChange = { viewModel.setWindDown(grayscale = it) },+                onDndChange = { viewModel.setWindDown(doNotDisturb = it) },+            )+        }+    }+}
screentime/src/main/java/com/vayunmathur/screentime/Route.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/Route.kt b/screentime/src/main/java/com/vayunmathur/screentime/Route.ktnew file mode 100644index 0000000000..332075a344--- /dev/null+++ b/screentime/src/main/java/com/vayunmathur/screentime/Route.kt@@ -0,0 +1,20 @@+package com.vayunmathur.screentime++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++@Serializable+/** Navigation destinations for Screen Time. */+sealed interface Route : NavKey {+    @Serializable+    /** The usage dashboard, reached from Settings > Digital Wellbeing. */+    data object Dashboard : Route++    @Serializable+    /** One app's usage, timer and pause state; the package name is the identity. */+    data class AppDetails(val packageName: String) : Route++    @Serializable+    /** The overnight wind-down schedule, reached from Settings. */+    data object WindDown : Route+}
screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.ktindex dc4d484ad3..f17df992ae 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt@@ -21,7 +21,7 @@ private const val TAG = "ScreenTimeSuspender"  *  * A suspended app's icon greys out and launches cancel: the platform shows the standard  * paused treatment with a button into our `ACTION_SHOW_SUSPENDED_APP_DETAILS` activity- * (see `AppDetailsActivity`), which is where the timer/pause reason lives. Unsuspending is+ * (see `Route.AppDetails`), which is where the timer/pause reason lives. Unsuspending is  * unconditional: reconcile recomputes the full paused set every time, so a stale suspend  * cannot survive a rule change, a reboot, or a timer deletion.  */@@ -46,7 +46,7 @@ class Suspender(private val context: Context) {         runCatching {             // 5-arg overload: (String[], boolean, PersistableBundle, PersistableBundle,             // SuspendDialogInfo). Null extras and null dialog: the platform shows its default-            // paused treatment, whose details button resolves to our AppDetailsActivity.+            // paused treatment, whose details button resolves to our AppDetails route.             method.invoke(pm, packages, suspended, null, null, null)             if (suspended) rememberPaused(packages.toSet()) else forgetPaused(packages.toSet())         }.onFailure { Log.status(TAG, "could not set suspended=$suspended for ${packages.toList()}", it) }
screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.ktindex a98293976a..e9018b8655 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/AppDetailsScreen.kt@@ -1,11 +1,5 @@ package com.vayunmathur.screentime.ui -import android.content.Intent-import android.os.Bundle-import androidx.activity.ComponentActivity-import androidx.activity.compose.setContent-import androidx.activity.enableEdgeToEdge-import androidx.activity.viewModels import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -29,9 +23,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp-import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.IconArrowForward import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.LazyListScaffold@@ -49,68 +41,10 @@ import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.screentime.R import com.vayunmathur.screentime.platform.AppDetailsUiState-import com.vayunmathur.screentime.platform.ScreenTimeViewModel import com.vayunmathur.screentime.platform.UsagePeriod import java.time.LocalDate -/**- * Per-app drill-down- * Per-app drill-down: the same week/day usage chart as the dashboard, scoped to one app, plus- * its daily limit and manual pause.- *- * Also answers `ACTION_SHOW_SUSPENDED_APP_DETAILS`: when the user taps a paused app, the- * platform routes the details button here, so the "why is this paused" question lands on the- * screen that can answer (and lift) it. The suspended package arrives as the intent data.- */-class AppDetailsActivity : ComponentActivity() {--    private val viewModel: ScreenTimeViewModel by viewModels()--    override fun onCreate(savedInstanceState: Bundle?) {-        super.onCreate(savedInstanceState)-        enableEdgeToEdge()-        viewModel.openDetail(suspendedPackage())-        setContent {-            DynamicTheme {-                val state by viewModel.detailState.collectAsStateWithLifecycle()-                AppDetailsScreen(-                    state = state,-                    onBack = { finish() },-                    onSetPeriod = viewModel::setPeriod,-                    onStep = viewModel::stepAnchor,-                    onTimerChange = { minutes ->-                        state.packageName?.let { viewModel.setTimer(it, minutes) }-                    },-                    onPausedChange = { paused ->-                        state.packageName?.let { viewModel.setAppPaused(it, paused) }-                    },-                )-            }-        }-    }--    override fun onResume() {-        super.onResume()-        viewModel.refresh()-    }--    private fun suspendedPackage(): String? {-        // String literal, not Intent.ACTION_SHOW_SUSPENDED_APP_DETAILS: the constant is absent-        // from this SDK's Intent, and the action string is stable platform surface.-        if (intent.action == ACTION_SHOW_SUSPENDED_APP_DETAILS) {-            intent.data?.schemeSpecificPart?.removePrefix("package:")?.let { return it }-        }-        return intent.getStringExtra(EXTRA_DETAILS_PACKAGE)-    }--    companion object {-        const val EXTRA_DETAILS_PACKAGE = "com.vayunmathur.screentime.extra.DETAILS_PACKAGE"--        private const val ACTION_SHOW_SUSPENDED_APP_DETAILS =-            "android.intent.action.SHOW_SUSPENDED_APP_DETAILS"-    }-}-+/** Per-app drill-down: week/day usage scoped to one app, plus its timer and pause. */ @OptIn(ExperimentalMaterial3Api::class) @Composable fun AppDetailsScreen(
screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardActivity.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardActivity.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardActivity.ktdeleted file mode 100644index c84d9eab59..0000000000--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/DashboardActivity.kt+++ /dev/null@@ -1,51 +0,0 @@-package com.vayunmathur.screentime.ui--import androidx.activity.ComponentActivity-import androidx.activity.compose.setContent-import androidx.activity.enableEdgeToEdge-import androidx.activity.viewModels-import android.content.Intent-import android.os.Bundle-import androidx.compose.runtime.getValue-import androidx.lifecycle.compose.collectAsStateWithLifecycle-import com.vayunmathur.library.ui.DynamicTheme-import com.vayunmathur.screentime.platform.ScreenTimeViewModel--/**- * The screen-time dashboard, reached from Settings (no launcher icon).- *- * Self-managed screen time lives under Settings > Digital Wellbeing; this activity answers the- * homepage row registered in the manifest rather than a launcher intent.- */-class DashboardActivity : ComponentActivity() {--    private val viewModel: ScreenTimeViewModel by viewModels()--    override fun onCreate(savedInstanceState: Bundle?) {-        super.onCreate(savedInstanceState)-        enableEdgeToEdge()-        setContent {-            DynamicTheme {-                val state by viewModel.state.collectAsStateWithLifecycle()-                DashboardScreen(-                    state = state,-                    actions = DashboardActions(-                        onSetPeriod = viewModel::setPeriod,-                        onStep = viewModel::stepAnchor,-                        onOpenApp = { packageName ->-                            startActivity(-                                Intent(this, AppDetailsActivity::class.java)-                                    .putExtra(AppDetailsActivity.EXTRA_DETAILS_PACKAGE, packageName),-                            )-                        },-                    ),-                )-            }-        }-    }--    override fun onResume() {-        super.onResume()-        viewModel.refresh()-    }-}
screentime/src/main/java/com/vayunmathur/screentime/ui/WindDownScreen.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/ui/WindDownScreen.kt b/screentime/src/main/java/com/vayunmathur/screentime/ui/WindDownScreen.ktindex e466471da4..6e3748d80b 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/ui/WindDownScreen.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/ui/WindDownScreen.kt@@ -1,10 +1,5 @@ package com.vayunmathur.screentime.ui -import androidx.activity.ComponentActivity-import androidx.activity.compose.setContent-import androidx.activity.enableEdgeToEdge-import androidx.activity.viewModels-import android.os.Bundle import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth@@ -23,7 +18,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.LazyListScaffold import com.vayunmathur.library.ui.SettingsRow import com.vayunmathur.library.ui.SettingsSection@@ -33,47 +27,6 @@ import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.screentime.R import com.vayunmathur.screentime.platform.ScreenTimeUiState-import com.vayunmathur.screentime.platform.ScreenTimeViewModel--/**- * Overnight wind-down, reached from Settings (`BEDTIME_SETTINGS`) and the dashboard.- *- * Nothing is blocked here - the screen just goes quiet at the scheduled hour: grayscale- * first, Do Not Disturb alongside when configured. Both halves apply and clear together on- * every reconcile, so a mid-window edit takes effect without waiting for a boundary.- */-class WindDownActivity : ComponentActivity() {--    private val viewModel: ScreenTimeViewModel by viewModels()--    override fun onCreate(savedInstanceState: Bundle?) {-        super.onCreate(savedInstanceState)-        enableEdgeToEdge()-        setContent {-            DynamicTheme {-                val state by viewModel.state.collectAsStateWithLifecycle()-                WindDownScreen(-                    state = state,-                    onEnabledChange = { viewModel.setWindDown(enabled = it) },-                    onStartChange = { h, m -> viewModel.setWindDown(startMinute = h * 60 + m) },-                    onEndChange = { h, m -> viewModel.setWindDown(endMinute = h * 60 + m) },-                    onToggleDay = { day ->-                        viewModel.setWindDown(-                            daysMask = state.windDown.daysMask xor (1 shl day),-                        )-                    },-                    onGrayscaleChange = { viewModel.setWindDown(grayscale = it) },-                    onDndChange = { viewModel.setWindDown(doNotDisturb = it) },-                )-            }-        }-    }--    override fun onResume() {-        super.onResume()-        viewModel.refresh()-    }-}  @OptIn(ExperimentalMaterial3Api::class) @Composable
screentime/src/main/java/com/vayunmathur/screentime/widget/ScreenTimeGlanceWidget.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/widget/ScreenTimeGlanceWidget.kt b/screentime/src/main/java/com/vayunmathur/screentime/widget/ScreenTimeGlanceWidget.ktindex cf6ae4c1d4..bf3a56d5d3 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/widget/ScreenTimeGlanceWidget.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/widget/ScreenTimeGlanceWidget.kt@@ -28,7 +28,7 @@ import androidx.glance.text.TextAlign import androidx.glance.text.TextStyle import com.vayunmathur.library.widgets.MaWidget import com.vayunmathur.screentime.R-import com.vayunmathur.screentime.ui.DashboardActivity+import com.vayunmathur.screentime.MainActivity  internal val TotalMinutesKey = longPreferencesKey("screentime_total_minutes") internal val TopLabelKey = stringPreferencesKey("screentime_top_label")@@ -88,7 +88,7 @@ private fun ScreenTimeWidgetContent(             .padding(16.dp)             .clickable(                 actionStartActivity(-                    Intent(LocalContext.current, DashboardActivity::class.java).apply {+                    Intent(LocalContext.current, MainActivity::class.java).apply {                         addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)                     },                 ),
screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.ktindex f2de72d1f3..6569e9348f 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt@@ -26,30 +26,30 @@ class ActivitiesAndReceiversTest {      private fun ctx() = ApplicationProvider.getApplicationContext<android.content.Context>() -    @Test fun dashboardActivity_creates() {-        val controller = Robolectric.buildActivity(DashboardActivity::class.java).create()+    @Test fun mainActivity_creates() {+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java).create()         assertNotNull(controller.get())         controller.destroy()     } -    @Test fun appDetailsActivity_withPackageExtra() {-        val intent = Intent(ctx(), AppDetailsActivity::class.java)-            .putExtra(AppDetailsActivity.EXTRA_DETAILS_PACKAGE, "com.a.app")-        val controller = Robolectric.buildActivity(AppDetailsActivity::class.java, intent).create()+    @Test fun mainActivity_appDetailsWithPackageExtra() {+        val intent = Intent(ctx(), com.vayunmathur.screentime.MainActivity::class.java)+            .putExtra(com.vayunmathur.screentime.MainActivity.EXTRA_DETAILS_PACKAGE, "com.a.app")+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, intent).create()         assertNotNull(controller.get())         controller.destroy()     } -    @Test fun appDetailsActivity_suspendedDataUri() {+    @Test fun mainActivity_appDetailsSuspendedDataUri() {         val intent = Intent("android.intent.action.SHOW_SUSPENDED_APP_DETAILS")             .setData(Uri.parse("package:com.b.app"))-        val controller = Robolectric.buildActivity(AppDetailsActivity::class.java, intent).create()+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, intent).create()         assertNotNull(controller.get())         controller.destroy()     } -    @Test fun windDownActivity_creates() {-        val controller = Robolectric.buildActivity(WindDownActivity::class.java).create()+    @Test fun mainActivity_windDownCreates() {+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, Intent("android.settings.BEDTIME_SETTINGS")).create()         assertNotNull(controller.get())         controller.destroy()     }
screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesDeepTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesDeepTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesDeepTest.ktindex b1d89b783e..81e1b55688 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesDeepTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesDeepTest.kt@@ -17,8 +17,8 @@ import kotlin.test.assertFalse class ActivitiesDeepTest {     @Before fun setUp() = FakeAndroidKeyStore.install() -    @Test fun dashboardActivityResumesAndRefreshes() {-        val controller = Robolectric.buildActivity(DashboardActivity::class.java).create().start().resume().visible()+    @Test fun mainActivityDashboardResumesAndRefreshes() {+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java).create().start().resume().visible()         repeat(10) {             shadowOf(Looper.getMainLooper()).idle()             shadowOf(Looper.getMainLooper()).idleFor(50, TimeUnit.MILLISECONDS)@@ -48,26 +48,26 @@ class ActivitiesDeepTest {         }     } -    @Test fun windDownActivityResumesAndRefreshes() {-        val controller = Robolectric.buildActivity(WindDownActivity::class.java).create().start().resume().visible()+    @Test fun mainActivityWindDownResumesAndRefreshes() {+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, android.content.Intent("android.settings.BEDTIME_SETTINGS")).create().start().resume().visible()         pump()         assertFalse(controller.get().isFinishing)         controller.pause().stop().destroy()         drain()     } -    @Test fun appDetailsActivityResumesWithPackageAndSuspendedUri() {+    @Test fun mainActivityAppDetailsResumesWithPackageAndSuspendedUri() {         val ctx = androidx.test.core.app.ApplicationProvider.getApplicationContext<android.content.Context>()-        val intent = android.content.Intent(ctx, AppDetailsActivity::class.java)-            .putExtra(AppDetailsActivity.EXTRA_DETAILS_PACKAGE, "com.a.app")-        val controller = Robolectric.buildActivity(AppDetailsActivity::class.java, intent).create().start().resume().visible()+        val intent = android.content.Intent(ctx, com.vayunmathur.screentime.MainActivity::class.java)+            .putExtra(com.vayunmathur.screentime.MainActivity.EXTRA_DETAILS_PACKAGE, "com.a.app")+        val controller = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, intent).create().start().resume().visible()         pump()         assertFalse(controller.get().isFinishing)         controller.pause().stop().destroy()          val uriIntent = android.content.Intent("android.intent.action.SHOW_SUSPENDED_APP_DETAILS")             .setData(android.net.Uri.parse("package:com.b.app"))-        val second = Robolectric.buildActivity(AppDetailsActivity::class.java, uriIntent).create().start().resume().visible()+        val second = Robolectric.buildActivity(com.vayunmathur.screentime.MainActivity::class.java, uriIntent).create().start().resume().visible()         pump()         assertFalse(second.get().isFinishing)         second.pause().stop().destroy()