Merge "Fix crash when selecting AppInfo for uninstalled app from Recents." into nyc-mr1-dev
diff --git a/res/drawable/drag_handle.xml b/res/drawable/drag_handle.xml
index 33a68c6..835ac5b 100644
--- a/res/drawable/drag_handle.xml
+++ b/res/drawable/drag_handle.xml
@@ -22,6 +22,6 @@
         android:tint="@color/material_grey_600">
 
     <path android:fillColor="@android:color/white"
-          android:pathData="M8,18v4h32v-4hm-32,8v4h32v-4z" />
+          android:pathData="M6,30h36v-4L6,26v4zM6,38h36v-4L6,34v4zM6,22h36L42,18L6,18v4zM6,10v4h36L42,10L6,10z" />
 
 </vector>
diff --git a/res/drawable/ic_wifi_signal_0.xml b/res/drawable/ic_wifi_signal_0.xml
new file mode 100644
index 0000000..55faf64
--- /dev/null
+++ b/res/drawable/ic_wifi_signal_0.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2015 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+  android:width="26dp"
+  android:height="24dp"
+  android:viewportWidth="26"
+  android:viewportHeight="24">
+  <path
+    android:fillAlpha="0.3"
+    android:fillColor="?attr/wifi_signal_color"
+    android:pathData="M13.0,22.0L25.6,6.5C25.1,6.1 20.3,2.1 13.0,2.1S0.9,6.1 0.4,6.5L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0L13.0,22.0z"/>
+</vector>
\ No newline at end of file
diff --git a/res/layout/condition_card.xml b/res/layout/condition_card.xml
index 9d18abc5..7c9e46d 100644
--- a/res/layout/condition_card.xml
+++ b/res/layout/condition_card.xml
@@ -25,7 +25,6 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical"
-        android:paddingStart="16dp"
         android:background="?android:attr/colorAccent"
         android:elevation="2dp"
         android:clickable="true"
@@ -35,6 +34,7 @@
             android:id="@+id/collapsed_group"
             android:layout_width="match_parent"
             android:layout_height="56dp"
+            android:background="?android:attr/selectableItemBackground"
             android:orientation="horizontal"
             android:gravity="center">
 
@@ -42,6 +42,7 @@
                 android:id="@android:id/icon"
                 android:layout_width="24dp"
                 android:layout_height="wrap_content"
+                android:layout_marginStart="16dp"
                 android:layout_marginEnd="32dp"
                 android:tint="?android:attr/textColorPrimaryInverse" />
 
@@ -58,10 +59,7 @@
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 android:padding="16dp"
-                android:tint="?android:attr/textColorPrimaryInverse"
-                android:clickable="true"
-                android:focusable="true"
-                android:background="?android:attr/selectableItemBackground" />
+                android:tint="?android:attr/textColorPrimaryInverse"/>
 
         </LinearLayout>
 
@@ -69,7 +67,7 @@
             android:id="@+id/detail_group"
             android:layout_width="match_parent"
             android:layout_height="0dp"
-            android:paddingStart="56dp"
+            android:paddingStart="72dp"
             android:visibility="gone"
             android:orientation="vertical">
 
diff --git a/res/layout/dashboard.xml b/res/layout/dashboard.xml
index ebf5204..f1bf259 100644
--- a/res/layout/dashboard.xml
+++ b/res/layout/dashboard.xml
@@ -19,9 +19,10 @@
     android:id="@+id/dashboard_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:clipChildren="false"
+    android:clipToPadding="false"
+    android:focusable="false"
     android:paddingStart="@dimen/dashboard_padding_start"
     android:paddingEnd="@dimen/dashboard_padding_end"
     android:paddingTop="@dimen/dashboard_padding_top"
-    android:paddingBottom="@dimen/dashboard_padding_bottom"
-    android:clipChildren="false"
-    android:clipToPadding="false" />
+    android:paddingBottom="@dimen/dashboard_padding_bottom"/>
diff --git a/res/layout/enable_accessibility_service_dialog_content.xml b/res/layout/enable_accessibility_service_dialog_content.xml
index 25c6ba2..3ca40ac 100644
--- a/res/layout/enable_accessibility_service_dialog_content.xml
+++ b/res/layout/enable_accessibility_service_dialog_content.xml
@@ -26,25 +26,30 @@
         android:layout_height="wrap_content"
         android:orientation="vertical"
         android:paddingStart="16dip"
-        android:paddingEnd="16dip" >
+        android:paddingEnd="16dip">
 
-        <TextView android:id="@+id/encryption_warning"
+        <TextView
+            android:id="@+id/encryption_warning"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:padding="10dip"
+            android:textAlignment="viewStart"
             android:textAppearance="?android:attr/textAppearanceMedium"/>
 
-        <TextView android:id="@+id/capabilities_header"
+        <TextView
+            android:id="@+id/capabilities_header"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:padding="10dip"
-            android:textAppearance="?android:attr/textAppearanceMedium" />
+            android:textAlignment="viewStart"
+            android:textAppearance="?android:attr/textAppearanceMedium"/>
 
