From 0568f28ac3ba83ec268b54d16a8b19c1fcaf9c89 Mon Sep 17 00:00:00 2001 From: Craig Donner Date: Mon, 11 Apr 2016 13:02:44 -0700 Subject: [PATCH] Sets COARSE_LOCATION permission for VrCore when in vr mode. See b/27900412 for more details. Bug: 27900412 Change-Id: I3e8544e44ff6dfc96d58f9189cf0034ce76ed009 --- .../android/server/vr/VrManagerService.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/vr/VrManagerService.java b/services/core/java/com/android/server/vr/VrManagerService.java index f004b4592413f..018d4928f0edc 100644 --- a/services/core/java/com/android/server/vr/VrManagerService.java +++ b/services/core/java/com/android/server/vr/VrManagerService.java @@ -103,6 +103,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; @@ -418,6 +419,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC mWasDefaultGranted = true; + grantCoarseLocationAccess(pName, userId); grantOverlayAccess(pName, userId); grantNotificationPolicyAccess(pName); grantNotificationListenerAccess(pName, userId); @@ -447,6 +449,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC String pName = component.getPackageName(); if (mWasDefaultGranted) { + revokeCoarseLocationAccess(userId); revokeOverlayAccess(userId); revokeNotificationPolicyAccess(pName); revokeNotificiationListenerAccess(); @@ -455,6 +458,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 == @@ -476,7 +500,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC } } - private void grantNotificationPolicyAccess(String pkg) { NotificationManager nm = mContext.getSystemService(NotificationManager.class); boolean prev = nm.isNotificationPolicyAccessGrantedForPackage(pkg);