diff options
2 files changed, 36 insertions, 1 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepositoryImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepositoryImplTest.kt index 9c0674dfbd6e..bc57ce6f95f5 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepositoryImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepositoryImplTest.kt @@ -245,6 +245,33 @@ class InstalledTilesComponentRepositoryImplTest : SysuiTestCase() { assertThat(flowForUser2).isNotEqualTo(flowForUser1) } + // Tests that a ServiceInfo that is returned by queryIntentServicesAsUser but shortly + // after uninstalled, doesn't crash SystemUI. + @Test + fun packageUninstalledAfterQuery_noCrash_noComponent() = + testScope.runTest { + val userId = 0 + val resolveInfo = + ResolveInfo(TEST_COMPONENT, hasPermission = true, defaultEnabled = true) + + val componentNames by collectLastValue(underTest.getInstalledTilesComponents(userId)) + + whenever( + packageManager.queryIntentServicesAsUser( + matchIntent(), + matchFlags(), + eq(userId) + ) + ) + .thenReturn(listOf(resolveInfo)) + whenever(packageManager.getComponentEnabledSetting(TEST_COMPONENT)) + .thenThrow(IllegalArgumentException()) + kosmos.fakePackageChangeRepository.notifyChange(PackageChangeModel.Empty) + runCurrent() + + assertThat(componentNames).isEmpty() + } + companion object { private val INTENT = Intent(TileService.ACTION_QS_TILE) private val FLAGS = diff --git a/packages/SystemUI/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepository.kt b/packages/SystemUI/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepository.kt index 93021bab606d..cfcea9829610 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/pipeline/data/repository/InstalledTilesComponentRepository.kt @@ -91,7 +91,15 @@ constructor( .queryIntentServicesAsUser(INTENT, FLAGS, userId) .mapNotNull { it.serviceInfo } .filter { it.permission == BIND_QUICK_SETTINGS_TILE } - .filter { packageManager.isComponentActuallyEnabled(it) } + .filter { + try { + packageManager.isComponentActuallyEnabled(it) + } catch (e: IllegalArgumentException) { + // If the package is not found, it means it was uninstalled between query + // and now. So it's clearly not enabled. + false + } + } .mapTo(mutableSetOf()) { it.componentName } } |