-        <LinearLayout android:id="@+id/capabilities"
+        <LinearLayout
+            android:id="@+id/capabilities"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical"
-            android:padding="10dip" />
+            android:padding="10dip"/>
 
     </LinearLayout>
 
diff --git a/res/layout/nfc_payment_option.xml b/res/layout/nfc_payment_option.xml
index 90ba279..be5fe5f 100644
--- a/res/layout/nfc_payment_option.xml
+++ b/res/layout/nfc_payment_option.xml
@@ -21,7 +21,7 @@
     android:focusable="true"
     android:clickable="false"
     android:orientation="horizontal"
-    android:paddingLeft="24dip"
+    android:paddingStart="24dip"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:background="?android:attr/selectableItemBackground">
     <RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
diff --git a/res/layout/support_fragment.xml b/res/layout/support_fragment.xml
index 481a548..10b9418 100644
--- a/res/layout/support_fragment.xml
+++ b/res/layout/support_fragment.xml
@@ -19,4 +19,5 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/support_items"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"/>
\ No newline at end of file
+    android:layout_height="match_parent"
+    android:focusable="false"  />
\ No newline at end of file
diff --git a/res/layout/support_offline_escalation_options.xml b/res/layout/support_offline_escalation_options.xml
index 6a54fba..08c52aa 100644
--- a/res/layout/support_offline_escalation_options.xml
+++ b/res/layout/support_offline_escalation_options.xml
@@ -41,6 +41,7 @@
         android:layout_height="wrap_content"
         android:orientation="horizontal">
         <TextView
+            android:id="@+id/support_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:paddingEnd="8dp"
diff --git a/res/layout/user_dictionary_add_word.xml b/res/layout/user_dictionary_add_word.xml
index 3624dad..2b8c19a 100644
--- a/res/layout/user_dictionary_add_word.xml
+++ b/res/layout/user_dictionary_add_word.xml
@@ -14,72 +14,73 @@
      limitations under the License.
   -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:id="@+id/user_dict_settings_add_dialog_top"
-              android:layout_width="match_parent"
-              android:layout_height="wrap_content"
-              android:orientation="vertical">
+        android:id="@+id/user_dict_settings_add_dialog_top"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
 
   <LinearLayout android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="vertical">
+          android:layout_height="wrap_content"
+          android:orientation="vertical">
     <com.android.internal.widget.DialogTitle
-          style="?android:attr/windowTitleStyle"
-          android:singleLine="true"
-          android:ellipsize="end"
-          android:layout_width="match_parent"
-          android:layout_height="64dip"
-          android:layout_marginStart="16dip"
-          android:layout_marginEnd="16dip"
-          android:gravity="center_vertical|start"
-          android:text="@string/user_dict_settings_add_dialog_title" />
-    <View android:layout_width="match_parent"
-          android:layout_height="2dip"
-          android:background="@android:color/holo_blue_light" />
+            style="?android:attr/windowTitleStyle"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="24dip"
+            android:layout_marginEnd="24dip"
+            android:layout_marginTop="24dip"
+            android:layout_marginBottom="0dip"
+            android:ellipsize="end"
+            android:gravity="center_vertical|start"
+            android:singleLine="true"
+            android:text="@string/user_dict_settings_add_dialog_title" />
   </LinearLayout>
 
   <EditText android:id="@+id/user_dictionary_add_word_text"
-            android:maxLength="@integer/maximum_user_dictionary_word_length"
-            android:layout_height="match_parent"
-            android:layout_width="match_parent"
-            android:layout_gravity="fill_horizontal|center_vertical"
-            android:layout_marginStart="8dip"
-            android:layout_marginBottom="8dip"
-            android:layout_marginTop="8dip"
-            android:hint="@string/user_dict_settings_add_word_hint"
-            android:inputType="textNoSuggestions"
-            android:imeOptions="flagNoFullscreen">
+          android:layout_width="match_parent"
+          android:layout_height="match_parent"
+          android:layout_gravity="fill_horizontal|center_vertical"
+          android:layout_marginStart="24dip"
+          android:layout_marginEnd="24dip"
+          android:layout_marginTop="20dip"
+          android:layout_marginBottom="24dip"
+          android:hint="@string/user_dict_settings_add_word_hint"
+          android:imeOptions="flagNoFullscreen"
+          android:inputType="textNoSuggestions"
+          android:maxLength="@integer/maximum_user_dictionary_word_length">
     <requestFocus />
   </EditText>
 
   <LinearLayout android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="vertical"
-                android:divider="?android:attr/dividerHorizontal"
-                android:showDividers="beginning"
-                android:dividerPadding="0dip">
+          android:layout_height="wrap_content"
+          android:divider="?android:attr/dividerHorizontal"
+          android:dividerPadding="0dip"
+          android:orientation="vertical"
+          android:showDividers="beginning">
     <LinearLayout style="?android:attr/buttonBarStyle"
