diff options
| author | 2024-08-26 10:29:26 -0700 | |
|---|---|---|
| committer | 2024-08-26 10:30:21 -0700 | |
| commit | fce02f43bcf6457a2b1da97a9bd5a85642649084 (patch) | |
| tree | 2193225210e2f283be0c4c729ad84701c99fd02c | |
| parent | 7477c179b16fc5a27d371fd85f8a392fa1c20a95 (diff) | |
Ignore InstallSessions with null appPackageName.
This changelist filters out InstallSessions without a appPackageName
set. This prevents trying to converting the session another class that
requires the package name to be non-null.
Test: atest PackageInstallerMonitorTest#installSessions_ignoreNullPackageNameSessions
Flag: EXEMPT bugfix
Fixes: 362276271
Change-Id: I6109f00b9ffbcbdbd41087ba0e7f0cc0c39381e8
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 } ) |