Merge "Fix Android Beam toggle switch on Manta." into jb-mr2-dev
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 42154f4..99946ea 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -592,6 +592,8 @@
         <item>camera</item>
         <item>record audio</item>
         <item>play audio</item>
+        <item>read clipboard</item>
+        <item>modify clipboard</item>
     </string-array>
 
     <!-- User display names for app ops codes -->
@@ -625,6 +627,8 @@
         <item>Camera</item>
         <item>Record audio</item>
         <item>Play audio</item>
+        <item>Read clipboard</item>
+        <item>Modify clipboard</item>
     </string-array>
 
     <!-- Titles for the list of long press timeout options. -->
@@ -765,6 +769,20 @@
         <item>error</item>
     </string-array>
 
+    <!-- Titles for non-rectangular clipping preference. [CHAR LIMIT=35] -->
+    <string-array name="show_non_rect_clip_entries">
+        <item>Off</item>
+        <item>Draw non-rectangular clip region in blue</item>
+        <item>Highlight tested drawing commands in green</item>
+    </string-array>
+
+    <!-- Values for non-rectangular clipping preference. -->
+    <string-array name="show_non_rect_clip_values" translatable="false" >
+        <item>hide</item>
+        <item>region</item>
+        <item>highlight</item>
+    </string-array>
+
     <!-- Titles for frame time tracking preference. [CHAR LIMIT=35] -->
     <string-array name="track_frame_time_entries">
         <item>Off</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 57dbcae..c15d315 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3873,6 +3873,9 @@
     <!-- Preference category for drawing debugging development settings. [CHAR LIMIT=25] -->
     <string name="debug_drawing_category">Drawing</string>
 
+    <!-- Preference category for hardware accelerated drawing debugging development settings. [CHAR LIMIT=50] -->
+    <string name="debug_hw_drawing_category">Hardware accelerated rendering</string>
+
     <!-- Preference category for monitoring debugging development settings. [CHAR LIMIT=25] -->
     <string name="debug_monitoring_category">Monitoring</string>
 
@@ -3940,6 +3943,9 @@
     <!-- UI debug setting: force anti-aliasing summary [CHAR LIMIT=50] -->
     <string name="force_msaa_summary">Enable 4x MSAA in OpenGL ES 2.0 apps</string>
 
+    <!-- UI debug setting: show when non-rectangular clip operations are used [CHAR LIMIT=50] -->
+    <string name="show_non_rect_clip">Debug non-rectangular clip operations</string>
+
     <!-- UI debug setting: profile time taken by hardware acceleration to render apps [CHAR LIMIT=25] -->
     <string name="track_frame_time">Profile GPU rendering</string>
 
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index c199b1d..6fbbbf4 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -104,30 +104,15 @@
             android:title="@string/debug_drawing_category">
 
         <CheckBoxPreference
-            android:key="debug_layout"
-            android:title="@string/debug_layout"
-            android:summary="@string/debug_layout_summary"/>
-
-        <CheckBoxPreference
-            android:key="show_hw_screen_udpates"
-            android:title="@string/show_hw_screen_updates"
-            android:summary="@string/show_hw_screen_updates_summary"/>
-
-        <CheckBoxPreference
-            android:key="show_hw_layers_udpates"
-            android:title="@string/show_hw_layers_updates"
-            android:summary="@string/show_hw_layers_updates_summary"/>
-
-        <CheckBoxPreference
-            android:key="show_hw_overdraw"
-            android:title="@string/show_hw_overdraw"
-            android:summary="@string/show_hw_overdraw_summary"/>
-
-        <CheckBoxPreference
             android:key="show_screen_updates"
             android:title="@string/show_screen_updates"
             android:summary="@string/show_screen_updates_summary"/>
 
+        <CheckBoxPreference
+            android:key="debug_layout"
+            android:title="@string/debug_layout"
+            android:summary="@string/debug_layout_summary"/>
+
         <ListPreference
             android:key="window_animation_scale"
             android:title="@string/window_animation_scale_title"
@@ -149,21 +134,6 @@
             android:entries="@array/animator_duration_scale_entries"
             android:entryValues="@array/animator_duration_scale_values" />
 
-        <CheckBoxPreference
-            android:key="disable_overlays"
-            android:title="@string/disable_overlays"
-            android:summary="@string/disable_overlays_summary"/>
-
-        <CheckBoxPreference
-            android:key="force_hw_ui"
-            android:title="@string/force_hw_ui"
-            android:summary="@string/force_hw_ui_summary"/>
-
-        <CheckBoxPreference
-            android:key="force_msaa"
-            android:title="@string/force_msaa"
-            android:summary="@string/force_msaa_summary"/>
-
         <ListPreference
             android:key="overlay_display_devices"
             android:title="@string/overlay_display_devices_title"