-                  android:layout_width="match_parent"
-                  android:layout_height="wrap_content"
-                  android:orientation="horizontal"
-                  android:measureWithLargestChild="true">
-      <Button android:layout_width="0dip"
-              android:layout_gravity="start"
-              android:layout_weight="1"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="end"
+            android:orientation="horizontal">
+      <Button style="?android:attr/buttonBarButtonStyle"
+              android:layout_width="wrap_content"
+              android:layout_height="36dip"
+              android:layout_marginTop="8dip"
+              android:layout_marginBottom="8dip"
+              android:layout_marginLeft="8dip"
+              android:layout_marginRight="0dip"
               android:maxLines="2"
-              style="?android:attr/buttonBarButtonStyle"
+              android:onClick="onClickCancel"
               android:textSize="14sp"
-              android:text="@string/cancel"
-              android:layout_height="wrap_content"
-              android:onClick="onClickCancel" />
-      <Button android:layout_width="0dip"
-              android:layout_gravity="end"
-              android:layout_weight="1"
+              android:text="@string/cancel" />
+      <Button style="?android:attr/buttonBarButtonStyle"
+              android:layout_width="wrap_content"
+              android:layout_height="36dip"
+              android:layout_margin="8dip"
               android:maxLines="2"
-              style="?android:attr/buttonBarButtonStyle"
+              android:onClick="onClickConfirm"
               android:textSize="14sp"
-              android:text="@string/user_dict_settings_add_dialog_confirm"
-              android:layout_height="wrap_content"
-              android:onClick="onClickConfirm" />
+              android:text="@string/user_dict_settings_add_dialog_confirm" />
     </LinearLayout>
   </LinearLayout>
-</LinearLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/values-fr-rCA/strings.xml b/res/values-fr-rCA/strings.xml
index b901058..64efd46 100644
--- a/res/values-fr-rCA/strings.xml
+++ b/res/values-fr-rCA/strings.xml
@@ -3018,7 +3018,7 @@
     <string name="condition_hotspot_summary" msgid="3433182779269409683">"Le point d\'accès Wi-Fi mobile « <xliff:g id="ID_1">%1$s</xliff:g> » est actif. Le Wi-Fi est désactivé pour cet appareil."</string>
     <string name="condition_airplane_title" msgid="287356299107070503">"Le mode Avion est activé"</string>
     <string name="condition_airplane_summary" msgid="2136872325308526329">"Le Wi-Fi, le Bluetooth et le réseau cellulaire sont désactivés. Vous ne pouvez pas faire d\'appels téléphoniques ni vous connecter à Internet."</string>
-    <string name="condition_zen_title" msgid="2679168532600816392">"Mode Ne pas déranger activé (<xliff:g id="ID_1">%1$s</xliff:g>)"</string>
+    <string name="condition_zen_title" msgid="2679168532600816392">"Mode « Ne pas déranger » activé (<xliff:g id="ID_1">%1$s</xliff:g>)"</string>
     <string name="condition_battery_title" msgid="3272131008388575349">"Économie d\'énergie activée"</string>
     <string name="condition_battery_summary" msgid="4418839236027977450">"Les performances sont réduites. Les services de localisation et les données en arrière-plan sont désactivés."</string>
     <string name="condition_cellular_title" msgid="2398754272044917264">"Données cellulaire désactivées"</string>
diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml
index eb37d0f..eeb677a 100755
--- a/res/values-sw600dp-land/dimens.xml
+++ b/res/values-sw600dp-land/dimens.xml
@@ -27,4 +27,6 @@
     <!-- CryptKeeper top margin for pattern screen -->
     <dimen name="crypt_keeper_pattern_top_margin">128dip</dimen>
 
+    <dimen name="captioning_preview_height">150dp</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fa17aab..9b8614a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7733,7 +7733,7 @@
     <string name="double_tap_power_for_camera_title">Jump to Camera</string>
 
     <!-- Summary text for double tap power for camera [CHAR LIMIT=160]-->
-    <string name="double_tap_power_for_camera_summary">To quickly open camera, just double-tap the power button. Works from any screen</string>
+    <string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen</string>
 
     <!-- Title text for double twist for camera mode [CHAR LIMIT=60]-->
     <string name="double_twist_for_camera_mode_title">Flip camera</string>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index dbcb277..4e5da6e 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -53,11 +53,11 @@
 import android.os.StrictMode;
 import android.os.SystemProperties;
 import android.os.UserHandle;
-import android.service.persistentdata.PersistentDataBlockManager;
 import android.os.UserManager;
 import android.os.storage.IMountService;
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
+import android.service.persistentdata.PersistentDataBlockManager;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
@@ -67,9 +67,9 @@
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
-import android.view.ThreadedRenderer;
 import android.view.IWindowManager;
 import android.view.LayoutInflater;
