From 30ead8d85d6f2aeab8ae78040e82424041653895 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Mon, 13 Sep 2021 14:36:39 -0400 Subject: [PATCH] Show privacy dialog on secondary user calls When calls are performed by a secondary user, the attribution is to UID 1000, so they don't match the current user. However, as they are marked with isPhoneCall, show them anyway. Test: atest PrivacyDialogControllerTest (fails without fix) Fixes: 198552515 Change-Id: I11682eceb578ab3b9bf1b2573294af8ca418e6e2 --- .../systemui/privacy/PrivacyDialogController.kt | 8 ++++++-- .../privacy/PrivacyDialogControllerTest.kt | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt index a626681c0b01d..3f6380f7ef703 100644 --- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt +++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt @@ -155,7 +155,7 @@ class PrivacyDialogController( val items = usage.mapNotNull { val type = filterType(permGroupToPrivacyType(it.permGroupName)) val userInfo = userInfos.firstOrNull { ui -> ui.id == UserHandle.getUserId(it.uid) } - userInfo?.let { ui -> + if (userInfo != null || it.isPhoneCall) { type?.let { t -> // Only try to get the app name if we actually need it val appName = if (it.isPhoneCall) { @@ -171,10 +171,14 @@ class PrivacyDialogController( it.attribution, it.lastAccess, it.isActive, - ui.isManagedProfile, + // If there's no user info, we're in a phoneCall in secondary user + userInfo?.isManagedProfile ?: false, it.isPhoneCall ) } + } else { + // No matching user or phone call + null } } uiExecutor.execute { diff --git a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt index 03248f7e3a70b..8181d3070618a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt @@ -22,6 +22,7 @@ import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.pm.UserInfo +import android.os.Process.SYSTEM_UID import android.os.UserHandle import android.permission.PermGroupUsage import android.permission.PermissionManager @@ -550,6 +551,21 @@ class PrivacyDialogControllerTest : SysuiTestCase() { verify(dialog, never()).dismiss() } + @Test + fun testCallOnSecondaryUser() { + // Calls happen in + val usage = createMockPermGroupUsage(uid = SYSTEM_UID, isPhoneCall = true) + `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) + `when`(userTracker.userProfiles).thenReturn(listOf( + UserInfo(ENT_USER_ID, "", 0) + )) + + controller.showDialog(context) + exhaustExecutors() + + verify(dialog).show() + } + private fun exhaustExecutors() { FakeExecutor.exhaustExecutors(backgroundExecutor, uiExecutor) }