Modern Apps git

← Modern-Apps.git

launcher: add GrapheneOS two-line labels and add-apps-to-home

Commit
a4d7744cb4d6799d90081d7dd93918311a765de4
Author
Vayun Mathur <[email protected]>
When
2026-12-06 16:33 UTC (1 hour ago)
Parents
df47c20
GrapheneOS Launcher3QuickStep 17 (pulled from the owner's Pixel 9
Pro XL, see analysis/launcher3-phone-gap.md) exposes two Home
settings our phone launcher lacked:

- pref_enable_two_line_toggle (default off): drawer grid labels
  may wrap to two lines. Added Settings > App drawer > Two-line
  labels, persisted as launcher_drawer_two_line, threaded through
  DrawerUiState to LauncherAppIcon/LauncherIconCell labelMaxLines.
  Workspace and hotseat labels stay single-line, as in Launcher3.

- pref_add_icon_to_home (default on): newly installed apps are
  added to the home screen. Added Settings > Add apps to Home
  screen, persisted as launcher_add_apps_to_home. A persisted
  seen-set (launcher_known_apps) is seeded from the current app
  list on first run; only activities first seen afterwards and
  not already anywhere in the layout are placed at the first
  vacant cell, so toggling the setting on later does not dump
  the whole drawer onto the home screen. The diff is the pure
  domain/NewApps.unseen, unit-tested.

Watch and TV paths are untouched. launcher/AGENTS.md lists the
new domain file.

Verified: ./gradlew :launcher:lint :launcher:lintVitalRelease
:launcher:testDevUnitTest (428 tests) green in this worktree.
:launcher:checkMetadata has no such task on this base
(pre-existing; no metadata task is registered for :launcher).

Diff