+import android.view.ThreadedRenderer;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityManager;
@@ -684,10 +684,6 @@
                 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
         updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
                 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
-        if (mEnableOemUnlock != null) {
-            updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
-            updateOemUnlockSettingDescription();
-        }
         updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
                 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
         updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr,
@@ -1039,6 +1035,8 @@
 
     private void updateOemUnlockOptions() {
         if (mEnableOemUnlock != null) {
+            updateSwitchPreference(mEnableOemUnlock, isBootloaderUnlocked());
+            updateOemUnlockSettingDescription();
             // Showing mEnableOemUnlock preference as device has persistent data block.
             mEnableOemUnlock.setDisabledByAdmin(null);
             mEnableOemUnlock.setEnabled(enableOemUnlockPreference());
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 5b81c56..05d67b5 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -588,7 +588,6 @@
             // of starting fresh.
             mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
             mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
-
             setTitleFromIntent(intent);
 
             ArrayList<DashboardCategory> categories =
@@ -601,6 +600,7 @@
 
             mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
             mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
+
         } else {
             if (!mIsShowingDashboard) {
                 mDisplaySearch = false;
@@ -623,7 +623,13 @@
                 // Show Search affordance
                 mDisplaySearch = true;
                 mInitialTitleResId = R.string.dashboard_title;
-                switchToFragment(DashboardContainerFragment.class.getName(), null, false, false,
+
+                // add argument to indicate which settings tab should be initially selected
+                final Bundle args = new Bundle();
+                final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
+                args.putString(extraName, intent.getStringExtra(extraName));
+
+                switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
                         mInitialTitleResId, mInitialTitle, false);
             }
         }
@@ -1272,5 +1278,4 @@
         }
         super.onActivityResult(requestCode, resultCode, data);
     }
-
 }
diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java
index 357ec1e..7c7d5a5 100644
--- a/src/com/android/settings/applications/AppStorageSettings.java
+++ b/src/com/android/settings/applications/AppStorageSettings.java
@@ -60,6 +60,9 @@
 import java.util.Objects;
 import java.util.TreeMap;
 
