Modern Apps git

← Modern-Apps.git

launcher: drop icons whose launcher activity no longer exists

Commit
d64b17a32738d6b4bc4afb37866fc6749b61fccc
Author
Vayun Mathur <[email protected]>
When
2026-11-07 19:58 UTC (29 days ago)
Parents
47fb59a
Symptom: after an app update that renames or removes its
launcher activity (keeping the package), the home-screen icon
stays forever and every tap answers 'Could not open'.

Root cause: reconciliation judged APPLICATION rows by package
only (ReconcileUseCase + LauncherRepository.reconcile). A
package still present in the installed set kept the row alive
even though the stored className no longer resolves to any
launchable activity, and LauncherAppsMonitor.entryFor then
found nothing to launch.

Fix: thread the monitor's live activity list through
LauncherRepository.reconcile as a new ActivityKey set, carry
className on ReconcileUseCase.Item (from LauncherItemEntity),
and delete APPLICATION rows whose activity is absent from
that list. DEEP_SHORTCUT rows are exempt (a shortcut target
need not be a launcher activity), and an empty activity list
skips the check rather than deleting everything.

Verification: new ReconcileUseCaseTest cases cover a vanished
launcher activity (deleted) and a pinned shortcut whose
target is not a launcher activity (kept). Full module
verification runs at the end of the stack.

Diff

