Merge "Allow system apps to be disabled" into nyc-dev
diff --git a/res/layout/preference_list_fragment.xml b/res/layout/preference_list_fragment.xml
index 42c9139..2621ada 100644
--- a/res/layout/preference_list_fragment.xml
+++ b/res/layout/preference_list_fragment.xml
@@ -33,14 +33,14 @@
         android:id="@android:id/list_container"
         android:layout_height="0px"
         android:layout_weight="1"
-        android:layout_width="match_parent">
+        android:layout_width="match_parent"
+        android:paddingStart="@dimen/settings_side_margin"
+        android:paddingEnd="@dimen/settings_side_margin">
 
         <ListView android:id="@+id/backup_list"
             style="@style/PreferenceFragmentListSinglePane"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:paddingStart="@dimen/settings_side_margin"
-            android:paddingEnd="@dimen/settings_side_margin"
             android:paddingTop="@dimen/dashboard_padding_top"
             android:paddingBottom="@dimen/dashboard_padding_bottom"
             android:scrollbarStyle="@*android:integer/preference_fragment_scrollbarStyle"
diff --git a/res/layout/redaction_interstitial.xml b/res/layout/redaction_interstitial.xml
index aafeb1b..e7678ce 100644
--- a/res/layout/redaction_interstitial.xml
+++ b/res/layout/redaction_interstitial.xml
@@ -44,21 +44,21 @@
 
         <com.android.settings.RestrictedRadioButton
                 android:id="@+id/show_all"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/redaction_vertical_margins"
                 android:text="@string/lock_screen_notifications_summary_show" />
 
         <com.android.settings.RestrictedRadioButton
                 android:id="@+id/redact_sensitive"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/redaction_vertical_margins"
                 android:text="@string/lock_screen_notifications_summary_hide" />
 
         <RadioButton
                 android:id="@+id/hide_all"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/redaction_vertical_margins"
                 android:text="@string/lock_screen_notifications_summary_disable" />
@@ -72,7 +72,6 @@
             android:layout_marginTop="@dimen/redaction_vertical_margins"
             android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
             android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
-            android:text="@string/lockscreen_remote_input"
-            android:textAppearance="?android:attr/textAppearanceMedium" />
+            android:text="@string/lockscreen_remote_input" />
 
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/restricted_dialog_singlechoice.xml b/res/layout/restricted_dialog_singlechoice.xml
index f75493e..3daedc7 100644
--- a/res/layout/restricted_dialog_singlechoice.xml
+++ b/res/layout/restricted_dialog_singlechoice.xml
@@ -21,12 +21,14 @@
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         android:paddingStart="20dp"
+        android:gravity="center"
         android:paddingEnd="?android:attr/dialogPreferredPadding"
         android:minHeight="?android:attr/listPreferredItemHeightSmall">
     <CheckedTextView
             android:id="@+id/text1"
-            android:layout_width="wrap_content"
+            android:layout_width="0dp"
             android:layout_height="wrap_content"
+            android:layout_weight="1"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:textColor="?android:attr/textColorAlertDialogListItem"
             android:gravity="center_vertical"
diff --git a/res/layout/restricted_radio_with_summary.xml b/res/layout/restricted_radio_with_summary.xml
new file mode 100644
index 0000000..399d11d
--- /dev/null
+++ b/res/layout/restricted_radio_with_summary.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2016 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<com.android.settings.CheckableLinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:background="?android:attr/selectableItemBackground"
+    android:minHeight="?android:attr/listPreferredItemHeightSmall">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:paddingStart="20dp"
+        android:paddingEnd="?android:attr/dialogPreferredPadding">
+        <CheckedTextView
+            android:id="@android:id/title"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textColor="?android:attr/textColorAlertDialogListItem"
+            android:gravity="center_vertical"
+            android:drawableStart="?android:attr/listChoiceIndicatorSingle"
+            android:ellipsize="marquee" />
+        <ImageView
+            android:id="@+id/restricted_icon"
+            android:layout_width="@dimen/restricted_icon_size"
+            android:layout_height="match_parent"
+            android:scaleType="centerInside"
+            android:src="@drawable/ic_info"
+            android:layout_marginLeft="@dimen/restricted_icon_padding"
+            android:visibility="gone" />
+    </LinearLayout>
+
+
+    <TextView android:id="@android:id/summary"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingBottom="8dp"
+        android:paddingStart="52dp"
+        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+        android:textColor="?android:attr/textColorSecondary"
+        android:maxLines="10" />
+
+</com.android.settings.CheckableLinearLayout>
\ No newline at end of file
diff --git a/res/layout/settings_main_prefs.xml b/res/layout/settings_main_prefs.xml
index 7d6ce08..4f08679 100644
--- a/res/layout/settings_main_prefs.xml
+++ b/res/layout/settings_main_prefs.xml
@@ -39,8 +39,6 @@
                 android:id="@+id/main_content"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:paddingStart="@dimen/dashboard_padding_start"
