Fix auto-grant for groups with solely R_W_R perms

Recently, we added code to consider a group granted only if it has at
least one non-REVOKE_WHEN_REQUESTED permission granted.

But, there is another case where a group should be considered granted:
when all of its permissions are granted and all have
REVOKE_WHEN_REQUESTED. (This is the case for groups auto-granted by
split permission.)

Bug: 223907044
Fixes: 231839805
Test: atest SplitPermissionAutoGrantTest
Test: Manually as described in b/231839805#comment7
Change-Id: I48195875b3a19b6621279d54d5c8974c549c158e
Merged-In: I48195875b3a19b6621279d54d5c8974c549c158e
diff --git a/PermissionController/src/com/android/permissioncontroller/permission/model/livedatatypes/LightAppPermGroup.kt b/PermissionController/src/com/android/permissioncontroller/permission/model/livedatatypes/LightAppPermGroup.kt
index 356f4e5..64d63bd 100644
--- a/PermissionController/src/com/android/permissioncontroller/permission/model/livedatatypes/LightAppPermGroup.kt
+++ b/PermissionController/src/com/android/permissioncontroller/permission/model/livedatatypes/LightAppPermGroup.kt
@@ -189,11 +189,15 @@
         val isGranted = specialLocationGrant ?: permissions.any { it.value.isGrantedIncludingAppOp }
 
         /**
-         * Whether any of this App Permission SubGroup's permissions are granted excluding
-         * auto granted permissions during install time with flag RevokeWhenRequested
+         * Whether this App Permission SubGroup should be treated as granted. This means either:
+         * 1) At least one permission was granted excluding auto-granted permissions (i.e., granted
+         * during install time with flag RevokeWhenRequested.) Or,
+         * 2) All permissions were auto-granted (all permissions are all granted and all
+         * RevokeWhenRequested.)
          */
-        val isGrantedExcludeRevokeWhenRequestedPermissions = specialLocationGrant ?: permissions
-            .any { it.value.isGrantedIncludingAppOp && !it.value.isRevokeWhenRequested }
+        val isGrantedExcludingRWROrAllRWR = specialLocationGrant ?: (permissions
+            .any { it.value.isGrantedIncludingAppOp && !it.value.isRevokeWhenRequested } ||
+            permissions.all { it.value.isGrantedIncludingAppOp && it.value.isRevokeWhenRequested })
 
         /**
          * Whether any of this App Permission SubGroup's permissions are granted by default
diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/model/GrantPermissionsViewModel.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/model/GrantPermissionsViewModel.kt
index a27bd5b..2f0921f 100644
--- a/PermissionController/src/com/android/permissioncontroller/permission/ui/model/GrantPermissionsViewModel.kt
+++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/model/GrantPermissionsViewModel.kt
@@ -710,7 +710,7 @@
 
         // Do not attempt to grant background access if foreground access is not either already
         // granted or requested
-        if (isBackground && !group.foreground.isGrantedExcludeRevokeWhenRequestedPermissions &&
+        if (isBackground && !group.foreground.isGrantedExcludingRWROrAllRWR &&
             !hasForegroundRequest) {
             Log.w(LOG_TAG, "Cannot grant $perm as the matching foreground permission is not " +
                 "already granted.")
@@ -724,8 +724,8 @@
 
         // TODO(b/205888750): remove isRuntimePermReview line once confident in
         //  REVIEW_REQUIRED flag setting
-        if ((isBackground && group.background.isGrantedExcludeRevokeWhenRequestedPermissions ||
-            !isBackground && group.foreground.isGrantedExcludeRevokeWhenRequestedPermissions) &&
+        if ((isBackground && group.background.isGrantedExcludingRWROrAllRWR ||
+            !isBackground && group.foreground.isGrantedExcludingRWROrAllRWR) &&
             !group.isRuntimePermReviewRequired) {
             // If FINE location is not granted, do not grant it automatically when COARSE
             // location is already granted.