From e3cfe3c7f626d70fcf6d32e37355333daf7bc309 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 26 Apr 2021 18:02:19 -0700 Subject: [PATCH] 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 --- .../android/app/admin/DevicePolicyManager.java | 3 +++ .../devicepolicy/DevicePolicyManagerService.java | 16 ++++++++++++---- 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 c93a88f9f312c..cbf2d6a12bec8 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. * + *

Note: 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 64cdfa65f9c56..c7910a280fe20 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); } });