summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yi-an Chen <theianchen@google.com> 2024-05-23 17:12:02 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-05-23 17:12:02 +0000
commite93dfe8b4578d7c739b2f2c960f3dc35ece2aa05 (patch)
tree3804a319900af56f0a00e318d0e0d88bd2b27653
parentaad336927bf7768666b7935a399e710e36741b04 (diff)
parent97889e37f42885492e03fb1664d6f0a795151cca (diff)
Merge "Limit ACTION_MANAGE_PERMISSION_USAGE to location provider on privacy dialog" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt13
-rw-r--r--packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogControllerV2.kt13
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt31
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerV2Test.kt32
5 files changed, 90 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
index 11e6f7a8c38c..b0fc60e74b52 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
@@ -66,6 +66,7 @@ import android.hardware.display.DisplayManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.input.InputManager;
+import android.location.LocationManager;
import android.media.AudioManager;
import android.media.IAudioService;
import android.media.MediaRouter2Manager;
@@ -689,6 +690,12 @@ public class FrameworkServicesModule {
@Provides
@Singleton
+ static LocationManager provideLocationManager(Context context) {
+ return context.getSystemService(LocationManager.class);
+ }
+
+ @Provides
+ @Singleton
static ClipboardManager provideClipboardManager(Context context) {
return context.getSystemService(ClipboardManager.class);
}
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
index 8147877a8a29..22cf7dbd762e 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogController.kt
@@ -23,6 +23,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
+import android.location.LocationManager
import android.os.UserHandle
import android.permission.PermissionGroupUsage
import android.permission.PermissionManager
@@ -62,6 +63,7 @@ private val defaultDialogProvider = object : PrivacyDialogController.DialogProvi
class PrivacyDialogController(
private val permissionManager: PermissionManager,
private val packageManager: PackageManager,
+ private val locationManager: LocationManager,
private val privacyItemController: PrivacyItemController,
private val userTracker: UserTracker,
private val activityStarter: ActivityStarter,
@@ -78,6 +80,7 @@ class PrivacyDialogController(
constructor(
permissionManager: PermissionManager,
packageManager: PackageManager,
+ locationManager: LocationManager,
privacyItemController: PrivacyItemController,
userTracker: UserTracker,
activityStarter: ActivityStarter,
@@ -90,6 +93,7 @@ class PrivacyDialogController(
) : this(
permissionManager,
packageManager,
+ locationManager,
privacyItemController,
userTracker,
activityStarter,
@@ -147,15 +151,17 @@ class PrivacyDialogController(
@WorkerThread
private fun getManagePermissionIntent(
+ context: Context,
packageName: String,
userId: Int,
permGroupName: CharSequence,
attributionTag: CharSequence?,
isAttributionSupported: Boolean
- ): Intent
- {
+ ): Intent {
lateinit var intent: Intent
- if (attributionTag != null && isAttributionSupported) {
+ // We should only limit this intent to location provider
+ if (attributionTag != null && isAttributionSupported &&
+ locationManager.isProviderPackage(null, packageName, attributionTag.toString())) {
intent = Intent(Intent.ACTION_MANAGE_PERMISSION_USAGE)
intent.setPackage(packageName)
intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, permGroupName.toString())
@@ -230,6 +236,7 @@ class PrivacyDialogController(
it.isPhoneCall,
it.permissionGroupName,
getManagePermissionIntent(
+ context,
it.packageName,
userId,
it.permissionGroupName,
diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogControllerV2.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogControllerV2.kt
index 3faa044ca31d..d6eaf66ef0de 100644
--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogControllerV2.kt
+++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogControllerV2.kt
@@ -23,6 +23,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
+import android.location.LocationManager
import android.os.UserHandle
import android.permission.PermissionGroupUsage
import android.permission.PermissionManager
@@ -65,6 +66,7 @@ private val defaultDialogProvider =
class PrivacyDialogControllerV2(
private val permissionManager: PermissionManager,
private val packageManager: PackageManager,
+ private val locationManager: LocationManager,
private val privacyItemController: PrivacyItemController,
private val userTracker: UserTracker,
private val activityStarter: ActivityStarter,
@@ -82,6 +84,7 @@ class PrivacyDialogControllerV2(
constructor(
permissionManager: PermissionManager,
packageManager: PackageManager,
+ locationManager: LocationManager,
privacyItemController: PrivacyItemController,
userTracker: UserTracker,
activityStarter: ActivityStarter,
@@ -95,6 +98,7 @@ class PrivacyDialogControllerV2(
) : this(
permissionManager,
packageManager,
+ locationManager,
privacyItemController,
userTracker,
activityStarter,
@@ -166,12 +170,18 @@ class PrivacyDialogControllerV2(
@WorkerThread
private fun getStartViewPermissionUsageIntent(
+ context: Context,
packageName: String,
permGroupName: String,
attributionTag: CharSequence?,
isAttributionSupported: Boolean
): Intent? {
- if (attributionTag != null && isAttributionSupported) {
+ // We should only limit this intent to location provider
+ if (
+ attributionTag != null &&
+ isAttributionSupported &&
+ locationManager.isProviderPackage(null, packageName, attributionTag.toString())
+ ) {
val intent = Intent(Intent.ACTION_MANAGE_PERMISSION_USAGE)
intent.setPackage(packageName)
intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, permGroupName)
@@ -237,6 +247,7 @@ class PrivacyDialogControllerV2(
val userId = UserHandle.getUserId(it.uid)
val viewUsageIntent =
getStartViewPermissionUsageIntent(
+ context,
it.packageName,
it.permissionGroupName,
it.attributionTag,
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 38b448fb362c..84e9107f177c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt
@@ -25,6 +25,7 @@ import android.content.pm.PackageManager
import android.content.pm.PackageManager.ResolveInfoFlags
import android.content.pm.ResolveInfo
import android.content.pm.UserInfo
+import android.location.LocationManager
import android.os.Process.SYSTEM_UID
import android.os.UserHandle
import android.permission.PermissionGroupUsage
@@ -86,6 +87,8 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
@Mock
private lateinit var packageManager: PackageManager
@Mock
+ private lateinit var locationManager: LocationManager
+ @Mock
private lateinit var privacyItemController: PrivacyItemController
@Mock
private lateinit var userTracker: UserTracker
@@ -135,6 +138,7 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
controller = PrivacyDialogController(
permissionManager,
packageManager,
+ locationManager,
privacyItemController,
userTracker,
activityStarter,
@@ -652,7 +656,7 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
}
@Test
- fun testCorrectIntentSubAttribution() {
+ fun testCorrectIntentSubAttributionForLocationProvider() {
val usage = createMockPermGroupUsage(
attributionTag = TEST_ATTRIBUTION_TAG,
attributionLabel = "TEST_LABEL"
@@ -660,6 +664,8 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
val activityInfo = createMockActivityInfo()
val resolveInfo = createMockResolveInfo(activityInfo)
+ `when`(locationManager.isProviderPackage(null, TEST_PACKAGE_NAME, TEST_ATTRIBUTION_TAG))
+ .thenReturn(true)
`when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage))
`when`(packageManager.resolveActivity(any(), any<ResolveInfoFlags>()))
.thenAnswer { resolveInfo }
@@ -679,6 +685,29 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
}
@Test
+ fun testCorrectIntentSubAttributionForNonLocationProvider() {
+ val usage = createMockPermGroupUsage(
+ attributionTag = TEST_ATTRIBUTION_TAG,
+ attributionLabel = "TEST_LABEL"
+ )
+
+ val activityInfo = createMockActivityInfo()
+ val resolveInfo = createMockResolveInfo(activityInfo)
+ `when`(locationManager.isProviderPackage(null, TEST_PACKAGE_NAME, TEST_ATTRIBUTION_TAG))
+ .thenReturn(false)
+ `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage))
+ `when`(packageManager.resolveActivity(any(), any<ResolveInfoFlags>()))
+ .thenAnswer { resolveInfo }
+ controller.showDialog(context)
+ exhaustExecutors()
+
+ dialogProvider.list?.let { list ->
+ val navigationIntent = list.get(0).navigationIntent!!
+ assertThat(navigationIntent.action).isEqualTo(Intent.ACTION_MANAGE_APP_PERMISSIONS)
+ }
+ }
+
+ @Test
fun testDefaultIntentOnMissingAttributionLabel() {
val usage = createMockPermGroupUsage(
attributionTag = TEST_ATTRIBUTION_TAG
diff --git a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerV2Test.kt b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerV2Test.kt
index 59a6811dd395..0c7e09988a00 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerV2Test.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerV2Test.kt
@@ -25,6 +25,7 @@ import android.content.pm.PackageManager
import android.content.pm.PackageManager.ResolveInfoFlags
import android.content.pm.ResolveInfo
import android.content.pm.UserInfo
+import android.location.LocationManager
import android.os.Process.SYSTEM_UID
import android.os.UserHandle
import android.permission.PermissionGroupUsage
@@ -86,6 +87,7 @@ class PrivacyDialogControllerV2Test : SysuiTestCase() {
@Mock private lateinit var dialog: PrivacyDialogV2
@Mock private lateinit var permissionManager: PermissionManager
@Mock private lateinit var packageManager: PackageManager
+ @Mock private lateinit var locationManager: LocationManager
@Mock private lateinit var privacyItemController: PrivacyItemController
@Mock private lateinit var userTracker: UserTracker
@Mock private lateinit var activityStarter: ActivityStarter
@@ -136,6 +138,7 @@ class PrivacyDialogControllerV2Test : SysuiTestCase() {
PrivacyDialogControllerV2(
permissionManager,
packageManager,
+ locationManager,
privacyItemController,
userTracker,
activityStarter,
@@ -660,7 +663,7 @@ class PrivacyDialogControllerV2Test : SysuiTestCase() {
}
@Test
- fun testServiceIntentOnCorrectSubAttribution() {
+ fun testServiceIntentOnCorrectSubAttributionForLocationProvider() {
val usage =
createMockPermGroupUsage(
attributionTag = TEST_ATTRIBUTION_TAG,
@@ -669,6 +672,8 @@ class PrivacyDialogControllerV2Test : SysuiTestCase() {
val activityInfo = createMockActivityInfo()
val resolveInfo = createMockResolveInfo(activityInfo)
+ `when`(locationManager.isProviderPackage(null, TEST_PACKAGE_NAME, TEST_ATTRIBUTION_TAG))
+ .thenReturn(true)
`when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage))
`when`(packageManager.resolveActivity(any(), any<ResolveInfoFlags>())).thenAnswer {
resolveInfo
@@ -690,6 +695,31 @@ class PrivacyDialogControllerV2Test : SysuiTestCase() {
}
@Test
+ fun testServiceIntentOnCorrectSubAttributionForNonLocationProvider() {
+ val usage =
+ createMockPermGroupUsage(
+ attributionTag = TEST_ATTRIBUTION_TAG,
+ attributionLabel = "TEST_LABEL"
+ )
+
+ val activityInfo = createMockActivityInfo()
+ val resolveInfo = createMockResolveInfo(activityInfo)
+ `when`(locationManager.isProviderPackage(null, TEST_PACKAGE_NAME, TEST_ATTRIBUTION_TAG))
+ .thenReturn(false)
+ `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage))
+ `when`(packageManager.resolveActivity(any(), any<ResolveInfoFlags>())).thenAnswer {
+ resolveInfo
+ }
+ controller.showDialog(context)
+ exhaustExecutors()
+
+ dialogProvider.list?.let { list ->
+ val navigationIntent = list.get(0).navigationIntent!!
+ assertThat(navigationIntent.action).isEqualTo(Intent.ACTION_MANAGE_APP_PERMISSIONS)
+ }
+ }
+
+ @Test
fun testDefaultIntentOnMissingAttributionLabel() {
val usage = createMockPermGroupUsage(attributionTag = TEST_ATTRIBUTION_TAG)