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

Commit bd409916 authored by Mark Renouf's avatar Mark Renouf
Browse files

Screenshot detection: MATCH_ANY_USER for resolving pacakage label

The user of the activity which detected screenshot is unknown to
SystemUI. Adding MATCH_ANY_USER resolves an error when the package is
not installed for the primary user.

Bug: 332622475
Flag: EXEMPT bugfix
Test: manually
Change-Id: I9699091bb44e841343f43f40da2727215bbde556
parent 9e3ba6f7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.screenshot

import android.content.pm.PackageManager
import android.content.pm.PackageManager.ComponentInfoFlags
import android.content.pm.PackageManager.MATCH_ANY_USER
import android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS
import android.view.Display
import android.view.IWindowManager
@@ -47,7 +48,8 @@ constructor(
        // Convert component names to app names.
        return components.map {
            packageManager
                .getActivityInfo(it, ComponentInfoFlags.of(MATCH_DISABLED_COMPONENTS.toLong()))
                .getActivityInfo(it, ComponentInfoFlags.of(
                    (MATCH_DISABLED_COMPONENTS or MATCH_ANY_USER).toLong()))
                .loadLabel(packageManager)
        }
    }
+6 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.screenshot
import android.content.ComponentName
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.MATCH_ANY_USER
import android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS
import android.testing.AndroidTestingRunner
import android.view.Display
@@ -191,16 +192,16 @@ class ScreenshotDetectionControllerTest {
        whenever(
            packageManager.getActivityInfo(
                eq(component),
                argThat(includesFlagBits(MATCH_DISABLED_COMPONENTS))
                argThat(includesFlagBits(MATCH_DISABLED_COMPONENTS or MATCH_ANY_USER))
            )
        ).thenReturn(activityInfo);
        ).thenReturn(activityInfo)

        whenever(
            packageManager.getActivityInfo(
                eq(component),
                argThat(excludesFlagBits(MATCH_DISABLED_COMPONENTS))
            )
        ).thenThrow(PackageManager.NameNotFoundException::class.java);
        ).thenThrow(PackageManager.NameNotFoundException::class.java)

        whenever(windowManager.notifyScreenshotListeners(eq(Display.DEFAULT_DISPLAY)))
            .thenReturn(listOf(component))
@@ -212,5 +213,4 @@ class ScreenshotDetectionControllerTest {
        assertEquals(1, list.size)
        assertEquals(appName, list[0])
    }

}