Loading location/java/android/location/ILocationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading location/java/android/location/LocationManager.java +5 −7 Original line number Diff line number Diff line Loading @@ -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(); } } /** Loading services/core/java/com/android/server/LocationManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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(), Loading services/core/java/com/android/server/location/SettingsHelper.java +18 −0 Original line number Diff line number Diff line Loading @@ -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. Loading Loading
location/java/android/location/ILocationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
location/java/android/location/LocationManager.java +5 −7 Original line number Diff line number Diff line Loading @@ -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(); } } /** Loading
services/core/java/com/android/server/LocationManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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(), Loading
services/core/java/com/android/server/location/SettingsHelper.java +18 −0 Original line number Diff line number Diff line Loading @@ -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. Loading