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

Commit fce02f43 authored by Bryce Lee's avatar Bryce Lee
Browse files

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
parent 7477c179
Loading
Loading
Loading
Loading
+36 −1
Original line number Original line Diff line number Diff line
@@ -139,6 +139,41 @@ class PackageInstallerMonitorTest : SysuiTestCase() {
            verify(packageInstaller).unregisterSessionCallback(eq(callback))
            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
    @Test
    fun installSessions_newSessionsAreAdded() =
    fun installSessions_newSessionsAreAdded() =
        testScope.runTest {
        testScope.runTest {
+2 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.common.data.repository


import android.content.pm.PackageInstaller
import android.content.pm.PackageInstaller
import android.os.Handler
import android.os.Handler
import android.text.TextUtils
import com.android.internal.annotations.GuardedBy
import com.android.internal.annotations.GuardedBy
import com.android.systemui.common.shared.model.PackageInstallSession
import com.android.systemui.common.shared.model.PackageInstallSession
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
@@ -63,6 +64,7 @@ constructor(
                        synchronized(sessions) {
                        synchronized(sessions) {
                            sessions.putAll(
                            sessions.putAll(
                                packageInstaller.allSessions
                                packageInstaller.allSessions
                                    .filter { !TextUtils.isEmpty(it.appPackageName) }
                                    .map { session -> session.toModel() }
                                    .map { session -> session.toModel() }
                                    .associateBy { it.sessionId }
                                    .associateBy { it.sessionId }
                            )
                            )