Change landing page from PrivacyDialog

The landing page is now the permissions page for that app

Fixes: 179699198
Test: atest com.android.systemui.privacy
Change-Id: If7d3f982b45cce5198a8061094bc0a0a0b151fe4
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialog.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialog.kt
index 3f79be8..680a617 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialog.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialog.kt
@@ -41,13 +41,12 @@
  * @param context A context to create the dialog
  * @param list list of elements to show in the dialog. The elements will show in the same order they
  *             appear in the list
- * @param activityStarter a callback to start an activity for a given permission group name (as
- *                        given by [PrivacyType.permGroupName])
+ * @param activityStarter a callback to start an activity for a given package name and user id
  */
 class PrivacyDialog(
     context: Context,
     private val list: List<PrivacyElement>,
-    activityStarter: (String) -> Unit
+    activityStarter: (String, Int) -> Unit
 ) : SystemUIDialog(context, R.style.ScreenRecord) {
 
     private val dismissListeners = mutableListOf<WeakReference<OnDialogDismissed>>()
@@ -129,7 +128,7 @@
         } ?: firstLine
         newView.requireViewById<TextView>(R.id.text).text = finalText
         newView.apply {
-            tag = element.type.permGroupName
+            setTag(element)
             setOnClickListener(clickListener)
         }
         return newView
@@ -152,12 +151,17 @@
     }
 
     private val clickListener = View.OnClickListener { v ->
-        v.tag?.let { activityStarter(it as String) }
+        v.tag?.let {
+            val element = it as PrivacyElement
+            activityStarter(element.packageName, element.userId)
+        }
     }
 
     /** */
     data class PrivacyElement(
         val type: PrivacyType,
+        val packageName: String,
+        val userId: Int,
         val applicationName: CharSequence,
         val attribution: CharSequence?,
         val lastActiveTimestamp: Long,
@@ -169,6 +173,8 @@
 
         init {
             builder.append("type=${type.logName}")
+            builder.append(", packageName=$packageName")
+            builder.append(", userId=$userId")
             builder.append(", appName=$applicationName")
             if (attribution != null) {
                 builder.append(", attribution=$attribution")
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
index 8b6c04f..03c1843 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
@@ -43,7 +43,7 @@
     override fun makeDialog(
         context: Context,
         list: List<PrivacyDialog.PrivacyElement>,
-        starter: (String) -> Unit
+        starter: (String, Int) -> Unit
     ): PrivacyDialog {
         return PrivacyDialog(context, list, starter)
     }
@@ -107,10 +107,11 @@
     }
 
     @MainThread
-    private fun startActivity(permGroupName: String) {
-        val intent = Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
-        intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, permGroupName)
-        privacyLogger.logStartSettingsActivityFromDialog(permGroupName)
+    private fun startActivity(packageName: String, userId: Int) {
+        val intent = Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS)
+        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName)
+        intent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId))
+        privacyLogger.logStartSettingsActivityFromDialog(packageName, userId)
         if (!keyguardStateController.isUnlocked) {
             // If we are locked, hide the dialog so the user can unlock
             dialog?.hide()
@@ -159,6 +160,8 @@
                         }
                         PrivacyDialog.PrivacyElement(
                                 t,
+                                it.packageName,
+                                UserHandle.getUserId(it.uid),
                                 appName,
                                 it.attribution,
                                 it.lastAccess,
@@ -257,7 +260,7 @@
         fun makeDialog(
             context: Context,
             list: List<PrivacyDialog.PrivacyElement>,
-            starter: (String) -> Unit
+            starter: (String, Int) -> Unit
         ): PrivacyDialog
     }
 }
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt b/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt
index 8059475..ebf6ae9 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/logging/PrivacyLogger.kt
@@ -121,11 +121,12 @@
         })
     }
 
-    fun logStartSettingsActivityFromDialog(permGroupName: String) {
+    fun logStartSettingsActivityFromDialog(packageName: String, userId: Int) {
         log(LogLevel.INFO, {
-            str1 = permGroupName
+            str1 = packageName
+            int1 = userId
         }, {
-            "Start settings activity from dialog for perm group: $str1"
+            "Start settings activity from dialog for packageName=$str1, userId=$int1 "
         })
     }
 
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 f86b465..072f7b8 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt
@@ -100,12 +100,12 @@
 
     private val dialogProvider = object : PrivacyDialogController.DialogProvider {
         var list: List<PrivacyDialog.PrivacyElement>? = null
-        var starter: ((String) -> Unit)? = null
+        var starter: ((String, Int) -> Unit)? = null
 
         override fun makeDialog(
             context: Context,
             list: List<PrivacyDialog.PrivacyElement>,
-            starter: (String) -> Unit
+            starter: (String, Int) -> Unit
         ): PrivacyDialog {
             this.list = list
             this.starter = starter
@@ -210,7 +210,7 @@
     fun testSingleElementInList() {
         val usage = createMockPermGroupUsage(
                 packageName = TEST_PACKAGE_NAME,
-                uid = generateUidForUser(0),
+                uid = generateUidForUser(USER_ID),
                 permGroupName = PERM_CAMERA,
                 lastAccess = 5L,
                 isActive = true,
@@ -224,6 +224,8 @@
 
         val expected = PrivacyDialog.PrivacyElement(
                 type = PrivacyType.TYPE_CAMERA,
+                packageName = TEST_PACKAGE_NAME,
+                userId = USER_ID,
                 applicationName = TEST_PACKAGE_NAME,
                 attribution = TEST_ATTRIBUTION,
                 lastActiveTimestamp = 5L,
@@ -459,13 +461,28 @@
         controller.showDialog(context)
         exhaustExecutors()
 
-        dialogProvider.starter?.invoke(PERM_MICROPHONE)
+        dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
         verify(activityStarter)
                 .startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>())
 
-        assertThat(intentCaptor.value.action).isEqualTo(Intent.ACTION_MANAGE_PERMISSION_APPS)
-        assertThat(intentCaptor.value.getStringExtra(Intent.EXTRA_PERMISSION_GROUP_NAME))
-                .isEqualTo(PERM_MICROPHONE)
+        assertThat(intentCaptor.value.action).isEqualTo(Intent.ACTION_MANAGE_APP_PERMISSIONS)
+        assertThat(intentCaptor.value.getStringExtra(Intent.EXTRA_PACKAGE_NAME))
+                .isEqualTo(TEST_PACKAGE_NAME)
+        assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle)
+                .isEqualTo(UserHandle.of(USER_ID))
+    }
+
+    @Test
+    fun testStartActivityCorrectIntent_enterpriseUser() {
+        controller.showDialog(context)
+        exhaustExecutors()
+
+        dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, ENT_USER_ID)
+        verify(activityStarter)
+                .startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>())
+
+        assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle)
+                .isEqualTo(UserHandle.of(ENT_USER_ID))
     }
 
     @Test