-                android:paddingEnd="@dimen/dashboard_padding_end"
                 />
 
     </LinearLayout>
diff --git a/res/layout/setup_redaction_interstitial.xml b/res/layout/setup_redaction_interstitial.xml
index 59b7e08..e0f2d94 100644
--- a/res/layout/setup_redaction_interstitial.xml
+++ b/res/layout/setup_redaction_interstitial.xml
@@ -44,7 +44,7 @@
 
         <RadioGroup
             android:id="@+id/radio_group"
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/redaction_vertical_margins"
             android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
@@ -72,27 +72,17 @@
                 android:layout_height="wrap_content"
                 android:text="@string/lock_screen_notifications_summary_disable" />
 
-            <!-- CheckBox is styled with SuwRadioButton to make it line up nicely with the radios
-                 above. -->
+            <!-- Place the checkbox inside RadioGroup and use SuwRadioButton style instead of
+                 SuwCheckBox style so that the checkbox and text is aligned with radio buttons. -->
             <CheckBox
                 android:id="@+id/lockscreen_remote_input"
-                android:layout_width="match_parent"
+                style="@style/SuwRadioButton"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="@dimen/suw_check_box_margin_top"
-                android:text="@string/lockscreen_remote_input"
-                style="@style/SuwRadioButton" />
+                android:layout_marginTop="@dimen/redaction_vertical_margins"
+                android:text="@string/lockscreen_remote_input" />
         </RadioGroup>
 
-        <CheckBox
-            android:id="@+id/lockscreen_remote_input"
-            style="@style/SuwCheckBox"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/redaction_vertical_margins"
-            android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
-            android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
-            android:text="@string/lockscreen_remote_input" />
-
     </LinearLayout>
 
 </com.android.setupwizardlib.SetupWizardLayout>
diff --git a/res/layout/switch_bar.xml b/res/layout/switch_bar.xml
index 7136624..a31bd3e 100644
--- a/res/layout/switch_bar.xml
+++ b/res/layout/switch_bar.xml
@@ -30,6 +30,15 @@
               android:textColor="?android:attr/textColorPrimary"
               android:textAlignment="viewStart" />
 
+    <ImageView android:id="@+id/restricted_icon"
+            android:layout_width="@dimen/restricted_icon_size"
+            android:layout_height="@dimen/restricted_icon_size"
+            android:src="@drawable/ic_info"
+            android:theme="@android:style/Theme.Material"
+            android:layout_gravity="center_vertical"
+            android:layout_marginEnd="@dimen/restricted_icon_margin_end"
+            android:visibility="gone" />
+
     <com.android.settings.widget.ToggleSwitch android:id="@+id/switch_widget"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 53dd515..c84129a 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -285,4 +285,7 @@
     <dimen name="screen_magnification_video_height">311dp</dimen>
     <dimen name="screen_magnification_video_margin_top">40dp</dimen>
 
+    <!-- Restricted icon in switch bar -->
+    <dimen name="restricted_icon_margin_end">16dp</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ac27897..c2ff86e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7357,4 +7357,13 @@
     <!-- Developer option to convert to file encryption - final button -->
     <string name="button_confirm_convert_fbe">Wipe and convert</string>
 
+    <!-- Reset rate-limiting in the system service ShortcutManager. [CHAR_LIMIT=none] -->
+    <string name="reset_shortcut_manager_throttling">Reset ShortcutManager rate-limiting counters</string>
+
+    <!-- Title of the dialog box to confirm resetting rate-limiting in the system service ShortcutManager. [CHAR_LIMIT=none] -->
+    <string name="confirm_reset_shortcut_manager_throttling_title">Reset ShortcutManager rate-limiting?</string>
+
+    <!-- Message of the dialog box to confirm resetting rate-limiting in the system service ShortcutManager. [CHAR_LIMIT=none] -->
+    <string name="confirm_reset_shortcut_manager_throttling_message">Reset ShortcutManager rate-limiting counters?</string>
+
 </resources>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 1b056b8..e58ff95 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -365,6 +365,10 @@
             android:key="force_resizable_activities"
             android:title="@string/force_resizable_activities"
             android:summary="@string/force_resizable_activities_summary"/>
+
+        <Preference
+            android:key="reset_shortcut_manager_throttling"
+            android:title="@string/reset_shortcut_manager_throttling" />
      </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index d604473..e33c081 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -23,8 +23,6 @@
 import android.app.AppOpsManager;
 import android.app.AppOpsManager.PackageOps;
 import android.app.Dialog;
-import android.app.DialogFragment;
-import android.app.UiModeManager;
 import android.app.admin.DevicePolicyManager;
 import android.app.backup.IBackupManager;
 import android.bluetooth.BluetoothAdapter;
@@ -36,6 +34,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
+import android.content.pm.IShortcutService;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
@@ -60,7 +59,6 @@
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.DropDownPreference;
 import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
