launcher: wear drawer with our own flashlight cell
- Commit
d6e1034393f5dec9beb75b078179acfb15525281- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 16:32 UTC (11 minutes ago)
- Parents
5fe18d5
Replicate the stock Wear OS app-drawer experience in the merged launcher APK's watch experience, based on the pulled Pixel Watch sysui analysis (analysis/wear-launcher-spec.md, gitignored): AllAppsLauncherActivity/RecentsActivity in sysui are the drawer, while watch-face home, QS/notifications shades, tiles and assistant stay privileged system surfaces. Watch home gains a Quick actions section whose Flashlight cell launches our own WearFlashlightActivity by explicit component intent in this APK; the stock Google flashlight package is hidden in our drawer. Our flashlight is a screen torch at full brightness (double-tap toggles white/red, 120s timeout, Back exits) and uses the camera torch only when FEATURE_CAMERA_FLASH is present (Pixel Watch has none). All-apps gains long-press app-info (uninstall for user apps via system app-info). HOME: MainActivity already carries HOME+DEFAULT and is HOME-resolvable on the watch, forwarding to WearMainActivity; stock Wear OS offers no third-party HOME election or ROLE_HOME grant, documented in launcher/AGENTS.md. Verified: :launcher:testDevUnitTest, :launcher:lint, :launcher:lintVitalRelease (vital report skipped by AGP, no findings), :launcher:metadata (phone+wear regenerated).
Diff
launcher/AGENTS.md
diff --git a/launcher/AGENTS.md b/launcher/AGENTS.mdindex ddd9d00f51..046ece4379 100644--- a/launcher/AGENTS.md+++ b/launcher/AGENTS.md@@ -42,13 +42,25 @@ neither runs on the wrong form factor. ## Watch experience (in this module) - `ui/WearMainActivity` (`exported=false`, no launcher/HOME filter of its own) routes `ui/WearRoute` over home- (synced favorites, watch-local recents, companion shortcuts) /- all-apps drawer with local filter / settings rows that open only- system intents resolving on the watch.-- On stock Wear OS this is not the system HOME: the watch home is a- privileged system component with no public `CATEGORY_HOME` election- or `ROLE_HOME` grant for third-party apps, so the watch experience- never claims HOME (phone/TV HOME in `MainActivity` is unchanged).+ (synced favorites, watch-local recents, companion shortcuts,+ quick actions) / all-apps drawer with local filter and long-press+ app-info / settings rows that open only system intents resolving+ on the watch. The Quick actions row's Flashlight cell launches+ `ui/WearFlashlightActivity` by explicit component intent in this+ APK (our own screen torch: max brightness, double-tap white/red,+ camera torch only when `FEATURE_CAMERA_FLASH` exists); the stock+ Google flashlight package is hidden in our drawer. Analysis:+ `analysis/wear-launcher-spec.md` (gitignored).+- HOME on watch: `MainActivity`'s single filter already carries+ `HOME + DEFAULT`, so this APK is HOME-resolvable on a watch and+ forwards to `WearMainActivity`. On stock Wear OS there is still+ no third-party HOME election: sysui (`SysUiActivity`,+ `MAIN+HOME+HOME_MAIN`) is the privileged default and `ROLE_HOME`+ holder, with no user picker or grant for third parties, so the+ watch experience is selectable only where the OS offers a default-+ home choice (it cannot be forced by code) and never claims the+ watch-face home, QS/notifications shades or tiles, which stay+ system. Phone/TV HOME in `MainActivity` is unchanged. - Watch state persists in `data/WearLauncherStore` (`wear-launcher-favorites.json` / `wear-launcher-recents.json`); installed apps are enumerated by `platform/InstalledApps`, sections@@ -118,8 +130,9 @@ neither runs on the wrong form factor. ### Watch experience (ui/ + data/ + domain/ + platform/ + sync/) - com/vayunmathur/launcher/ui/WearMainActivity.kt — watch entry (exported=false) - com/vayunmathur/launcher/ui/WearRoute.kt, WearLauncherScreen.kt, WearAllAppsScreen.kt, WearSettingsScreen.kt+- com/vayunmathur/launcher/ui/WearFlashlightActivity.kt + WearFlashlightScreen.kt — our own watch flashlight (drawer hardcoded cell target) - com/vayunmathur/launcher/data/WearLauncherStore.kt-- com/vayunmathur/launcher/domain/WearLauncherModel.kt+- com/vayunmathur/launcher/domain/WearLauncherModel.kt + WearFlashlight.kt (flashlight modes) - com/vayunmathur/launcher/sync/WearLauncherSync.kt — phone conduit client node; favorites publish, watch-state receive, request-sync handling - com/vayunmathur/launcher/sync/WearLinkBridge.kt — watch conduit client node; favorites receive into the store, watch-state publish
launcher/src/main/AndroidManifest.xml
diff --git a/launcher/src/main/AndroidManifest.xml b/launcher/src/main/AndroidManifest.xmlindex 9f1598d8d4..c3279436b6 100644--- a/launcher/src/main/AndroidManifest.xml+++ b/launcher/src/main/AndroidManifest.xml@@ -113,6 +113,14 @@ </intent-filter> </activity> + <!-- Our own watch flashlight: the wear drawer's hardcoded cell launches+ it by explicit component intent in this APK. Not exported: only our+ drawer (same app) opens it. -->+ <activity+ android:name=".ui.WearFlashlightActivity"+ android:exported="false"+ android:theme="@style/Theme.Launcher" />+ <!-- Watch experience is paired with the phone app, not standalone. --> <meta-data android:name="com.google.android.wearable.standalone"
launcher/src/main/java/com/vayunmathur/launcher/domain/WearFlashlight.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearFlashlight.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearFlashlight.ktnew file mode 100644index 0000000000..093d92a73b--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearFlashlight.kt@@ -0,0 +1,13 @@+package com.vayunmathur.launcher.domain++/** Our own watch flashlight colour modes; mirrors the stock double-tap behaviour. */+enum class WearFlashlightMode { WHITE, RED }++/** Double-tap toggles white <-> red; single tap never changes mode. */+fun toggleWearFlashlightMode(mode: WearFlashlightMode): WearFlashlightMode = when (mode) {+ WearFlashlightMode.WHITE -> WearFlashlightMode.RED+ WearFlashlightMode.RED -> WearFlashlightMode.WHITE+}++/** Auto-off after this long with no interaction, so the watch is not left lit in a pocket. */+const val WEAR_FLASHLIGHT_TIMEOUT_MS: Long = 120_000L
launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherModel.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherModel.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherModel.ktindex 3474288b34..6ed5d3cec3 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherModel.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/WearLauncherModel.kt@@ -32,6 +32,9 @@ val WEAR_COMPANIONS: List<WearCompanion> = listOf( const val MAX_RECENTS = 6 +/** Stock Google flashlight: hidden in our drawer, replaced by our own flashlight cell. */+const val STOCK_FLASHLIGHT_PACKAGE = "com.google.android.clockwork.flashlight"+ /** The watch home's sections, all derived from installed apps + synced favorites. */ data class WearLauncherSections( /** Synced phone favorites that are installed on the watch, in phone rank order. */@@ -66,6 +69,7 @@ fun buildWearLauncherSections( val sorted = installed .filter { it.packageName.isNotBlank() && it.className.isNotBlank() } .filter { it.packageName != ownPackageName }+ .filter { it.packageName != STOCK_FLASHLIGHT_PACKAGE } .sortedWith(compareBy({ it.label.lowercase() }, { it.packageName }, { it.className })) // The drawer shows one row per package; favorites may name any component. val apps = sorted.distinctBy { it.packageName }
launcher/src/main/java/com/vayunmathur/launcher/platform/InstalledApps.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/InstalledApps.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/InstalledApps.ktindex c9666464ac..dc62b83ec9 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/InstalledApps.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/InstalledApps.kt@@ -58,6 +58,18 @@ object InstalledApps { fun settingsIntent(target: WearSettingsTarget): Intent = Intent(target.action) + /** Our own flashlight, by explicit component in this APK (the drawer hardcoded cell). */+ fun flashlightIntent(context: Context): Intent =+ Intent(Intent.ACTION_MAIN)+ .setComponent(ComponentName(context.packageName, "com.vayunmathur.launcher.ui.WearFlashlightActivity"))+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)++ /** App-info screen for [app] (offers uninstall for user apps) — the drawer's long-press action. */+ fun appDetailsIntent(app: WatchApp): Intent =+ Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)+ .setData(android.net.Uri.parse("package:" + app.packageName))+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ /** Generic system-settings fallback entry point. */ fun systemSettingsIntent(): Intent = Intent(Settings.ACTION_SETTINGS) }
launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.ktindex 5f3716de14..57f0f7c57e 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearAllAppsScreen.kt@@ -47,6 +47,7 @@ fun WearAllAppsScreen(store: WearLauncherStore, onBack: () -> Unit) { } WearAllAppsContent( all = all,+ onAppInfo = { app -> runCatching { context.startActivity(InstalledApps.appDetailsIntent(app)) } }, onLaunch = { app -> val intent = InstalledApps.launchIntent(context, app) ?: return@WearAllAppsContent store.recordLaunch(app.packageName)@@ -63,6 +64,7 @@ fun WearAllAppsScreen(store: WearLauncherStore, onBack: () -> Unit) { @Composable internal fun WearAllAppsContent( all: List<WatchApp>,+ onAppInfo: (WatchApp) -> Unit = {}, onLaunch: (WatchApp) -> Unit, onBack: () -> Unit, ) {@@ -106,7 +108,7 @@ internal fun WearAllAppsContent( } } else { items(filtered, key = { it.packageName }) { app ->- WearAppChip(app) { onLaunch(app) }+ WearAppChip(app, onLongClick = { onAppInfo(app) }) { onLaunch(app) } } } }
launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightActivity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightActivity.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightActivity.ktnew file mode 100644index 0000000000..8ae757286a--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightActivity.kt@@ -0,0 +1,55 @@+package com.vayunmathur.launcher.ui++import android.hardware.camera2.CameraManager+import android.os.Bundle+import android.view.WindowManager+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.lifecycle.lifecycleScope+import androidx.wear.compose.material.MaterialTheme+import com.vayunmathur.launcher.domain.WEAR_FLASHLIGHT_TIMEOUT_MS+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++/**+ * Our own flashlight, in this APK. The wear drawer hardcoded cell launches+ * it by explicit component intent (`cmp=com.vayunmathur.launcher/.ui.WearFlashlightActivity`),+ * replacing the stock drawer's Google flashlight component in OUR drawer only+ * (the system QS flashlight cell inside sysui is not replaceable).+ * Uses the camera torch only when the watch exposes FEATURE_CAMERA_FLASH;+ * otherwise (Pixel Watch) the max-brightness screen is the torch.+ */+class WearFlashlightActivity : ComponentActivity() {++ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)+ val attrs = window.attributes+ attrs.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL+ window.attributes = attrs+ setCameraTorchIfAvailable(true)+ lifecycleScope.launch {+ delay(WEAR_FLASHLIGHT_TIMEOUT_MS)+ finish()+ }+ setContent {+ MaterialTheme {+ WearFlashlightScreen()+ }+ }+ }++ override fun onDestroy() {+ setCameraTorchIfAvailable(false)+ super.onDestroy()+ }++ private fun setCameraTorchIfAvailable(on: Boolean) {+ if (!packageManager.hasSystemFeature(android.content.pm.PackageManager.FEATURE_CAMERA_FLASH)) return+ runCatching {+ val cameraManager = getSystemService(CameraManager::class.java)+ val cameraId = cameraManager.cameraIdList.firstOrNull() ?: return+ cameraManager.setTorchMode(cameraId, on)+ }+ }+}
launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightScreen.ktnew file mode 100644index 0000000000..7dc99b6b2a--- /dev/null+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearFlashlightScreen.kt@@ -0,0 +1,35 @@+package com.vayunmathur.launcher.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.pointerInput+import com.vayunmathur.launcher.domain.WearFlashlightMode+import com.vayunmathur.launcher.domain.toggleWearFlashlightMode++/**+ * Our own screen flashlight: full-screen light at max brightness.+ * Double-tap toggles white/red (stock behaviour); Back or the activity+ * timeout turns it off. No camera LED is assumed — Pixel Watch exposes+ * no FEATURE_CAMERA_FLASH, so the screen is the light source.+ */+@Composable+fun WearFlashlightScreen() {+ var mode by remember { mutableStateOf(WearFlashlightMode.WHITE) }+ Box(+ Modifier+ .fillMaxSize()+ .background(if (mode == WearFlashlightMode.WHITE) Color.White else Color.Red)+ .pointerInput(Unit) {+ detectTapGestures(onDoubleTap = { mode = toggleWearFlashlightMode(mode) })+ },+ )+}
launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.ktindex 905eb5564e..526a3c61e4 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/ui/WearLauncherScreen.kt@@ -2,6 +2,8 @@ package com.vayunmathur.launcher.ui import android.graphics.drawable.Drawable import androidx.compose.foundation.Image+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size@@ -51,6 +53,7 @@ fun WearLauncherScreen( WearLauncherContent( sections = sections, installedEmpty = installed.isEmpty(),+ onOpenFlashlight = { runCatching { context.startActivity(InstalledApps.flashlightIntent(context)) } }, onLaunch = { app -> val intent = InstalledApps.launchIntent(context, app) ?: return@WearLauncherContent store.recordLaunch(app.packageName)@@ -69,6 +72,7 @@ fun WearLauncherScreen( internal fun WearLauncherContent( sections: com.vayunmathur.launcher.domain.WearLauncherSections, installedEmpty: Boolean,+ onOpenFlashlight: () -> Unit, onLaunch: (WatchApp) -> Unit, onOpenAllApps: () -> Unit, onOpenSettings: () -> Unit,@@ -93,6 +97,15 @@ internal fun WearLauncherContent( modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp), ) }+ item { WearSectionHeader(stringResource(R.string.wear_quick_actions)) }+ item {+ Chip(+ onClick = onOpenFlashlight,+ label = { Text(stringResource(R.string.wear_flashlight), maxLines = 1) },+ colors = ChipDefaults.primaryChipColors(),+ modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+ )+ } if (installedEmpty) { item { Text(@@ -172,13 +185,18 @@ internal fun WearSectionHeader(text: String) { /** One launchable app row with its on-device icon (loaded from PackageManager). */ @Composable-internal fun WearAppChip(app: WatchApp, onClick: () -> Unit) {+internal fun WearAppChip(app: WatchApp, onLongClick: (() -> Unit)? = null, onClick: () -> Unit) { val context = LocalContext.current val icon by produceState<Drawable?>(initialValue = null, app.packageName) { value = withContext(Dispatchers.IO) { runCatching { context.packageManager.getApplicationIcon(app.packageName) }.getOrNull() } }+ androidx.compose.foundation.layout.Box(+ if (onLongClick != null) Modifier.pointerInput(app.packageName) {+ detectTapGestures(onLongPress = { onLongClick() })+ } else Modifier,+ ) { Chip( onClick = onClick, label = { Text(app.label, maxLines = 1) },@@ -194,4 +212,5 @@ internal fun WearAppChip(app: WatchApp, onClick: () -> Unit) { colors = ChipDefaults.secondaryChipColors(), modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp), )+ } }
launcher/src/main/res/values/wear_strings.xml
diff --git a/launcher/src/main/res/values/wear_strings.xml b/launcher/src/main/res/values/wear_strings.xmlindex 43d9b993aa..900aead895 100644--- a/launcher/src/main/res/values/wear_strings.xml+++ b/launcher/src/main/res/values/wear_strings.xml@@ -4,6 +4,8 @@ <string name="wear_recent">Recent</string> <string name="wear_our_apps">Our apps</string> <string name="wear_all_apps">All apps</string>+ <string name="wear_quick_actions">Quick actions</string>+ <string name="wear_flashlight">Flashlight</string> <string name="wear_settings">Settings</string> <string name="wear_search_apps">Search apps</string> <string name="wear_no_apps">No launchable apps found on this watch yet.</string>
launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt
diff --git a/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt b/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.ktindex ed07784f93..f808ecee5d 100644--- a/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt+++ b/launcher/src/screenshotTest/kotlin/com/vayunmathur/launcher/ui/WearMetadataPreviews.kt@@ -37,6 +37,7 @@ class WearMetadataPreviews { WearLauncherContent( sections = WearLauncherSections(favorites = fixtureApps.take(2), recents = fixtureApps.drop(2), companions = fixtureApps, all = fixtureApps), installedEmpty = false,+ onOpenFlashlight = {}, onLaunch = {}, onOpenAllApps = {}, onOpenSettings = {},@@ -44,6 +45,13 @@ class WearMetadataPreviews { } } + @PreviewTest+ @Preview(name = "4-flashlight-round", device = ROUND, group = "wear")+ @Composable+ fun Preview4FlashlightRound() {+ RoundPreview { WearFlashlightScreen() }+ }+ @PreviewTest @Preview(name = "2-all-apps-round", device = ROUND, group = "wear") @Composable
launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherModelTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherModelTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherModelTest.ktindex 79771de9a7..33ec4091a5 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherModelTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/WearLauncherModelTest.kt@@ -8,6 +8,23 @@ import kotlin.test.assertTrue class WearLauncherModelTest { + @Test+ fun flashlightModeDoubleTapToggles() {+ assertEquals(WearFlashlightMode.RED, toggleWearFlashlightMode(WearFlashlightMode.WHITE))+ assertEquals(WearFlashlightMode.WHITE, toggleWearFlashlightMode(WearFlashlightMode.RED))+ }++ @Test+ fun stockFlashlightHiddenInOurDrawer() {+ val sections = buildWearLauncherSections(+ installed = listOf(app(STOCK_FLASHLIGHT_PACKAGE, "Flashlight"), app("com.example.alpha", "alpha")),+ snapshot = WearFavoritesSnapshot(0L, emptyList()),+ recents = emptyList(),+ ownPackageName = "com.vayunmathur.launcher",+ )+ assertEquals(listOf("com.example.alpha"), sections.all.map { it.packageName })+ }+ private fun app(pkg: String, label: String, cls: String = "$pkg.Main") = WatchApp(pkg, cls, label)
metadata_data/photos/launcher/phone/2.png
diff --git a/metadata_data/photos/launcher/phone/2.png b/metadata_data/photos/launcher/phone/2.pngindex c077aebe70..d016455dc2 100644Binary files a/metadata_data/photos/launcher/phone/2.png and b/metadata_data/photos/launcher/phone/2.png differ
metadata_data/photos/launcher/phone/4.png
diff --git a/metadata_data/photos/launcher/phone/4.png b/metadata_data/photos/launcher/phone/4.pngindex 5331828ccb..5a0c494c6e 100644Binary files a/metadata_data/photos/launcher/phone/4.png and b/metadata_data/photos/launcher/phone/4.png differ
metadata_data/photos/launcher/phone/6.png
diff --git a/metadata_data/photos/launcher/phone/6.png b/metadata_data/photos/launcher/phone/6.pngnew file mode 100644index 0000000000..96abd605f1Binary files /dev/null and b/metadata_data/photos/launcher/phone/6.png differ
metadata_data/photos/launcher/wear/1.png
diff --git a/metadata_data/photos/launcher/wear/1.png b/metadata_data/photos/launcher/wear/1.pngindex 61e55288c4..711ed71c35 100644Binary files a/metadata_data/photos/launcher/wear/1.png and b/metadata_data/photos/launcher/wear/1.png differ
metadata_data/photos/launcher/wear/4.png
diff --git a/metadata_data/photos/launcher/wear/4.png b/metadata_data/photos/launcher/wear/4.pngnew file mode 100644index 0000000000..0fc25e4e59Binary files /dev/null and b/metadata_data/photos/launcher/wear/4.png differ