+import static android.content.pm.ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
+import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
+
 public class AppStorageSettings extends AppInfoWithHeader
         implements OnClickListener, Callbacks, DialogInterface.OnClickListener {
     private static final String TAG = AppStorageSettings.class.getSimpleName();
@@ -354,19 +357,27 @@
     }
 
     private void initDataButtons() {
-        // If the app doesn't have its own space management UI
-        // And it's a system app that doesn't allow clearing user data or is an active admin
-        // Then disable the Clear Data button.
-        if (mAppEntry.info.manageSpaceActivityName == null
-                && ((mAppEntry.info.flags&(ApplicationInfo.FLAG_SYSTEM
-                        | ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA))
-                        == ApplicationInfo.FLAG_SYSTEM
-                        || mDpm.packageHasActiveAdmins(mPackageName))) {
+        final boolean appHasSpaceManagementUI = mAppEntry.info.manageSpaceActivityName != null;
+        final boolean appHasActiveAdmins = mDpm.packageHasActiveAdmins(mPackageName);
+        // Check that SYSTEM_APP flag is set, and ALLOW_CLEAR_USER_DATA is not set.
+        final boolean isNonClearableSystemApp =
+                (mAppEntry.info.flags & (FLAG_SYSTEM | FLAG_ALLOW_CLEAR_USER_DATA)) == FLAG_SYSTEM;
+        final boolean appRestrictsClearingData = isNonClearableSystemApp || appHasActiveAdmins;
+
+        final Intent intent = new Intent(Intent.ACTION_DEFAULT);
+        if (appHasSpaceManagementUI) {
+            intent.setClassName(mAppEntry.info.packageName, mAppEntry.info.manageSpaceActivityName);
+        }
+        final boolean isManageSpaceActivityAvailable =
+                getPackageManager().resolveActivity(intent, 0) != null;
+
+        if ((!appHasSpaceManagementUI && appRestrictsClearingData)
+                || !isManageSpaceActivityAvailable) {
             mClearDataButton.setText(R.string.clear_user_data_text);
             mClearDataButton.setEnabled(false);
             mCanClearData = false;
         } else {
-            if (mAppEntry.info.manageSpaceActivityName != null) {
+            if (appHasSpaceManagementUI) {
                 mClearDataButton.setText(R.string.manage_space_text);
             } else {
                 mClearDataButton.setText(R.string.clear_user_data_text);
diff --git a/src/com/android/settings/applications/DefaultPhonePreference.java b/src/com/android/settings/applications/DefaultPhonePreference.java
index 5689c83..e151274 100644
--- a/src/com/android/settings/applications/DefaultPhonePreference.java
+++ b/src/com/android/settings/applications/DefaultPhonePreference.java
@@ -82,9 +82,13 @@
             return false;
         }
 
-        final UserManager um =
-                (UserManager) context.getSystemService(Context.USER_SERVICE);
-        return !um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
+        final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        final boolean hasUserRestriction =
+                um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
+        final CharSequence[] entries = getEntries();
+        return !hasUserRestriction
+                && entries != null
+                && entries.length > 0;
     }
 
     public static boolean hasPhonePreference(String pkg, Context context) {
diff --git a/src/com/android/settings/applications/ProcStatsEntry.java b/src/com/android/settings/applications/ProcStatsEntry.java
index 36d397e..90ef5d7 100644
--- a/src/com/android/settings/applications/ProcStatsEntry.java
+++ b/src/com/android/settings/applications/ProcStatsEntry.java
@@ -20,12 +20,13 @@
 import android.content.pm.PackageManager;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Log;
 import android.util.SparseArray;
 
-import com.android.internal.app.procstats.ProcessStats;
 import com.android.internal.app.procstats.ProcessState;
+import com.android.internal.app.procstats.ProcessStats;
 import com.android.internal.app.procstats.ServiceState;
 
 import java.util.ArrayList;
@@ -33,6 +34,7 @@
 import java.util.Comparator;
 
 public final class ProcStatsEntry implements Parcelable {
+
     private static final String TAG = "ProcStatsEntry";
     private static boolean DEBUG = ProcessStatsUi.DEBUG;
 
@@ -40,7 +42,7 @@
     final int mUid;
     final String mName;
     public CharSequence mLabel;
-    final ArrayList<String> mPackages = new ArrayList<String>();
+    final ArrayList<String> mPackages = new ArrayList<>();
     final long mBgDuration;
     final long mAvgBgMem;
     final long mMaxBgMem;
@@ -52,7 +54,7 @@
 
     String mBestTargetPackage;
 
-    ArrayMap<String, ArrayList<Service>> mServices = new ArrayMap<String, ArrayList<Service>>(1);
+    ArrayMap<String, ArrayList<Service>> mServices = new ArrayMap<>(1);
 
     public ProcStatsEntry(ProcessState proc, String packageName,
             ProcessStats.ProcessDataCollection tmpBgTotals,
@@ -249,6 +251,10 @@
                             + " not as good as last " + bestRunTime);
                 }
             }
+            // Final fallback, just pick the first subProc.
+            if (TextUtils.isEmpty(mBestTargetPackage)) {
+                mBestTargetPackage = subProcs.get(0).mPackage;
+            }
         } else if (subProcs.size() == 1) {
             mBestTargetPackage = subProcs.get(0).mPackage;
         }
diff --git a/src/com/android/settings/dashboard/DashboardContainerFragment.java b/src/com/android/settings/dashboard/DashboardContainerFragment.java
index 4268b81..cd42f7d 100644
--- a/src/com/android/settings/dashboard/DashboardContainerFragment.java
+++ b/src/com/android/settings/dashboard/DashboardContainerFragment.java
@@ -22,6 +22,7 @@
 import android.content.Context;
 import android.os.Bundle;
 import android.support.v13.app.FragmentPagerAdapter;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -42,6 +43,10 @@
  */
 public final class DashboardContainerFragment extends InstrumentedFragment {
 
+    public static final String EXTRA_SELECT_SETTINGS_TAB = ":settings:select_settings_tab";
+
+    private static final String ARG_SUPPORT_TAB = "SUPPORT";
+    private static final String ARG_SUMMARY_TAB = "SUMMARY";
     private static final int INDEX_SUMMARY_FRAGMENT = 0;
     private static final int INDEX_SUPPORT_FRAGMENT = 1;
 
@@ -69,7 +74,16 @@
         mViewPager.setAdapter(mPagerAdapter);
         mViewPager.addOnPageChangeListener(
                 new TabChangeListener((SettingsActivity) getActivity()));
-        mViewPager.setCurrentItem(INDEX_SUMMARY_FRAGMENT);
+
+        // check if support tab needs to be selected
+        final String selectedTab = getArguments().
+            getString(EXTRA_SELECT_SETTINGS_TAB, ARG_SUMMARY_TAB);
+        if (TextUtils.equals(selectedTab, ARG_SUPPORT_TAB)) {
+            mViewPager.setCurrentItem(INDEX_SUPPORT_FRAGMENT);
+        } else {
+            mViewPager.setCurrentItem(INDEX_SUMMARY_FRAGMENT);
+        }
+
         mHeaderView = inflater.inflate(R.layout.dashboard_container_header, parent, false);
         ((SlidingTabLayout) mHeaderView).setViewPager(mViewPager);
         return content;
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index b5c130c..9ef69883 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -20,6 +20,7 @@
 import android.annotation.LayoutRes;
 import android.annotation.StringRes;
 import android.app.Activity;
+import android.app.ActivityManager;
 import android.app.DialogFragment;
 import android.content.Context;
 import android.content.Intent;
@@ -372,6 +373,13 @@
         } else {
             holder.text2View.setVisibility(View.GONE);
         }
+
+        if (ActivityManager.isUserAMonkey()) {
+            holder.text1View.setVisibility(View.GONE);
+            holder.text2View.setVisibility(View.GONE);
+            spinner.setVisibility(View.GONE);
+            holder.itemView.findViewById(R.id.support_text).setVisibility(View.GONE);
+        }
     }
 
     private void bindSignInPromoTile(ViewHolder holder, EscalationData data) {
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
index 51fd132..a16de50 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionAdapterUtils.java
@@ -68,12 +68,13 @@
         card.setOnClickListener(onClickListener);
         view.icon.setImageIcon(condition.getIcon());
         view.title.setText(condition.getTitle());
-        ImageView expand = (ImageView) view.itemView.findViewById(R.id.expand_indicator);
-        expand.setTag(condition);
+        final View collapsedGroup = view.itemView.findViewById(R.id.collapsed_group);
+        collapsedGroup.setTag(condition);
+        final ImageView expand = (ImageView) view.itemView.findViewById(R.id.expand_indicator);
         expand.setImageResource(isExpanded ? R.drawable.ic_expand_less : R.drawable.ic_expand_more);
         expand.setContentDescription(expand.getContext().getString(isExpanded
                 ? R.string.condition_expand_hide : R.string.condition_expand_show));
-        expand.setOnClickListener(onExpandListener);
+        collapsedGroup.setOnClickListener(onExpandListener);
 
         View detailGroup = view.itemView.findViewById(R.id.detail_group);
         CharSequence[] actions = condition.getActions();
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index e9aa8c9..482703b 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -198,10 +198,16 @@
             final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
 
             if (bytes > 1.5f * GB_IN_BYTES) {
-                bytesPicker.setText(formatText(bytes / (float) GB_IN_BYTES));
+                final String bytesText = formatText(bytes / (float) GB_IN_BYTES);
+                bytesPicker.setText(bytesText);
+                bytesPicker.setSelection(0, bytesText.length());
+
                 type.setSelection(1);
             } else {
-                bytesPicker.setText(formatText(bytes / (float) MB_IN_BYTES));
+                final String bytesText = formatText(bytes / (float) MB_IN_BYTES);
+                bytesPicker.setText(bytesText);
+                bytesPicker.setSelection(0, bytesText.length());
+
                 type.setSelection(0);
             }
         }
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 532c720..ee68311 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -58,6 +58,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 
@@ -165,17 +166,14 @@
 
         for (VolumeInfo vol : volumes) {
             if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
+                final long volumeTotalBytes = getTotalSize(vol);
                 final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
                 mInternalCategory.addPreference(
-                        new StorageVolumePreference(context, vol, color, sTotalInternalStorage));
+                        new StorageVolumePreference(context, vol, color, volumeTotalBytes));
                 if (vol.isMountedReadable()) {
                     final File path = vol.getPath();
-                    privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
-                    if (sTotalInternalStorage > 0) {
-                        privateTotalBytes = sTotalInternalStorage;
-                    } else {
-                        privateTotalBytes += path.getTotalSpace();
-                    }
+                    privateUsedBytes += (volumeTotalBytes - path.getFreeSpace());
+                    privateTotalBytes += volumeTotalBytes;
                 }
             } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
                 mExternalCategory.addPreference(
@@ -277,7 +275,7 @@
             if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
                 final Bundle args = new Bundle();
                 args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
-                PrivateVolumeSettings.setVolumeSize(args, sTotalInternalStorage);
+                PrivateVolumeSettings.setVolumeSize(args, getTotalSize(vol));
                 startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
                         -1, 0, args);
                 return true;
