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
This commit is contained in:
Felipe Leme
2021-04-26 18:02:19 -07:00
parent a553d62c56
commit e3cfe3c7f6
2 changed files with 15 additions and 4 deletions

View File

@@ -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.

View File

@@ -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);
}
});