Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 772be0cc authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Prevent crash when a TileService is uninstalled" into main

parents ebb03a80 5ffb6213
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -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 =
+9 −1
Original line number Diff line number Diff line
@@ -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 }
    }