Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 103ba9e8 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Update setLocationEnabled in DPM

Simplify method to use common helper functions for behavior more similar
to other DPM methods.

Test: atest DevicePolicyManagerTest
Change-Id: I1b547cb682446aaab793aa72d5cd92547db50e80
parent f10083e2
Loading
Loading
Loading
Loading
+12 −23
Original line number Diff line number Diff line
@@ -10899,21 +10899,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setLocationEnabled(ComponentName who, boolean locationEnabled) {
        Preconditions.checkNotNull(who, "ComponentName is null");
        int userId = mInjector.userHandleGetCallingUserId();
        enforceDeviceOwner(who);
        synchronized (getLockObject()) {
            getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
        UserHandle userHandle = mInjector.binderGetCallingUserHandle();
        mInjector.binderWithCleanCallingIdentity(
                () -> mInjector.getLocationManager().setLocationEnabledForUser(locationEnabled,
                        userHandle));
            if (!isDeviceOwner(who, userId) && !isCurrentUserDemo()) {
                throw new SecurityException(
                        "Permission denial: Profile owners cannot update location settings");
            }
        }
        long ident = mInjector.binderClearCallingIdentity();
        try {
            mInjector.getLocationManager().setLocationEnabledForUser(
                    locationEnabled, UserHandle.of(userId));
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.SET_SECURE_SETTING)
                .setAdmin(who)
@@ -10921,9 +10913,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                        locationEnabled ? Settings.Secure.LOCATION_MODE_ON
                                : Settings.Secure.LOCATION_MODE_OFF))
                .write();
        } finally {
            mInjector.binderRestoreCallingIdentity(ident);
        }
    }
    @Override