summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Christie <dnchrist@google.com> 2013-09-04 19:22:25 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2013-09-04 19:22:54 +0000
commit61edc94ab58354381ab381cd9b92faf0a337742b (patch)
tree4e356336fa8fcc6a01f15fedfa3fbe84d5d41175
parent48a278aeaf9735a66d2948243e1eb764ed6b1878 (diff)
parentb12ba933f3db9280edcb6a3591741d29c109a4e2 (diff)
Merge "Make location QuickSettings multi-user compatible (b/10563313)" into klp-dev
-rw-r--r--core/java/android/os/UserManager.java13
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java65
3 files changed, 62 insertions, 24 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 83426ae8f77a..10b97652d1ba 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -357,7 +357,18 @@ public class UserManager {
* @param restrictionKey the string key representing the restriction
*/
public boolean hasUserRestriction(String restrictionKey) {
- return getUserRestrictions().getBoolean(restrictionKey, false);
+ return hasUserRestriction(restrictionKey, Process.myUserHandle());
+ }
+
+ /**
+ * @hide
+ * Returns whether the given user has been disallowed from performing certain actions
+ * or setting certain settings.
+ * @param restrictionKey the string key representing the restriction
+ * @param userHandle the UserHandle of the user for whom to retrieve the restrictions.
+ */
+ public boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
+ return getUserRestrictions(userHandle).getBoolean(restrictionKey, false);
}
/**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
index b9c6fef9c5d7..0d591ba3c016 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
@@ -640,10 +640,10 @@ class QuickSettings {
@Override
public boolean onLongClick(View v) {
boolean newLocationEnabledState = !mLocationController.isLocationEnabled();
- mLocationController.setLocationEnabled(newLocationEnabledState);
- if (newLocationEnabledState) {
- // Close the notifications tray so that the network location provider
- // consent dialog can be shown.
+ if (mLocationController.setLocationEnabled(newLocationEnabledState)
+ && newLocationEnabledState) {
+ // If we've successfully switched from location off to on, close the
+ // notifications tray to show the network location provider consent dialog.
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.sendBroadcast(closeDialog);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
index 7e755840932d..3070a3acee96 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/LocationController.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.policy;
+import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
@@ -26,6 +27,7 @@ import android.content.IntentFilter;
import android.database.ContentObserver;
import android.location.LocationManager;
import android.os.Handler;
+import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -81,18 +83,18 @@ public class LocationController extends BroadcastReceiver {
mStatusBarManager
= (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
- // Register to listen for changes to the location settings
- context.getContentResolver().registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true,
- new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange) {
- boolean isEnabled = isLocationEnabled();
- for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) {
- cb.onLocationSettingsChanged(isEnabled);
- }
- }
- });
+ // Register to listen for changes in location settings.
+ IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION);
+ context.registerReceiverAsUser(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (LocationManager.MODE_CHANGED_ACTION.equals(action)) {
+ locationSettingsChanged();
+ }
+ }
+ }, UserHandle.ALL, intentFilter, null, new Handler());
// Examine the current location state and initialize the status view.
updateActiveLocationRequests();
@@ -114,31 +116,49 @@ public class LocationController extends BroadcastReceiver {
*
* <p>If enabling, a user consent dialog will pop up prompting the user to accept.
* If the user doesn't accept, network location won't be enabled.
+ *
+ * @return true if attempt to change setting was successful.
*/
- public void setLocationEnabled(boolean enabled) {
- final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
- if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
- return;
+ public boolean setLocationEnabled(boolean enabled) {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return false;
}
final ContentResolver cr = mContext.getContentResolver();
// When enabling location, a user consent dialog will pop up, and the
// setting won't be fully enabled until the user accepts the agreement.
int mode = enabled
? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY : Settings.Secure.LOCATION_MODE_OFF;
- Settings.Secure.putInt(cr, Settings.Secure.LOCATION_MODE, mode);
+ return Settings.Secure
+ .putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
}
/**
* Returns true if location isn't disabled in settings.
*/
public boolean isLocationEnabled() {
+ int currentUserId = ActivityManager.getCurrentUser();
+ if (isUserLocationRestricted(currentUserId)) {
+ return false;
+ }
+
ContentResolver resolver = mContext.getContentResolver();
- int mode = Settings.Secure.getInt(resolver, Settings.Secure.LOCATION_MODE,
- Settings.Secure.LOCATION_MODE_OFF);
+ int mode = Settings.Secure.getIntForUser(resolver, Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_OFF, currentUserId);
return mode != Settings.Secure.LOCATION_MODE_OFF;
}
/**
+ * Returns true if the current user is restricted from using location.
+ */
+ private boolean isUserLocationRestricted(int userId) {
+ final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ return um.hasUserRestriction(
+ UserManager.DISALLOW_SHARE_LOCATION,
+ new UserHandle(userId));
+ }
+
+ /**
* Returns true if there currently exist active high power location requests.
*/
private boolean areActiveHighPowerLocationRequests() {
@@ -188,6 +208,13 @@ public class LocationController extends BroadcastReceiver {
}
}
+ private void locationSettingsChanged() {
+ boolean isEnabled = isLocationEnabled();
+ for (LocationSettingsChangeCallback cb : mSettingsChangeCallbacks) {
+ cb.onLocationSettingsChanged(isEnabled);
+ }
+ }
+
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();