diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java index 07e017f8bd2ff..49ff385ee27fd 100644 --- a/services/core/java/com/android/server/vr/VrManagerService.java +++ b/services/core/java/com/android/server/vr/VrManagerService.java @@ -105,6 +105,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC new RemoteCallbackList<>(); private final ArraySet mPreviousToggledListenerSettings = new ArraySet<>(); private String mPreviousNotificationPolicyAccessPackage; + private String mPreviousCoarseLocationPackage; private String mPreviousManageOverlayPackage; private static final int MSG_VR_STATE_CHANGE = 0; @@ -446,6 +447,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC mWasDefaultGranted = true; + grantCoarseLocationAccess(pName, userId); grantOverlayAccess(pName, userId); grantNotificationPolicyAccess(pName); grantNotificationListenerAccess(pName, userId); @@ -475,6 +477,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC String pName = component.getPackageName(); if (mWasDefaultGranted) { + revokeCoarseLocationAccess(userId); revokeOverlayAccess(userId); revokeNotificationPolicyAccess(pName); revokeNotificiationListenerAccess(); @@ -483,6 +486,27 @@ public class VrManagerService extends SystemService implements EnabledComponentC } + private void grantCoarseLocationAccess(String pkg, UserHandle userId) { + PackageManager pm = mContext.getPackageManager(); + boolean prev = (PackageManager.PERMISSION_GRANTED == + pm.checkPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION, pkg)); + mPreviousCoarseLocationPackage = null; + if (!prev) { + pm.grantRuntimePermission(pkg, android.Manifest.permission.ACCESS_COARSE_LOCATION, + userId); + mPreviousCoarseLocationPackage = pkg; + } + } + + private void revokeCoarseLocationAccess(UserHandle userId) { + PackageManager pm = mContext.getPackageManager(); + if (mPreviousCoarseLocationPackage != null) { + pm.revokeRuntimePermission(mPreviousCoarseLocationPackage, + android.Manifest.permission.ACCESS_COARSE_LOCATION, userId); + mPreviousCoarseLocationPackage = null; + } + } + private void grantOverlayAccess(String pkg, UserHandle userId) { PackageManager pm = mContext.getPackageManager(); boolean prev = (PackageManager.PERMISSION_GRANTED == @@ -504,7 +528,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC } } - private void grantNotificationPolicyAccess(String pkg) { NotificationManager nm = mContext.getSystemService(NotificationManager.class); boolean prev = nm.isNotificationPolicyAccessGrantedForPackage(pkg);