summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Felipe Leme <felipeal@google.com> 2021-04-26 18:02:19 -0700
committer Felipe Leme <felipeal@google.com> 2021-04-26 18:23:07 -0700
commite3cfe3c7f626d70fcf6d32e37355333daf7bc309 (patch)
tree268dbdaf1a67930dabef8d37f654efa1c356d6f2
parenta553d62c56e6c0ac3de2ce64112d099c47eed22b (diff)
Disabled DevicePolicyManager.setLocationEnabled() for automotive.
Location is a fundamental feature for automotive, which should be out of reach of device admins (for example, disabling it could affect the navigation app). Test: atest com.android.cts.devicepolicy.DeviceOwnerTest#testSetLocationEnabled # on automotive and phone Bug: 186263875 Fixes: 185523465 Change-Id: I8a9d3347080d56c8f064038b66b5b1826e377f64
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java3
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java16
2 files changed, 15 insertions, 4 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index c93a88f9f312..cbf2d6a12bec 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -10368,6 +10368,9 @@ public class DevicePolicyManager {
/**
* Called by device owners to set the user's global location setting.
*
+ * <p><b>Note: </b> this call is ignored on
+ * {@link android.content.pm.PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
+ *
* @param admin Which {@link DeviceAdminReceiver} this request is associated with
* @param locationEnabled whether location should be enabled or disabled
* @throws SecurityException if {@code admin} is not a device owner.
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 64cdfa65f9c5..c7910a280fe2 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -11926,17 +11926,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
final CallerIdentity caller = getCallerIdentity(who);
Preconditions.checkCallAuthorization(isDeviceOwner(caller));
+ UserHandle userHandle = caller.getUserHandle();
+ if (mIsAutomotive) {
+ Slogf.v(LOG_TAG, "setLocationEnabled(%s, %b): ignoring for user %s on automotive build",
+ who.flattenToShortString(), locationEnabled, userHandle);
+ return;
+ }
+
mInjector.binderWithCleanCallingIdentity(() -> {
boolean wasLocationEnabled = mInjector.getLocationManager().isLocationEnabledForUser(
- caller.getUserHandle());
- mInjector.getLocationManager().setLocationEnabledForUser(locationEnabled,
- caller.getUserHandle());
+ userHandle);
+ Slogf.v(LOG_TAG, "calling locationManager.setLocationEnabledForUser(%b, %s)",
+ locationEnabled, userHandle);
+ mInjector.getLocationManager().setLocationEnabledForUser(locationEnabled, userHandle);
// make a best effort to only show the notification if the admin is actually enabling
// location. this is subject to race conditions with settings changes, but those are
// unlikely to realistically interfere
if (locationEnabled && !wasLocationEnabled) {
- showLocationSettingsEnabledNotification(caller.getUserHandle());
+ showLocationSettingsEnabledNotification(userHandle);
}
});