@@ -473,7 +490,7 @@
         controller.showDialog(context)
         exhaustExecutors()
 
-        dialogProvider.starter?.invoke(PERM_MICROPHONE)
+        dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
         verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor))
 
         activityStartedCaptor.value.onActivityStarted(ActivityManager.START_DELIVERED_TO_TOP)
@@ -486,7 +503,7 @@
         controller.showDialog(context)
         exhaustExecutors()
 
-        dialogProvider.starter?.invoke(PERM_MICROPHONE)
+        dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
         verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor))
 
         activityStartedCaptor.value.onActivityStarted(ActivityManager.START_ABORTED)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogTest.kt
index eb5dd4e..28b44d9 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogTest.kt
@@ -40,8 +40,13 @@
 @TestableLooper.RunWithLooper(setAsMainLooper = true)
 class PrivacyDialogTest : SysuiTestCase() {
 
+    companion object {
+        private const val TEST_PACKAGE_NAME = "test_pkg"
+        private const val TEST_USER_ID = 0
+    }
+
     @Mock
-    private lateinit var starter: (String) -> Unit
+    private lateinit var starter: (String, Int) -> Unit
 
     private lateinit var dialog: PrivacyDialog
 
@@ -58,10 +63,12 @@
     }
 
     @Test
-    fun testStarterCalledWithCorrectPermGroupName() {
+    fun testStarterCalledWithCorrectParams() {
         val list = listOf(
                 PrivacyDialog.PrivacyElement(
                         PrivacyType.TYPE_MICROPHONE,
+                        TEST_PACKAGE_NAME,
+                        TEST_USER_ID,
                         "App",
                         null,
                         0L,
@@ -73,7 +80,7 @@
         dialog = PrivacyDialog(context, list, starter)
         dialog.show()
         dialog.requireViewById<View>(R.id.privacy_item).callOnClick()
-        verify(starter).invoke(PrivacyType.TYPE_MICROPHONE.permGroupName)
+        verify(starter).invoke(TEST_PACKAGE_NAME, TEST_USER_ID)
     }
 
     @Test
@@ -104,6 +111,8 @@
         val list = listOf(
                 PrivacyDialog.PrivacyElement(
                         PrivacyType.TYPE_CAMERA,
+                        TEST_PACKAGE_NAME,
+                        TEST_USER_ID,
                         "App",
                         null,
                         0L,
@@ -113,6 +122,8 @@
                 ),
                 PrivacyDialog.PrivacyElement(
                         PrivacyType.TYPE_MICROPHONE,
+                        TEST_PACKAGE_NAME,
+                        TEST_USER_ID,
                         "App",
                         null,
                         0L,
@@ -130,6 +141,8 @@
     fun testUsingText() {
         val element = PrivacyDialog.PrivacyElement(
                 PrivacyType.TYPE_CAMERA,
+                TEST_PACKAGE_NAME,
+                TEST_USER_ID,
                 "App",
                 null,
                 0L,
@@ -154,6 +167,8 @@
     fun testRecentText() {
         val element = PrivacyDialog.PrivacyElement(
                 PrivacyType.TYPE_MICROPHONE,
+                TEST_PACKAGE_NAME,
+                TEST_USER_ID,
                 "App",
                 null,
                 0L,
@@ -178,6 +193,8 @@
     fun testEnterprise() {
         val element = PrivacyDialog.PrivacyElement(
                 PrivacyType.TYPE_MICROPHONE,
+                TEST_PACKAGE_NAME,
+                TEST_USER_ID,
                 "App",
                 null,
                 0L,
@@ -198,6 +215,8 @@
     fun testPhoneCall() {
         val element = PrivacyDialog.PrivacyElement(
                 PrivacyType.TYPE_MICROPHONE,
+                TEST_PACKAGE_NAME,
+                TEST_USER_ID,
                 "App",
                 null,
                 0L,
@@ -218,6 +237,8 @@
     fun testAttribution() {
         val element = PrivacyDialog.PrivacyElement(
                 PrivacyType.TYPE_MICROPHONE,
+                TEST_PACKAGE_NAME,
+                TEST_USER_ID,
                 "App",
                 "attribution",
                 0L,