@@ -212,6 +210,8 @@
     private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
     private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
 
+    private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
+
     private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
 
     private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
@@ -1919,6 +1919,8 @@
             writeBluetoothDisableAbsVolumeOptions();
         } else if (preference == mWebViewMultiprocess) {
             writeWebViewMultiprocessOptions();
+        } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
+            confirmResetShortcutManagerThrottling();
         } else {
             return super.onPreferenceTreeClick(preference);
         }
@@ -2171,4 +2173,30 @@
                     return keys;
                 }
             };
+
+    private void confirmResetShortcutManagerThrottling() {
+        final IShortcutService service = IShortcutService.Stub.asInterface(
+                ServiceManager.getService(Context.SHORTCUT_SERVICE));
+
+        DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                if (which == DialogInterface.BUTTON_POSITIVE) {
+                    try {
+                        service.resetThrottling();
+                    } catch (RemoteException e) {
+                    }
+                }
+            }
+        };
+
+        new AlertDialog.Builder(getActivity())
+                .setTitle(R.string.confirm_reset_shortcut_manager_throttling_title)
+                .setMessage(R.string.confirm_reset_shortcut_manager_throttling_message)
+                .setPositiveButton(R.string.okay, onClickListener)
+                .setNegativeButton(android.R.string.cancel, null)
+                .create()
+                .show();
+
+    }
 }
diff --git a/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
index e1f8950..bb8ffc1 100644
--- a/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
+++ b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
@@ -130,7 +130,7 @@
 
     private void inflateOption(final int mode, boolean selected, LinearLayout container,
             final boolean disallowedByAdmin) {
-        View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
+        View v = mLayoutInflater.inflate(R.layout.restricted_radio_with_summary, container, false);
 
         TextView titleView = (TextView) v.findViewById(android.R.id.title);
         titleView.setText(getTitle(mode));
@@ -139,7 +139,7 @@
 
         if (disallowedByAdmin) {
             if (mEnforcedAdmin != null) {
-                setDisabledByAdmin(titleView, summaryView);
+                setDisabledByAdmin(v, titleView, summaryView);
             } else {
                 return;
             }
@@ -164,12 +164,11 @@
         container.addView(v);
     }
 
-    private void setDisabledByAdmin(TextView titleView, TextView summaryView) {
+    private void setDisabledByAdmin(View rootView, TextView titleView, TextView summaryView) {
         if (mEnforcedAdmin != null) {
             titleView.setEnabled(false);
             summaryView.setEnabled(false);
-            RestrictedLockUtils.setTextViewPadlock(this,
-                    titleView, true /* showPadlock */);
+            rootView.findViewById(R.id.restricted_icon).setVisibility(View.VISIBLE);
             Drawable[] compoundDrawables = titleView.getCompoundDrawablesRelative();
             compoundDrawables[0 /* start */].mutate().setColorFilter(
                     getColor(R.color.disabled_text_color), PorterDuff.Mode.MULTIPLY);
diff --git a/src/com/android/settings/fuelgauge/FakeUid.java b/src/com/android/settings/fuelgauge/FakeUid.java
index e70ede5..80adb67 100644
--- a/src/com/android/settings/fuelgauge/FakeUid.java
+++ b/src/com/android/settings/fuelgauge/FakeUid.java
@@ -187,6 +187,11 @@
     }
 
     @Override
+    public Timer getProcessStateTimer(int state) {
+        return null;
+    }
+
+    @Override
     public Timer getVibratorOnTimer() {
         return null;
     }
diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java
index adf1ce0..3d8a5a6 100644
--- a/src/com/android/settings/widget/SwitchBar.java
+++ b/src/com/android/settings/widget/SwitchBar.java
@@ -58,6 +58,7 @@
     private final TextAppearanceSpan mSummarySpan;
 
     private ToggleSwitch mSwitch;
+    private View mRestrictedIcon;
     private TextView mTextView;
     private String mLabel;
     private String mSummary;
@@ -122,6 +123,8 @@
             }
         });
 
+        mRestrictedIcon = findViewById(R.id.restricted_icon);
+
         setOnClickListener(this);
 
         // Default is hide
@@ -189,12 +192,14 @@
         if (admin != null) {
             super.setEnabled(true);
             mDisabledByAdmin = true;
-            RestrictedLockUtils.setTextViewPadlock(mContext, mTextView, true);
             mTextView.setEnabled(false);
             mSwitch.setEnabled(false);
+            mSwitch.setVisibility(View.GONE);
+            mRestrictedIcon.setVisibility(View.VISIBLE);
         } else {
             mDisabledByAdmin = false;
-            RestrictedLockUtils.setTextViewPadlock(mContext, mTextView, false);
+            mSwitch.setVisibility(View.VISIBLE);
+            mRestrictedIcon.setVisibility(View.GONE);
             setEnabled(true);
         }
     }