diff options
2 files changed, 38 insertions, 1 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt index 5556b04c2d20..4c908dd895c7 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt @@ -140,6 +140,41 @@ class PackageInstallerMonitorTest : SysuiTestCase() { } @Test + fun installSessions_ignoreNullPackageNameSessions() = + testScope.runTest { + val nullPackageSession = + SessionInfo().apply { + sessionId = 1 + appPackageName = null + appIcon = icon1 + } + val wellFormedSession = + SessionInfo().apply { + sessionId = 2 + appPackageName = "pkg_name" + appIcon = icon2 + } + + defaultSessions = listOf(nullPackageSession, wellFormedSession) + + whenever(packageInstaller.allSessions).thenReturn(defaultSessions) + whenever(packageInstaller.getSessionInfo(1)).thenReturn(nullPackageSession) + whenever(packageInstaller.getSessionInfo(2)).thenReturn(wellFormedSession) + + val packageInstallerMonitor = + PackageInstallerMonitor( + handler, + kosmos.applicationCoroutineScope, + logcatLogBuffer("PackageInstallerRepositoryImplTest"), + packageInstaller, + ) + + val sessions by + testScope.collectLastValue(packageInstallerMonitor.installSessionsForPrimaryUser) + assertThat(sessions?.size).isEqualTo(1) + } + + @Test fun installSessions_newSessionsAreAdded() = testScope.runTest { val installSessions by collectLastValue(underTest.installSessionsForPrimaryUser) @@ -177,7 +212,7 @@ class PackageInstallerMonitorTest : SysuiTestCase() { } // Session 1 finished successfully - callback.onFinished(1, /* success = */ true) + callback.onFinished(1, /* success= */ true) runCurrent() // Verify flow updated with session 1 removed diff --git a/packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt b/packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt index 46db34618c70..208adc22a3e0 100644 --- a/packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt +++ b/packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt @@ -18,6 +18,7 @@ package com.android.systemui.common.data.repository import android.content.pm.PackageInstaller import android.os.Handler +import android.text.TextUtils import com.android.internal.annotations.GuardedBy import com.android.systemui.common.shared.model.PackageInstallSession import com.android.systemui.dagger.SysUISingleton @@ -63,6 +64,7 @@ constructor( synchronized(sessions) { sessions.putAll( packageInstaller.allSessions + .filter { !TextUtils.isEmpty(it.appPackageName) } .map { session -> session.toModel() } .associateBy { it.sessionId } ) |