launcher/src/main/java/com/vayunmathur/launcher/data/LauncherItemEntity.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherItemEntity.kt b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherItemEntity.ktindex 446f38230c..887a3fa629 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherItemEntity.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherItemEntity.kt@@ -111,6 +111,7 @@ data class LauncherItemEntity(         profileSerial = profileSerial,         appWidgetId = appWidgetId,         hidden = hidden,+        className = className,     ) } 
launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.ktindex 6f9e7427bb..525192ddf1 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/data/LauncherRepository.kt@@ -2,6 +2,7 @@ package com.vayunmathur.launcher.data  import android.content.Context import androidx.room3.withWriteTransaction+import com.vayunmathur.launcher.domain.ActivityKey import com.vayunmathur.launcher.domain.AutoPlacer import com.vayunmathur.launcher.domain.CellRect import com.vayunmathur.launcher.domain.ContainerRef@@ -304,6 +305,7 @@ class LauncherRepository private constructor(context: Context) :         unavailable: Set<PackageKey>,         boundWidgetIds: Set<Int>,         unavailableProfiles: Set<Long> = emptySet(),+        installedActivities: Set<ActivityKey> = emptySet(),     ): List<Int> = db.withWriteTransaction {         val all = dao.getAll()         val actions = ReconcileUseCase.reconcile(@@ -312,6 +314,7 @@ class LauncherRepository private constructor(context: Context) :             unavailable = unavailable,             boundWidgetIds = boundWidgetIds,             unavailableProfiles = unavailableProfiles,+            installedActivities = installedActivities,         )         val byId = all.associateBy { it.id }         val orphanedWidgetIds = mutableListOf<Int>()
launcher/src/main/java/com/vayunmathur/launcher/domain/LauncherItemType.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/LauncherItemType.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/LauncherItemType.ktindex 93f0b425bd..08cf70480e 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/domain/LauncherItemType.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/LauncherItemType.kt@@ -30,3 +30,6 @@ enum class LauncherItemType {  * reboot.  */ data class PackageKey(val packageName: String, val profileSerial: Long)++/** Identity of one launchable activity of an app for a given user. */+data class ActivityKey(val packageName: String, val className: String, val profileSerial: Long)
launcher/src/main/java/com/vayunmathur/launcher/domain/ReconcileUseCase.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/domain/ReconcileUseCase.kt b/launcher/src/main/java/com/vayunmathur/launcher/domain/ReconcileUseCase.ktindex daf61ac24e..383c486446 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/domain/ReconcileUseCase.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/domain/ReconcileUseCase.kt@@ -22,6 +22,7 @@ object ReconcileUseCase {         val profileSerial: Long,         val appWidgetId: Int?,         val hidden: Boolean,+        val className: String? = null,     ) {         val key: PackageKey? get() = packageName?.let { PackageKey(it, profileSerial) }     }@@ -48,6 +49,7 @@ object ReconcileUseCase {         unavailable: Set<PackageKey>,         boundWidgetIds: Set<Int>,         unavailableProfiles: Set<Long> = emptySet(),+        installedActivities: Set<ActivityKey> = emptySet(),     ): List<Action> = items.mapNotNull { item ->         when (item.type) {             // A folder's existence depends on its children, which FolderRules owns.@@ -73,6 +75,19 @@ object ReconcileUseCase {                     item.profileSerial in unavailableProfiles ->                         Action.SetHidden(item.id, true).takeUnless { item.hidden }                     key in unavailable -> Action.SetHidden(item.id, true).takeUnless { item.hidden }+                    // The package is still installed but the stored launcher+                    // activity is gone (an update renamed or removed it):+                    // the row can never launch again, so it is dead weight+                    // exactly like an uninstalled app. Only APPLICATION rows+                    // are judged this way - a pinned shortcut's activity is+                    // not required to be a launcher activity at all. An+                    // empty [installedActivities] means the caller supplied+                    // no activity list, in which case this check is skipped+                    // rather than deleting everything.+                    key in installed && item.type == LauncherItemType.APPLICATION &&+                        installedActivities.isNotEmpty() && item.className != null &&+                        ActivityKey(key.packageName, item.className, key.profileSerial) !in installedActivities ->+                        Action.Delete(item.id)                     key in installed -> Action.SetHidden(item.id, false).takeIf { item.hidden }                     else -> Action.Delete(item.id)                 }
launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherAppsMonitor.kt
diff --git a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherAppsMonitor.kt b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherAppsMonitor.ktindex bf0fb06c7d..efd38b31f6 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherAppsMonitor.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherAppsMonitor.kt@@ -10,6 +10,7 @@ import android.os.Bundle import android.os.Process import android.os.UserHandle import android.os.UserManager+import com.vayunmathur.launcher.domain.ActivityKey import com.vayunmathur.launcher.domain.PackageKey import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -185,6 +186,11 @@ class LauncherAppsMonitor(context: Context, private val scope: CoroutineScope) {      * `onPackagesUnavailable`, so the callback-built [unavailable] set is      * empty for it and reconciliation would mistake its apps for uninstalled.      */+    /** Launchable activities present right now, for reconciliation. */+    fun installedActivityKeys(): Set<ActivityKey> = _apps.value.map {+        ActivityKey(it.componentName.packageName, it.componentName.className, it.profileSerial)+    }.toSet()+     fun unavailableProfileSerials(): Set<Long> = runCatching {         launcherApps.profiles             .filter { userManager.isQuietModeEnabled(it) }
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 cce1d7565b..0827572ea3 100644--- a/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt+++ b/launcher/src/main/java/com/vayunmathur/launcher/platform/LauncherLifecycleOps.kt@@ -51,6 +51,7 @@ internal fun LauncherViewModel.reconcileNowImpl() {             unavailable = appsMonitor.unavailable.value,             boundWidgetIds = widgetHost.boundIds(),             unavailableProfiles = appsMonitor.unavailableProfileSerials(),+            installedActivities = appsMonitor.installedActivityKeys(),         )         orphaned.forEach(widgets::release)         widgets.releaseOrphans(repository.usedWidgetIds())
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 a16e196f8d..0d4b2f615a 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/domain/LauncherDomainTest.kt@@ -283,6 +283,47 @@ class ReconcileUseCaseTest {         assertTrue(actions.isEmpty())     } +    @Test+    fun `an app whose launcher activity is gone is deleted even though its package remains`() {+        val item = app(1, here).copy(className = "com.example.here.OldMain")+        val actions = ReconcileUseCase.reconcile(+            items = listOf(item),+            installed = setOf(here),+            unavailable = emptySet(),+            boundWidgetIds = emptySet(),+            installedActivities = setOf(+                com.vayunmathur.launcher.domain.ActivityKey("com.example.here", "com.example.here.NewMain", 0),+            ),+        )+        assertEquals(listOf(ReconcileUseCase.Action.Delete(1)), actions)+    }++    @Test+    fun `a pinned shortcut is not judged against the launcher activity list`() {+        // A shortcut's target activity need not be launchable from a+        // drawer at all, so its absence from installedActivities is+        // not evidence that the row is dead.+        val shortcut = ReconcileUseCase.Item(+            id = 2,+            type = LauncherItemType.DEEP_SHORTCUT,+            packageName = here.packageName,+            profileSerial = here.profileSerial,+            appWidgetId = null,+            hidden = false,+            className = "com.example.here.ShortcutTarget",+        )+        val actions = ReconcileUseCase.reconcile(+            items = listOf(shortcut),+            installed = setOf(here),+            unavailable = emptySet(),+            boundWidgetIds = emptySet(),+            installedActivities = setOf(+                com.vayunmathur.launcher.domain.ActivityKey("com.example.here", "com.example.here.Main", 0),+            ),+        )+        assertTrue(actions.isEmpty())+    }+     @Test     fun `a widget whose id the host has forgotten is deleted`() {         val widget = ReconcileUseCase.Item(