diff options
| author | 2024-08-26 21:48:43 +0000 | |
|---|---|---|
| committer | 2024-08-26 21:48:43 +0000 | |
| commit | efe333be51c43f71e519387059064703fb016ad7 (patch) | |
| tree | 6ea309236c0b44bc374a9e50dc1905ba16225458 | |
| parent | 23a02a0efc2fc20db1f752e2c5e339b76808c44f (diff) | |
| parent | fce02f43bcf6457a2b1da97a9bd5a85642649084 (diff) | |
Merge "Ignore InstallSessions with null appPackageName." into main
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 } ) |