@@ -173,6 +143,48 @@
 
     </PreferenceCategory>
 
+    <PreferenceCategory android:key="debug_hw_drawing_category"
+            android:title="@string/debug_hw_drawing_category">
+
+        <CheckBoxPreference
+                android:key="force_hw_ui"
+                android:title="@string/force_hw_ui"
+                android:summary="@string/force_hw_ui_summary"/>
+
+        <CheckBoxPreference
+                android:key="show_hw_screen_udpates"
+                android:title="@string/show_hw_screen_updates"
+                android:summary="@string/show_hw_screen_updates_summary"/>
+
+        <CheckBoxPreference
+                android:key="show_hw_layers_udpates"
+                android:title="@string/show_hw_layers_updates"
+                android:summary="@string/show_hw_layers_updates_summary"/>
+
+        <CheckBoxPreference
+                android:key="show_hw_overdraw"
+                android:title="@string/show_hw_overdraw"
+                android:summary="@string/show_hw_overdraw_summary"/>
+
+        <ListPreference
+                android:key="show_non_rect_clip"
+                android:title="@string/show_non_rect_clip"
+                android:persistent="false"
+                android:entries="@array/show_non_rect_clip_entries"
+                android:entryValues="@array/show_non_rect_clip_values" />
+
+        <CheckBoxPreference
+                android:key="force_msaa"
+                android:title="@string/force_msaa"
+                android:summary="@string/force_msaa_summary"/>
+
+        <CheckBoxPreference
+                android:key="disable_overlays"
+                android:title="@string/disable_overlays"
+                android:summary="@string/disable_overlays_summary"/>
+
+    </PreferenceCategory>
+
     <PreferenceCategory android:key="debug_monitoring_category"
             android:title="@string/debug_monitoring_category">
 
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index f37b5f8..4dfe700 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -46,11 +46,9 @@
 import android.os.ServiceManager;
 import android.os.StrictMode;
 import android.os.SystemProperties;
-import android.os.Trace;
 import android.os.UserHandle;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
-import android.preference.MultiCheckPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
 import android.preference.PreferenceFragment;
@@ -114,6 +112,7 @@
     private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
     private static final String FORCE_MSAA_KEY = "force_msaa";
     private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
+    private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
     private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
     private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
     private static final String SHOW_HW_OVERDRAW_KEY = "show_hw_overdraw";
@@ -173,6 +172,7 @@
     private CheckBoxPreference mShowHwOverdraw;
     private CheckBoxPreference mDebugLayout;
     private ListPreference mTrackFrameTime;
+    private ListPreference mShowNonRectClip;
     private ListPreference mWindowAnimationScale;
     private ListPreference mTransitionAnimationScale;
     private ListPreference mAnimatorDurationScale;
@@ -252,36 +252,23 @@
         mShowCpuUsage = findAndInitCheckboxPref(SHOW_CPU_USAGE_KEY);
         mForceHardwareUi = findAndInitCheckboxPref(FORCE_HARDWARE_UI_KEY);
         mForceMsaa = findAndInitCheckboxPref(FORCE_MSAA_KEY);
-        mTrackFrameTime = (ListPreference) findPreference(TRACK_FRAME_TIME_KEY);
-        mAllPrefs.add(mTrackFrameTime);
-        mTrackFrameTime.setOnPreferenceChangeListener(this);
+        mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
+        mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
         mShowHwScreenUpdates = findAndInitCheckboxPref(SHOW_HW_SCREEN_UPDATES_KEY);
         mShowHwLayersUpdates = findAndInitCheckboxPref(SHOW_HW_LAYERS_UPDATES_KEY);
         mShowHwOverdraw = findAndInitCheckboxPref(SHOW_HW_OVERDRAW_KEY);
         mDebugLayout = findAndInitCheckboxPref(DEBUG_LAYOUT_KEY);
