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

Commit efe333be authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge "Ignore InstallSessions with null appPackageName." into main

parents 23a02a0e fce02f43
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -139,6 +139,41 @@ class PackageInstallerMonitorTest : SysuiTestCase() {
            verify(packageInstaller).unregisterSessionCallback(eq(callback))
        }

    @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 {
+2 −0
Original line number Diff line number Diff line
@@ -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 }
                            )