@@ -495,19 +493,11 @@
             long privateFreeBytes = 0;
             long privateTotalBytes = 0;
             for (VolumeInfo info : volumes) {
-                if (info.getType() != VolumeInfo.TYPE_PUBLIC
-                        && info.getType() != VolumeInfo.TYPE_PRIVATE) {
-                    continue;
-                }
                 final File path = info.getPath();
-                if (path == null) {
+                if (info.getType() != VolumeInfo.TYPE_PRIVATE || path == null) {
                     continue;
                 }
-                if (info.getType() == VolumeInfo.TYPE_PRIVATE && sTotalInternalStorage > 0) {
-                    privateTotalBytes = sTotalInternalStorage;
-                } else {
-                    privateTotalBytes += path.getTotalSpace();
-                }
+                privateTotalBytes += getTotalSize(info);
                 privateFreeBytes += path.getFreeSpace();
             }
             long privateUsedBytes = privateTotalBytes - privateFreeBytes;
@@ -517,6 +507,27 @@
         }
     }
 
+    private static long getTotalSize(VolumeInfo info) {
+        // Device could have more than one primary storage, which could be located in the
+        // internal flash (UUID_PRIVATE_INTERNAL) or in an external disk.
+        // If it's internal, try to get its total size from StorageManager first
+        // (sTotalInternalStorage), since that size is more precise because it accounts for
+        // the system partition.
+        if (info.getType() == VolumeInfo.TYPE_PRIVATE
+                && Objects.equals(info.getFsUuid(), StorageManager.UUID_PRIVATE_INTERNAL)
+                && sTotalInternalStorage > 0) {
+            return sTotalInternalStorage;
+        } else {
+            final File path = info.getPath();
+            if (path == null) {
+                // Should not happen, caller should have checked.
+                Log.e(TAG, "info's path is null on getTotalSize(): " + info);
+                return 0;
+            }
+            return path.getTotalSpace();
+        }
+    }
+
     public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
             = new SummaryLoader.SummaryProviderFactory() {
         @Override
diff --git a/src/com/android/settings/fuelgauge/BatterySaverSettings.java b/src/com/android/settings/fuelgauge/BatterySaverSettings.java
index bd19db8..e19f683 100644
--- a/src/com/android/settings/fuelgauge/BatterySaverSettings.java
+++ b/src/com/android/settings/fuelgauge/BatterySaverSettings.java
@@ -25,6 +25,7 @@
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.AsyncTask;
+import android.os.BatteryManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.PowerManager;
@@ -186,23 +187,36 @@
     };
 
     private final class Receiver extends BroadcastReceiver {
+
         private boolean mRegistered;
 
         @Override
         public void onReceive(Context context, Intent intent) {
             if (DEBUG) Log.d(TAG, "Received " + intent.getAction());
-            mHandler.post(mUpdateSwitch);
+            String action = intent.getAction();
+            if (action.equals(ACTION_POWER_SAVE_MODE_CHANGING)) {
+                mHandler.post(mUpdateSwitch);
+            } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
+                final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+                // disable BSM switch if phone is plugged in or at 100% while plugged in
+                mSwitchBar.setEnabled(
+                        !(status == BatteryManager.BATTERY_STATUS_CHARGING
+                                || status == BatteryManager.BATTERY_STATUS_FULL));
+            }
         }