-        mWindowAnimationScale = (ListPreference) findPreference(WINDOW_ANIMATION_SCALE_KEY);
-        mAllPrefs.add(mWindowAnimationScale);
-        mWindowAnimationScale.setOnPreferenceChangeListener(this);
-        mTransitionAnimationScale = (ListPreference) findPreference(TRANSITION_ANIMATION_SCALE_KEY);
-        mAllPrefs.add(mTransitionAnimationScale);
-        mTransitionAnimationScale.setOnPreferenceChangeListener(this);
-        mAnimatorDurationScale = (ListPreference) findPreference(ANIMATOR_DURATION_SCALE_KEY);
-        mAllPrefs.add(mAnimatorDurationScale);
-        mAnimatorDurationScale.setOnPreferenceChangeListener(this);
-        mOverlayDisplayDevices = (ListPreference) findPreference(OVERLAY_DISPLAY_DEVICES_KEY);
-        mAllPrefs.add(mOverlayDisplayDevices);
-        mOverlayDisplayDevices.setOnPreferenceChangeListener(this);
-        mOpenGLTraces = (ListPreference) findPreference(OPENGL_TRACES_KEY);
-        mAllPrefs.add(mOpenGLTraces);
-        mOpenGLTraces.setOnPreferenceChangeListener(this);
+        mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
+        mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
+        mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
+        mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
+        mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
 
         mImmediatelyDestroyActivities = (CheckBoxPreference) findPreference(
                 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
         mAllPrefs.add(mImmediatelyDestroyActivities);
         mResetCbPrefs.add(mImmediatelyDestroyActivities);
-        mAppProcessLimit = (ListPreference) findPreference(APP_PROCESS_LIMIT_KEY);
-        mAllPrefs.add(mAppProcessLimit);
-        mAppProcessLimit.setOnPreferenceChangeListener(this);
+        mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
 
         mShowAllANRs = (CheckBoxPreference) findPreference(
                 SHOW_ALL_ANRS_KEY);
@@ -295,6 +282,13 @@
         removeHdcpOptionsForProduction();
     }
 
+    private ListPreference addListPreference(String prefKey) {
+        ListPreference pref = (ListPreference) findPreference(prefKey);
+        mAllPrefs.add(pref);
+        pref.setOnPreferenceChangeListener(this);
+        return pref;
+    }
+
     private void disableForUser(Preference pref) {
         if (pref != null) {
             pref.setEnabled(false);
@@ -426,6 +420,7 @@
         updateHardwareUiOptions();
         updateMsaaOptions();
         updateTrackFrameTimeOptions();
+        updateShowNonRectClipOptions();
         updateShowHwScreenUpdatesOptions();
         updateShowHwLayersUpdatesOptions();
         updateShowHwOverdrawOptions();
@@ -735,6 +730,32 @@
         updateTrackFrameTimeOptions();
     }
 
+    private void updateShowNonRectClipOptions() {
+        String value = SystemProperties.get(
+                HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
+        if (value == null) {
+            value = "hide";
+        }
+
+        CharSequence[] values = mShowNonRectClip.getEntryValues();
+        for (int i = 0; i < values.length; i++) {
+            if (value.contentEquals(values[i])) {
+                mShowNonRectClip.setValueIndex(i);
+                mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
+                return;
+            }
+        }
+        mShowNonRectClip.setValueIndex(0);
+        mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
+    }
+
+    private void writeShowNonRectClipOptions(Object newValue) {
+        SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
+                newValue == null ? "" : newValue.toString());
+        pokeSystemProperties();
+        updateShowNonRectClipOptions();
+    }
+
     private void updateShowHwScreenUpdatesOptions() {
         updateCheckBox(mShowHwScreenUpdates,
                 SystemProperties.getBoolean(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
@@ -1092,6 +1113,9 @@
         } else if (preference == mTrackFrameTime) {
             writeTrackFrameTimeOptions(newValue);
             return true;
+        } else if (preference == mShowNonRectClip) {
+            writeShowNonRectClipOptions(newValue);
+            return true;
         } else if (preference == mAppProcessLimit) {
             writeAppProcessLimitOptions(newValue);
             return true;
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/applications/AppOpsState.java b/src/com/android/settings/applications/AppOpsState.java
index 39ce0b9..6cdbdaf 100644
--- a/src/com/android/settings/applications/AppOpsState.java
+++ b/src/com/android/settings/applications/AppOpsState.java
@@ -115,13 +115,17 @@
                     AppOpsManager.OP_READ_CALL_LOG,
                     AppOpsManager.OP_WRITE_CALL_LOG,
                     AppOpsManager.OP_READ_CALENDAR,
-                    AppOpsManager.OP_WRITE_CALENDAR },
+                    AppOpsManager.OP_WRITE_CALENDAR,
+                    AppOpsManager.OP_READ_CLIPBOARD,
+                    AppOpsManager.OP_WRITE_CLIPBOARD },
             new boolean[] { true,
                     true,
                     true,
                     true,
                     true,
-                    true }
+                    true,
+                    false,
+                    false }
             );
 
     public static final OpsTemplate MESSAGING_TEMPLATE = new OpsTemplate(
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