launcher/AGENTS.md
diff --git a/launcher/AGENTS.md b/launcher/AGENTS.mdindex 046ece4379..fec1382452 100644--- a/launcher/AGENTS.md+++ b/launcher/AGENTS.md@@ -114,6 +114,7 @@ neither runs on the wrong form factor. - com/vayunmathur/launcher/domain/ReorderDwell.kt - com/vayunmathur/launcher/domain/FastScroll.kt - com/vayunmathur/launcher/domain/WidgetResize.kt+- com/vayunmathur/launcher/domain/NewApps.kt ### platform/ — ViewModel, monitor, widgets, bridge - com/vayunmathur/launcher/platform/LauncherViewModel.kt - com/vayunmathur/launcher/platform/LauncherUiContract.kt
launcher/src/main/java/com/vayunmathur/launcher/domain/NewApps.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/NewApps.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/NewApps.ktnew file mode 100644index 0000000000..ac5562794a--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/NewApps.kt@@ -0,0 +1,8 @@+package com.vayunmathur.launcher.domain++/** Pure seen-set diff behind GrapheneOS `pref_add_icon_to_home`. */+object NewApps {+    /** Activities in [current] that were not in the persisted [known] set, in current order. */+    fun unseen(known: Set<String>, current: List<String>): List<String> =+        current.filter { it !in known }.distinct()+}
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherActionOps.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherActionOps.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherActionOps.ktindex e61909b919..8ad44eb16a 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherActionOps.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherActionOps.kt@@ -131,6 +131,8 @@ internal object LauncherSettingsOpsHolder : SettingsActions {     override fun setShowLabels(show: Boolean) = vm().setShowLabelsImpl(show)     override fun setIconScale(scale: Float) = vm().setIconScaleImpl(scale)     override fun setDrawerListLayout(list: Boolean) = vm().setDrawerListLayoutImpl(list)+    override fun setDrawerTwoLineLabels(twoLine: Boolean) = vm().setDrawerTwoLineLabelsImpl(twoLine)+    override fun setAddAppsToHome(enabled: Boolean) = vm().setAddAppsToHomeImpl(enabled)     override fun pickWallpaper() = vm().pickWallpaperImpl()     override fun requestDefaultHome() = vm().requestDefaultHomeImpl() }
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.ktindex 73e5a5d653..2e8eaf41fb 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt@@ -69,6 +69,23 @@ internal fun LauncherViewModel.onAppsChangedImpl(stale: PackageKey?) {     refreshWorkProfileImpl()     seedIfEmptyImpl()     reconcileNowImpl()+    addNewAppsToHomeImpl()+}++/** GrapheneOS `pref_add_icon_to_home`: place activities first seen after the seen-set was built. */+internal fun LauncherViewModel.addNewAppsToHomeImpl() {+    viewModelScope.launch {+        val apps = appsMonitor.apps.value+        if (apps.isEmpty()) return@launch+        val current = apps.map { it.key.componentName.flattenToString() + "|" + it.profileSerial }+        val known = ds.getStringSetAwait(KEY_KNOWN_APPS)+        if (known.isEmpty()) { current.forEach { ds.addStringToSetIfAbsent(KEY_KNOWN_APPS, it) }; return@launch }+        val unseen = com.vayunmathur.launcher.domain.NewApps.unseen(known, current)+        current.forEach { ds.addStringToSetIfAbsent(KEY_KNOWN_APPS, it) }+        if (!settingsState.value.addAppsToHome || unseen.isEmpty()) return@launch+        val placed = repository.getAll().mapNotNull { e -> e.className?.let { e.packageName + "/" + it + "|" + e.profileSerial } }.toSet()+        apps.filter { app -> (app.key.componentName.flattenToString() + "|" + app.profileSerial) in unseen && (app.componentName.packageName + "/" + app.componentName.className + "|" + app.profileSerial) !in placed }.forEach { repository.addToFirstVacantCell(homeState.value.grid, entityForAppImpl(it)) }+    } }  /**@@ -95,6 +112,8 @@ internal fun LauncherViewModel.loadPreferencesImpl() {     val showLabels = ds.getBoolean(KEY_SHOW_LABELS, true)     val iconScale = (ds.getDouble(KEY_ICON_SCALE) ?: 1.0).toFloat()     val drawerListLayout = ds.getBoolean(KEY_DRAWER_LIST_LAYOUT, false)+    val drawerTwoLine = ds.getBoolean(KEY_DRAWER_TWO_LINE, false)+    val addAppsToHome = ds.getBoolean(KEY_ADD_APPS_TO_HOME, true)      settingsState.value = SettingsUiState(         columns = columns,@@ -103,6 +122,8 @@ internal fun LauncherViewModel.loadPreferencesImpl() {         showLabels = showLabels,         iconScale = iconScale,         drawerListLayout = drawerListLayout,+        drawerTwoLineLabels = drawerTwoLine,+        addAppsToHome = addAppsToHome,     )     homeState.value = homeState.value.copy(         grid = GridSpec(columns, rows, hotseat),@@ -113,6 +134,7 @@ internal fun LauncherViewModel.loadPreferencesImpl() {         showLabels = showLabels,         iconScale = iconScale,         listLayout = drawerListLayout,+        twoLineLabels = drawerTwoLine,     ) } 
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherMenuOps.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherMenuOps.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherMenuOps.ktindex af4815eacb..2198b48391 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherMenuOps.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherMenuOps.kt@@ -166,6 +166,17 @@ internal fun LauncherViewModel.setDrawerListLayoutImpl(list: Boolean) {     viewModelScope.launch { ds.setBoolean(KEY_DRAWER_LIST_LAYOUT, list) } } +internal fun LauncherViewModel.setDrawerTwoLineLabelsImpl(twoLine: Boolean) {+    settingsState.value = settingsState.value.copy(drawerTwoLineLabels = twoLine)+    drawerState.value = drawerState.value.copy(twoLineLabels = twoLine)+    viewModelScope.launch { ds.setBoolean(KEY_DRAWER_TWO_LINE, twoLine) }+}++internal fun LauncherViewModel.setAddAppsToHomeImpl(enabled: Boolean) {+    settingsState.value = settingsState.value.copy(addAppsToHome = enabled)+    viewModelScope.launch { ds.setBoolean(KEY_ADD_APPS_TO_HOME, enabled) }+}+ internal fun LauncherViewModel.pickWallpaperImpl() {     bridge?.pickWallpaper() }
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.ktindex c010e6d681..74bcd1fa41 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherUiContract.kt@@ -217,6 +217,8 @@ data class DrawerUiState(      * tiles. Bigger targets and left-aligned names, which is what makes the list easier to read.      */     val listLayout: Boolean = false,+    /** GrapheneOS `pref_enable_two_line_toggle` (default off): drawer grid labels may wrap to two lines. */+    val twoLineLabels: Boolean = false,     /**      * Whether the work profile is paused, or null when this build cannot pause it.      *@@ -360,6 +362,9 @@ data class SettingsUiState(     val showLabels: Boolean = true,     val iconScale: Float = 1f,     val drawerListLayout: Boolean = false,+    val drawerTwoLineLabels: Boolean = false,+    /** GrapheneOS `pref_add_icon_to_home` (default on). */+    val addAppsToHome: Boolean = true,     val isDefaultHome: Boolean = false, ) @@ -373,6 +378,8 @@ interface SettingsActions {      /** Switches the app drawer between the tile grid and one app per row. */     fun setDrawerListLayout(list: Boolean) {}+    fun setDrawerTwoLineLabels(twoLine: Boolean) {}+    fun setAddAppsToHome(enabled: Boolean) {}     fun pickWallpaper() {}     fun requestDefaultHome() {} 
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.ktindex caa5b67cec..221e75e2c8 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherViewModel.kt@@ -149,6 +149,9 @@ internal const val KEY_HOTSEAT = "launcher_hotseat_slots" internal const val KEY_SHOW_LABELS = "launcher_show_labels" internal const val KEY_ICON_SCALE = "launcher_icon_scale" internal const val KEY_DRAWER_LIST_LAYOUT = "launcher_drawer_list_layout"+internal const val KEY_DRAWER_TWO_LINE = "launcher_drawer_two_line"+internal const val KEY_ADD_APPS_TO_HOME = "launcher_add_apps_to_home"+internal const val KEY_KNOWN_APPS = "launcher_known_apps" internal const val KEY_SEEDED = "launcher_seeded"  /** Launcher3's own all-apps blur, in pixels; density-independent enough not to be a dp. */
launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerCells.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerCells.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerCells.ktindex 8ddd878a8a..f9fca0a586 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerCells.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/DrawerCells.kt@@ -80,6 +80,7 @@ internal fun DrawerCell(             // A row whose name sits beside the icon would otherwise carry it twice. The name is             // always drawn in list mode: an unlabelled list of icons is just a narrow grid.             showLabel = state.showLabels && !listLayout,+            labelMaxLines = if (state.twoLineLabels && !listLayout) 2 else 1,         )     }     val badgedIcon = @Composable {
launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.ktindex 1130df6c70..7be5873ebf 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/SettingsContent.kt@@ -123,6 +123,14 @@ fun SettingsContent(                 )             } +            SettingsSwitchRow(+                title = "Add apps to Home screen",+                supportingText = "Newly installed apps are added to the home screen",+                checked = state.addAppsToHome,+                onCheckedChange = actions::setAddAppsToHome,+                leadingContent = { IconApps() },+            )+             SettingsDivider()              SettingsSection(title = stringResource(R.string.settings_app_drawer)) {@@ -133,6 +141,12 @@ fun SettingsContent(                     onCheckedChange = actions::setDrawerListLayout,                     leadingContent = { IconList() },                 )+                SettingsSwitchRow(+                    title = "Two-line labels",+                    supportingText = "App names in the drawer may use two lines",+                    checked = state.drawerTwoLineLabels,+                    onCheckedChange = actions::setDrawerTwoLineLabels,+                )             }         }     }
launcher/src/main/java/com/vayunmathur/launcher/ui/components/LauncherAppIcon.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/components/LauncherAppIcon.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/components/LauncherAppIcon.ktindex 7a49be9463..fec34d2644 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/components/LauncherAppIcon.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/components/LauncherAppIcon.kt@@ -70,6 +70,7 @@ fun LauncherAppIcon(     scale: Float = 1f,     showLabel: Boolean = true,     dimmed: Boolean = false,+    labelMaxLines: Int = 1, ) {     val loader = LocalIconLoader.current     val bitmap by produceState<ImageBitmap?>(initialValue = null, key, loader) {@@ -82,6 +83,7 @@ fun LauncherAppIcon(         modifier = modifier,         showLabel = showLabel,         dimmed = dimmed,+        labelMaxLines = labelMaxLines,     ) {         LauncherIconImage(bitmap, label, scale)     }@@ -119,6 +121,7 @@ internal fun LauncherIconCell(     modifier: Modifier,     showLabel: Boolean,     dimmed: Boolean,+    labelMaxLines: Int = 1,     icon: @Composable () -> Unit, ) {     val density = LocalDensity.current@@ -138,7 +141,7 @@ internal fun LauncherIconCell(                 // `onSurface` text is illegible over a light one - which is most photographs.                 style = MaterialTheme.typography.labelSmall.copy(shadow = labelShadow(density)),                 color = MaterialTheme.colorScheme.onSurface,-                maxLines = 1,+                maxLines = labelMaxLines,                 overflow = TextOverflow.Ellipsis,                 textAlign = TextAlign.Center,                 modifier = Modifier.padding(top = 2.dp, start = 2.dp, end = 2.dp),
launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.ktindex 690b07b5ef..54a4c54f33 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt@@ -945,3 +945,12 @@ class FastScrollTest {         assertEquals(0.875f, FastScroll.fractionOf(9, sections = 4))     } }++class NewAppsTest {+    @Test fun `unseen returns only new in order`() {+        assertEquals(listOf("c"), NewApps.unseen(setOf("a", "b"), listOf("a", "b", "c", "c")))+    }+    @Test fun `unseen empty when known covers all`() {+        assertTrue(NewApps.unseen(setOf("a"), listOf("a")).isEmpty())+    }+}