-
         public void setListening(boolean listening) {
             if (listening && !mRegistered) {
-                mContext.registerReceiver(this, new IntentFilter(ACTION_POWER_SAVE_MODE_CHANGING));
+                final IntentFilter ifilter = new IntentFilter();
+                ifilter.addAction(ACTION_POWER_SAVE_MODE_CHANGING);
+                ifilter.addAction(Intent.ACTION_BATTERY_CHANGED);
+                mContext.registerReceiver(this, ifilter);
                 mRegistered = true;
             } else if (!listening && mRegistered) {
                 mContext.unregisterReceiver(this);
                 mRegistered = false;
             }
         }
+
     }
 
     private final class SettingsObserver extends ContentObserver {
diff --git a/src/com/android/settings/wifi/LongPressAccessPointPreference.java b/src/com/android/settings/wifi/LongPressAccessPointPreference.java
index 46746cb..79f29ef 100644
--- a/src/com/android/settings/wifi/LongPressAccessPointPreference.java
+++ b/src/com/android/settings/wifi/LongPressAccessPointPreference.java
@@ -17,21 +17,8 @@
 
 import android.app.Fragment;
 import android.content.Context;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.StateListDrawable;
-import android.net.wifi.WifiConfiguration;
-import android.os.Looper;
-import android.os.UserHandle;
-import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
-import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.util.SparseArray;
-import android.view.View;
-import android.widget.TextView;
-
-import com.android.settings.R;
 import com.android.settingslib.wifi.AccessPoint;
 import com.android.settingslib.wifi.AccessPointPreference;
 
@@ -51,6 +38,12 @@
         mFragment = fragment;
     }
 
+    public LongPressAccessPointPreference(AccessPoint accessPoint, Context context,
+            UserBadgeCache cache, boolean forSavedNetworks, int iconResId, Fragment fragment) {
+        super(accessPoint, context, cache, iconResId, forSavedNetworks);
+        mFragment = fragment;
+    }
+
     @Override
     public void onBindViewHolder(final PreferenceViewHolder view) {
         super.onBindViewHolder(view);
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 8eb1759..1ce214b 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -71,7 +71,6 @@
 import com.android.settingslib.wifi.AccessPointPreference;
 import com.android.settingslib.wifi.WifiStatusTracker;
 import com.android.settingslib.wifi.WifiTracker;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -630,10 +629,10 @@
                         }
                         LongPressAccessPointPreference
                                 preference = new LongPressAccessPointPreference(accessPoint,
-                                getPrefContext(), mUserBadgeCache, false, this);
+                                getPrefContext(), mUserBadgeCache, false,
+                                R.drawable.ic_wifi_signal_0, this);
                         preference.setKey(key);
                         preference.setOrder(index++);
-
                         if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
                                 && !accessPoint.isSaved()
                                 && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
@@ -642,6 +641,7 @@
                         }
                         getPreferenceScreen().addPreference(preference);
                         accessPoint.setListener(this);
