Merge "Add non-rectangular clip debug setting" into jb-mr2-dev
diff --git a/src/com/android/settings/LocationSettings.java b/src/com/android/settings/LocationSettings.java
index 0e50188..b73dccd 100644
--- a/src/com/android/settings/LocationSettings.java
+++ b/src/com/android/settings/LocationSettings.java
@@ -23,6 +23,7 @@
 import android.content.Intent;
 import android.database.Cursor;
 import android.location.LocationManager;
+import android.os.UserManager;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
@@ -92,6 +93,15 @@
         mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
         mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
 
+        // Only enable these controls if this user is allowed to change location
+        // sharing settings.
+        final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
+        boolean isToggleAllowed = um.isLocationSharingToggleAllowed();
+        if (mLocationAccess != null) mLocationAccess.setEnabled(isToggleAllowed);
+        if (mNetwork != null) mNetwork.setEnabled(isToggleAllowed);
+        if (mGps != null) mGps.setEnabled(isToggleAllowed);
+        if (mAssistedGps != null) mAssistedGps.setEnabled(isToggleAllowed);
+
         mLocationAccess.setOnPreferenceChangeListener(this);
         return root;
     }
@@ -119,15 +129,20 @@
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         final ContentResolver cr = getContentResolver();
+        final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
         if (preference == mNetwork) {
-            Settings.Secure.setLocationProviderEnabled(cr,
-                    LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
+            if (um.isLocationSharingToggleAllowed()) {
+                Settings.Secure.setLocationProviderEnabled(cr,
+                        LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
+            }
         } else if (preference == mGps) {
             boolean enabled = mGps.isChecked();
-            Settings.Secure.setLocationProviderEnabled(cr,
-                    LocationManager.GPS_PROVIDER, enabled);
-            if (mAssistedGps != null) {
-                mAssistedGps.setEnabled(enabled);
+            if (um.isLocationSharingToggleAllowed()) {
+                Settings.Secure.setLocationProviderEnabled(cr,
+                        LocationManager.GPS_PROVIDER, enabled);
+                if (mAssistedGps != null) {
+                    mAssistedGps.setEnabled(enabled);
+                }
             }
         } else if (preference == mAssistedGps) {
             Settings.Global.putInt(cr, Settings.Global.ASSISTED_GPS_ENABLED,
@@ -170,6 +185,10 @@
 
     /** Enable or disable all providers when the master toggle is changed. */
     private void onToggleLocationAccess(boolean checked) {
+        final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
+        if (! um.isLocationSharingToggleAllowed()) {
+            return;
+        }
         final ContentResolver cr = getContentResolver();
         Settings.Secure.setLocationProviderEnabled(cr,
                 LocationManager.GPS_PROVIDER, checked);
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index 75a83cc..ac9df9f 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -35,6 +35,7 @@
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.UserManager;
 import android.provider.Settings;
 import android.util.Log;
 import android.widget.RemoteViews;
@@ -538,11 +539,18 @@
             new AsyncTask<Void, Void, Boolean>() {
                 @Override
                 protected Boolean doInBackground(Void... args) {
-                    Settings.Secure.setLocationProviderEnabled(
-                        resolver,
-                        LocationManager.GPS_PROVIDER,
-                        desiredState);
-                    return desiredState;
+                    final UserManager um =
+                            (UserManager) context.getSystemService(Context.USER_SERVICE);
+                    if (um.isLocationSharingToggleAllowed()) {
+                        Settings.Secure.setLocationProviderEnabled(
+                            resolver,
+                            LocationManager.GPS_PROVIDER,
+                            desiredState);
+                        return desiredState;
+                    }
+                    return Settings.Secure.isLocationProviderEnabled(
+                            resolver,
+                            LocationManager.GPS_PROVIDER);
                 }
 
                 @Override