Loading packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt +55 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.common.shared.model.PackageInstallSession import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.backgroundScope import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.log.logcatLogBuffer import com.android.systemui.testKosmos Loading Loading @@ -172,6 +175,58 @@ class PackageInstallerMonitorTest : SysuiTestCase() { assertThat(sessions?.size).isEqualTo(1) } @Test fun onCreateUpdatedSession_ignoreNullPackageNameSessions() = kosmos.runTest { val nullPackageSession = SessionInfo().apply { sessionId = 1 appPackageName = null appIcon = icon1 } val wellFormedSession = SessionInfo().apply { sessionId = 2 appPackageName = "pkg_name" appIcon = icon2 } defaultSessions = listOf(wellFormedSession) whenever(packageInstaller.allSessions).thenReturn(defaultSessions) whenever(packageInstaller.getSessionInfo(1)).thenReturn(nullPackageSession) whenever(packageInstaller.getSessionInfo(2)).thenReturn(wellFormedSession) val packageInstallerMonitor = PackageInstallerMonitor( handler, backgroundScope, logcatLogBuffer("PackageInstallerRepositoryImplTest"), packageInstaller, ) val sessions by collectLastValue(packageInstallerMonitor.installSessionsForPrimaryUser) // Verify flow updated with the new session assertThat(sessions) .comparingElementsUsing(represents) .containsExactlyElementsIn(defaultSessions) val callback = withArgCaptor<PackageInstaller.SessionCallback> { verify(packageInstaller).registerSessionCallback(capture(), eq(handler)) } // New session added callback.onCreated(nullPackageSession.sessionId) // Verify flow updated with the new session assertThat(sessions) .comparingElementsUsing(represents) .containsExactlyElementsIn(defaultSessions) } @Test fun installSessions_newSessionsAreAdded() = testScope.runTest { Loading packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt +8 −5 Original line number Diff line number Diff line Loading @@ -64,15 +64,14 @@ constructor( synchronized(sessions) { sessions.putAll( packageInstaller.allSessions .filter { !TextUtils.isEmpty(it.appPackageName) } .map { session -> session.toModel() } .mapNotNull { session -> session.toModel() } .associateBy { it.sessionId } ) updateInstallerSessionsFlow() } packageInstaller.registerSessionCallback( this@PackageInstallerMonitor, bgHandler bgHandler, ) } else { synchronized(sessions) { Loading Loading @@ -130,7 +129,7 @@ constructor( if (session == null) { sessions.remove(sessionId) } else { sessions[sessionId] = session.toModel() session.toModel()?.apply { sessions[sessionId] = this } } updateInstallerSessionsFlow() } Loading @@ -144,7 +143,11 @@ constructor( companion object { const val TAG = "PackageInstallerMonitor" private fun PackageInstaller.SessionInfo.toModel(): PackageInstallSession { private fun PackageInstaller.SessionInfo.toModel(): PackageInstallSession? { if (TextUtils.isEmpty(this.appPackageName)) { return null } return PackageInstallSession( sessionId = this.sessionId, packageName = this.appPackageName, Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/common/data/repository/PackageInstallerMonitorTest.kt +55 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,9 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.common.shared.model.PackageInstallSession import com.android.systemui.coroutines.collectLastValue import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.backgroundScope import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.log.logcatLogBuffer import com.android.systemui.testKosmos Loading Loading @@ -172,6 +175,58 @@ class PackageInstallerMonitorTest : SysuiTestCase() { assertThat(sessions?.size).isEqualTo(1) } @Test fun onCreateUpdatedSession_ignoreNullPackageNameSessions() = kosmos.runTest { val nullPackageSession = SessionInfo().apply { sessionId = 1 appPackageName = null appIcon = icon1 } val wellFormedSession = SessionInfo().apply { sessionId = 2 appPackageName = "pkg_name" appIcon = icon2 } defaultSessions = listOf(wellFormedSession) whenever(packageInstaller.allSessions).thenReturn(defaultSessions) whenever(packageInstaller.getSessionInfo(1)).thenReturn(nullPackageSession) whenever(packageInstaller.getSessionInfo(2)).thenReturn(wellFormedSession) val packageInstallerMonitor = PackageInstallerMonitor( handler, backgroundScope, logcatLogBuffer("PackageInstallerRepositoryImplTest"), packageInstaller, ) val sessions by collectLastValue(packageInstallerMonitor.installSessionsForPrimaryUser) // Verify flow updated with the new session assertThat(sessions) .comparingElementsUsing(represents) .containsExactlyElementsIn(defaultSessions) val callback = withArgCaptor<PackageInstaller.SessionCallback> { verify(packageInstaller).registerSessionCallback(capture(), eq(handler)) } // New session added callback.onCreated(nullPackageSession.sessionId) // Verify flow updated with the new session assertThat(sessions) .comparingElementsUsing(represents) .containsExactlyElementsIn(defaultSessions) } @Test fun installSessions_newSessionsAreAdded() = testScope.runTest { Loading
packages/SystemUI/src/com/android/systemui/common/data/repository/PackageInstallerMonitor.kt +8 −5 Original line number Diff line number Diff line Loading @@ -64,15 +64,14 @@ constructor( synchronized(sessions) { sessions.putAll( packageInstaller.allSessions .filter { !TextUtils.isEmpty(it.appPackageName) } .map { session -> session.toModel() } .mapNotNull { session -> session.toModel() } .associateBy { it.sessionId } ) updateInstallerSessionsFlow() } packageInstaller.registerSessionCallback( this@PackageInstallerMonitor, bgHandler bgHandler, ) } else { synchronized(sessions) { Loading Loading @@ -130,7 +129,7 @@ constructor( if (session == null) { sessions.remove(sessionId) } else { sessions[sessionId] = session.toModel() session.toModel()?.apply { sessions[sessionId] = this } } updateInstallerSessionsFlow() } Loading @@ -144,7 +143,11 @@ constructor( companion object { const val TAG = "PackageInstallerMonitor" private fun PackageInstaller.SessionInfo.toModel(): PackageInstallSession { private fun PackageInstaller.SessionInfo.toModel(): PackageInstallSession? { if (TextUtils.isEmpty(this.appPackageName)) { return null } return PackageInstallSession( sessionId = this.sessionId, packageName = this.appPackageName, Loading