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

Commit 5b7a2e83 authored by Craig Donner's avatar Craig Donner Committed by android-build-merger
Browse files

Revert "Remove coarse location pre-grant for preinstalled VrListenerServices." am: cae8cdf9

am: 1a509618

Change-Id: I3427f6c65b338a5fb94f57c817ba0feb2c0d47c2
parents b7276df5 1a509618
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -219,6 +219,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                    String packageName = mNotificationAccessPackageToUserId.keyAt(i);
                    revokeNotificationListenerAccess(packageName, grantUserId);
                    revokeNotificationPolicyAccess(packageName);
                    revokeCoarseLocationPermissionIfNeeded(packageName, grantUserId);
                    mNotificationAccessPackageToUserId.removeAt(i);
                }
            }
@@ -227,6 +228,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                if (!packageNames.contains(pkg)) {
                    revokeNotificationListenerAccess(pkg, currentUserId);
                    revokeNotificationPolicyAccess(pkg);
                    revokeCoarseLocationPermissionIfNeeded(pkg, currentUserId);
                    mNotificationAccessPackageToUserId.remove(pkg);
                }
            }
@@ -234,6 +236,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                if (!allowed.contains(pkg)) {
                    grantNotificationPolicyAccess(pkg);
                    grantNotificationListenerAccess(pkg, currentUserId);
                    grantCoarseLocationPermissionIfNeeded(pkg, currentUserId);
                    mNotificationAccessPackageToUserId.put(pkg, currentUserId);
                }
            }
@@ -657,6 +660,22 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                flatSettings, userId);
    }

    private void grantCoarseLocationPermissionIfNeeded(String pkg, int userId) {
        // Don't clobber the user if permission set in current state explicitly
        if (!isPermissionUserUpdated(Manifest.permission.ACCESS_COARSE_LOCATION, pkg, userId)) {
            mContext.getPackageManager().grantRuntimePermission(pkg,
                    Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
        }
    }

    private void revokeCoarseLocationPermissionIfNeeded(String pkg, int userId) {
        // Don't clobber the user if permission set in current state explicitly
        if (!isPermissionUserUpdated(Manifest.permission.ACCESS_COARSE_LOCATION, pkg, userId)) {
            mContext.getPackageManager().revokeRuntimePermission(pkg,
                    Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
        }
    }

    private boolean isPermissionUserUpdated(String permission, String pkg, int userId) {
        final int flags = mContext.getPackageManager().getPermissionFlags(
                permission, pkg, new UserHandle(userId));