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

Commit 67571323 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "LocationManager: move impl of setLocationEnabledForUser to server"

parents 245a76e4 270296da
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ interface ILocationManager

    boolean isProviderEnabledForUser(String provider, int userId);
    boolean isLocationEnabledForUser(int userId);
    void setLocationEnabledForUser(boolean enabled, int userId);
    void addTestProvider(String name, in ProviderProperties properties, String opPackageName);
    void removeTestProvider(String provider, String opPackageName);
    void setTestProviderLocation(String provider, in Location loc, String opPackageName);
+5 −7
Original line number Diff line number Diff line
@@ -478,13 +478,11 @@ public class LocationManager {
    @TestApi
    @RequiresPermission(WRITE_SECURE_SETTINGS)
    public void setLocationEnabledForUser(boolean enabled, @NonNull UserHandle userHandle) {
        Settings.Secure.putIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE,
                enabled
                        ? Settings.Secure.LOCATION_MODE_ON
                        : Settings.Secure.LOCATION_MODE_OFF,
                userHandle.getIdentifier());
        try {
            mService.setLocationEnabledForUser(enabled, userHandle.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+11 −0
Original line number Diff line number Diff line
@@ -2421,6 +2421,17 @@ public class LocationManagerService extends ILocationManager.Stub {
        }
    }

    @Override
    public void setLocationEnabledForUser(boolean enabled, int userId) {
        if (UserHandle.getCallingUserId() != userId) {
            mContext.enforceCallingOrSelfPermission(Manifest.permission.INTERACT_ACROSS_USERS,
                    null);
        }
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS,
                "Requires WRITE_SECURE_SETTINGS permission");
        mSettingsHelper.setLocationEnabled(enabled, userId);
    }

    @Override
    public boolean isLocationEnabledForUser(int userId) {
        userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
+18 −0
Original line number Diff line number Diff line
@@ -134,6 +134,24 @@ public class SettingsHelper {
        return mLocationMode.getValueForUser(LOCATION_MODE_OFF, userId) != LOCATION_MODE_OFF;
    }

    /**
     * Set location enabled for a user.
     */
    public void setLocationEnabled(boolean enabled, int userId) {
        long identity = Binder.clearCallingIdentity();
        try {
            Settings.Secure.putIntForUser(
                    mContext.getContentResolver(),
                    Settings.Secure.LOCATION_MODE,
                    enabled
                        ? Settings.Secure.LOCATION_MODE_ON
                        : Settings.Secure.LOCATION_MODE_OFF,
                    userId);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }

    /**
     * Add a listener for changes to the location enabled setting. Callbacks occur on an unspecified
     * thread.