+                        preference.refresh();
                     }
                 }
                 removeCachedPrefs(getPreferenceScreen());
diff --git a/tests/app/Android.mk b/tests/app/Android.mk
index bb31539..cd13384 100644
--- a/tests/app/Android.mk
+++ b/tests/app/Android.mk
@@ -7,6 +7,11 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner bouncycastle
 
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-test \
+    mockito-target \
+    espresso-core
+
 # Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/app/AndroidManifest.xml b/tests/app/AndroidManifest.xml
index 2ef96cf..1c50700 100644
--- a/tests/app/AndroidManifest.xml
+++ b/tests/app/AndroidManifest.xml
@@ -51,9 +51,9 @@
         </activity>
     </application>
 
-    <instrumentation android:name="android.test.InstrumentationTestRunner"
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
         android:targetPackage="com.android.settings"
-        android:label="Settings App Tests">
+        android:label="Settings Test Cases">
     </instrumentation>
 
     <instrumentation android:name="SettingsLaunchPerformance"
diff --git a/tests/app/src/com/android/settings/dashboard/TabSelectionOnLaunchTest.java b/tests/app/src/com/android/settings/dashboard/TabSelectionOnLaunchTest.java
new file mode 100644
index 0000000..24c1ead
--- /dev/null
+++ b/tests/app/src/com/android/settings/dashboard/TabSelectionOnLaunchTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.
+ */
+package com.android.settings.dashboard;
+
+import android.content.Intent;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+import com.android.settings.Settings;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.isSelected;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+import static org.hamcrest.core.IsNot.not;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class TabSelectionOnLaunchTest {
+    @Rule
+    public ActivityTestRule<Settings> mActivityRule =
+            new ActivityTestRule<>(Settings.class, true, false);
+
+    private final int FLAG_RESTART = Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK;
+    private final String ARG_SELECT_SUPPORT_TAB = "SUPPORT";
+    private final String ARG_SELECT_FAKE_TAB = "NOT_SUPPORT";
+
+    @Test
+    /* cold start for settings app with correct flags and extra always selects support tab */
+    public void test_ColdStartWithCorrectArgsCorrectFlags_SupportSelected() {
+        launchSettingsWithFlags(ARG_SELECT_SUPPORT_TAB, FLAG_RESTART);
+        verifySupportSelected();
+    }
+
+    @Test
+    /* cold start with correct flags and wrong extra defaults to all tab */
+    public void test_ColdStartWithWrongExtra_DoesNotSelectSupport() {
+        launchSettingsWithFlags(ARG_SELECT_FAKE_TAB, FLAG_RESTART);
+        verifySupportNotSelected();
+    }
+
+    @Test
+    /* warm start from elsewhere in settings with wrong flags does not select support */
+    public void test_WarmStartSummarySelectedCorrectExtraWrongFlags_DoesNotSelectSupport() {
+        InstrumentationRegistry.getContext().
+                startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
+        launchSettingsNoFlags(ARG_SELECT_SUPPORT_TAB);
+        verifySupportNotSelected();
+    }
+
+    @Test
+    /* warm start from elsewhere in settings with with wrong flags & extra does not select support*/
+    public void test_WarmStartSummarySelectedWrongExtraWrongFlags_DoesNotSelectSupport() {
+        InstrumentationRegistry.getContext().
+                startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
+        launchSettingsNoFlags(ARG_SELECT_FAKE_TAB);
+        verifySupportNotSelected();
+    }
+
+    @Test
+    /* settings does not crash on null string */
+    public void test_DoesNotCrashOnNullExtra_DoesNotSelectSupport() {
+        launchSettingsWithFlags(null, FLAG_RESTART);
+        verifySupportNotSelected();
+    }
+
+    private void verifySupportNotSelected() {
+        onView(withText(mActivityRule.getActivity().getApplicationContext().
+                getString(com.android.settings.R.string.page_tab_title_support))).
+                check(matches(not(isSelected())));
+    }
+
+    private void verifySupportSelected() {
+        onView(withText(mActivityRule.getActivity().getApplicationContext().
+                getString(com.android.settings.R.string.page_tab_title_support))).
+                check(matches(isSelected()));
+    }
+
+    private void launchSettingsWithFlags(String extra, int flags) {
+        Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
+        intent.setFlags(flags);
+        intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra);
+        mActivityRule.launchActivity(intent);
+    }
+
+    private void launchSettingsNoFlags(String extra) {
+        Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
+        intent.putExtra(DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB, extra);
+        mActivityRule.launchActivity(intent);
+    }
+}
\ No newline at end of file
diff --git a/tests/unit/Android.mk b/tests/unit/Android.mk
index 3ba4606..5b20173 100644
--- a/tests/unit/Android.mk
+++ b/tests/unit/Android.mk
@@ -7,7 +7,10 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test mockito-target
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-test \
+    mockito-target \
+    espresso-core
 
 # Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)