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

Commit 270296da authored by Tim Murray's avatar Tim Murray
Browse files

LocationManager: move impl of setLocationEnabledForUser to server

Makes caching significantly easier.

Test: boots, works, gets location
Bug: 140788621

Change-Id: Ief39b3a985deea93e0e5f126863a3df383be5fd4
parent 334eedc5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -107,6 +107,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
@@ -446,13 +446,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
@@ -2408,6 +2408,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) {
        if (UserHandle.getCallingUserId() != userId) {
+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.