Merge "Change wifi detail buttons to match App buttons."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4e75bf6..c73c909 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2496,11 +2496,6 @@
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter android:priority="10">
-                <action android:name="com.android.settings.action.SETTINGS" />
-            </intent-filter>
-            <meta-data android:name="com.android.settings.category"
-                android:value="com.android.settings.category.ia.apps.default" />
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.nfc.PaymentSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -3001,7 +2996,7 @@
             <meta-data android:name="com.android.settings.category"
                        android:value="com.android.settings.category.ia.apps"/>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
-                       android:value="com.android.settings.applications.AdvancedAppSettings" />
+                       android:value="com.android.settings.applications.DefaultAppSettings" />
             <meta-data android:name="com.android.settings.summary"
                        android:resource="@string/summary_empty"/>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
diff --git a/res/layout/data_plans_sync_time_preference.xml b/res/layout/data_plans_sync_time_preference.xml
new file mode 100644
index 0000000..bb9da90
--- /dev/null
+++ b/res/layout/data_plans_sync_time_preference.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2017 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.
+-->
+
+<!-- Shows the data plans sync time -->
+<TextView
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@android:id/title"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingStart="@dimen/preference_no_icon_padding_start"
+        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+        android:gravity="end"
+        android:textColor="?android:attr/textColorSecondary"/>
diff --git a/res/layout/data_usage_bytes_editor.xml b/res/layout/data_usage_bytes_editor.xml
index 2878c3e..af2d59b 100644
--- a/res/layout/data_usage_bytes_editor.xml
+++ b/res/layout/data_usage_bytes_editor.xml
@@ -37,7 +37,6 @@
         android:id="@+id/size_spinner"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical"
-        android:entries="@array/bytes_picker_sizes" />
+        android:layout_gravity="center_vertical" />
 
 </LinearLayout>
diff --git a/res/layout/manage_data_plans_preference.xml b/res/layout/manage_data_plans_preference.xml
new file mode 100644
index 0000000..1686d3f
--- /dev/null
+++ b/res/layout/manage_data_plans_preference.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2017 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.
+-->
+
+<FrameLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:paddingStart="@dimen/preference_no_icon_padding_start"
+        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+        android:paddingTop="8dp"
+        android:paddingBottom="16dp">
+    <Button
+            android:id="@+id/manage_data_plans"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/data_plan_usage_manage_plans_button_text"
+            android:textAllCaps="true"
+            style="@style/AppActionPrimaryButton" />
+</FrameLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 95e6e18..df2168d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1971,6 +1971,8 @@
     <string name="wifi_advanced_ip_address_title">IP address</string>
 
     <!-- Wifi Network Details -->
+    <!-- Wifi details title-->
+    <string name="wifi_details_title">Network info</string>
     <!-- Wifi details preference title to display router IP subnet mask -->
     <string name="wifi_details_subnet_mask">Subnet mask</string>
     <!-- Wifi details preference title to display router DNS info -->
@@ -4686,7 +4688,7 @@
     <!-- Text for OK button in force stop dialog [CHAR LIMIT=30] -->
     <string name="dialog_stop_ok">Stop app</string>
 
-    <!-- Title for background usage dialog [CHAR LIMIT=60] -->
+    <!-- Title for background usage dialog [CHAR LIMIT=70] -->
     <string name="dialog_background_check_title">Turn off background usage &amp; stop app?</string>
     <!-- Message body for background usage dialog [CHAR LIMIT=NONE] -->
     <string name="dialog_background_check_message" product="default">Your phone can\'t manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps waking up your phone.\n\nTo try to fix this issue, you can stop <xliff:g id="app">%1$s</xliff:g> and prevent it from running in the background.</string>
@@ -5526,6 +5528,9 @@
     <!--  action to select all [CHAR LIMIT=30] -->
     <string name="select_all">Select all</string>
 
+    <!-- A button that gets displayed in data plan usage preference in settings page to manage data plans [CHAR LIMIT=25] -->
+    <string name="data_plan_usage_manage_plans_button_text">Manage plans</string>
+
     <!-- Activity title for network data usage summary. [CHAR LIMIT=25] -->
     <string name="data_usage_summary_title">Data usage</string>
     <!-- Activity title for Appk data usage summary. [CHAR LIMIT=25] -->
@@ -5715,6 +5720,13 @@
     <!-- Body text prompting user to enable Wi-Fi to configure metered networks. [CHAR LIMIT=64] -->
     <string name="data_usage_metered_wifi_disabled">To select metered networks, turn Wi\u2011Fi on.</string>
 
+    <!-- Option for indicating that a network being metered (expensive) should be determined automatically. [CHAR LIMIT=32] -->
+    <string name="data_usage_metered_auto">Automatic</string>
+    <!-- Option for indicating that a network is metered (expensive). [CHAR LIMIT=32] -->
+    <string name="data_usage_metered_yes">Metered</string>
+    <!-- Option for indicating that a network is not metered (inexpensive). [CHAR LIMIT=32] -->
+    <string name="data_usage_metered_no">Not metered</string>
+
     <!-- Disclaimer string for data usage measured by device. [CHAR LIMIT=80] -->
     <string name="data_usage_disclaimer">Carrier data accounting may differ from your device.</string>
 
@@ -8328,11 +8340,6 @@
     <!-- Text for the setting on whether you can type text into notifications without unlocking the device. -->
     <string name="lockscreen_remote_input">If device is locked, prevent typing replies or other text in notifications</string>
 
-    <string-array name="bytes_picker_sizes" translatable="false">
-        <item>@*android:string/megabyteShort</item>
-        <item>@*android:string/gigabyteShort</item>
-    </string-array>
-
     <!-- [CHAR LIMIT=30] Label for setting to control the default spell checker -->
     <string name="default_spell_checker">Default spell checker</string>
 
diff --git a/res/xml/app_default_settings.xml b/res/xml/app_default_settings.xml
index 11acb24..196ed9f 100644
--- a/res/xml/app_default_settings.xml
+++ b/res/xml/app_default_settings.xml
@@ -23,56 +23,56 @@
     <Preference
         android:key="assist_and_voice_input"
         android:title="@string/assist_and_voice_input_title"
-        android:fragment="com.android.settings.applications.assist.ManageAssist"
-        android:order="-20"/>
+        android:fragment="com.android.settings.applications.assist.ManageAssist" />
 
     <Preference
         android:key="default_browser"
         android:title="@string/default_browser_title"
-        android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker"
-        android:order="-19">
-        <extra android:name="for_work" android:value="false"/>
+        android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker">
+        <extra android:name="for_work" android:value="false" />
     </Preference>
 
     <Preference
         android:key="default_home"
         android:title="@string/home_app"
         android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
-        settings:keywords="@string/keywords_home"
-        android:order="-18"/>
+        settings:keywords="@string/keywords_home" />
 
     <Preference
         android:key="default_phone_app"
         android:title="@string/default_phone_title"
         android:fragment="com.android.settings.applications.defaultapps.DefaultPhonePicker"
-        settings:keywords="@string/keywords_default_phone_app"
-        android:order="-17"/>
+        settings:keywords="@string/keywords_default_phone_app" />
 
     <Preference
         android:key="default_sms_app"
         android:title="@string/sms_application_title"
         android:fragment="com.android.settings.applications.defaultapps.DefaultSmsPicker"
-        settings:keywords="@string/keywords_more_default_sms_app"
-        android:order="-16"/>
+        settings:keywords="@string/keywords_more_default_sms_app" />
+
+    <Preference
+        android:key="default_payment_app"
+        android:title="@string/nfc_payment_settings_title"
+        android:summary="@string/summary_placeholder"
+        android:fragment="com.android.settings.nfc.PaymentSettings" />
 
     <Preference
         android:key="default_emergency_app"
         android:title="@string/default_emergency_app"
-        settings:keywords="@string/keywords_emergency_app"
-        android:order="-15"/>
+        settings:keywords="@string/keywords_emergency_app" />
 
     <!--
     <Preference
         android:key="default_notification_asst_app"
         android:title="@string/default_notification_assistant"
         android:fragment="com.android.settings.applications.defaultapps.DefaultNotificationAssistantPicker"
-        android:order="-13"/>
+        />
      -->
 
     <Preference
         android:key="domain_urls"
         android:title="@string/domain_urls_title"
-        android:fragment="com.android.settings.applications.ManageDomainUrls"/>
+        android:fragment="com.android.settings.applications.ManageDomainUrls" />
 
     <com.android.settings.WorkOnlyCategory
         android:key="work_defaults"
@@ -82,7 +82,7 @@
             android:key="work_default_browser"
             android:title="@string/default_browser_title"
             android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker">
-            <extra android:name="for_work" android:value="true"/>
+            <extra android:name="for_work" android:value="true" />
         </Preference>
 
         <Preference
@@ -90,7 +90,7 @@
             android:title="@string/default_phone_title"
             android:fragment="com.android.settings.applications.defaultapps.DefaultPhonePicker"
             settings:keywords="@string/keywords_default_phone_app">
-            <extra android:name="for_work" android:value="true"/>
+            <extra android:name="for_work" android:value="true" />
         </Preference>
 
     </com.android.settings.WorkOnlyCategory>
diff --git a/res/xml/wifi_network_details_fragment.xml b/res/xml/wifi_network_details_fragment.xml
index 64e61b1..443cb88 100644
--- a/res/xml/wifi_network_details_fragment.xml
+++ b/res/xml/wifi_network_details_fragment.xml
@@ -14,9 +14,7 @@
      limitations under the License.
 -->
 
-<PreferenceScreen
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 
     <com.android.settings.applications.LayoutPreference
         android:key="connection_header"
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index dc4c995..fe0111b 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -247,9 +247,8 @@
     /**
      * Whether to show the checkbox to wipe the eUICC.
      *
-     * <p>We show the checkbox on any device which supports eUICC as long as either the eUICC was
-     * ever provisioned (that is, at least one profile was ever downloaded onto it), or if the user
-     * has enabled development mode.
+     * <p>We show the checkbox on any device which supports eUICC as long as the eUICC was ever
+     * provisioned (that is, at least one profile was ever downloaded onto it).
      */
     @VisibleForTesting
     boolean showWipeEuicc() {
@@ -258,8 +257,7 @@
             return false;
         }
         ContentResolver cr = context.getContentResolver();
-        return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0
-                || Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+        return Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index a7d9afc..225c5ea 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -813,13 +813,6 @@
                         Settings.DateTimeSettingsActivity.class.getName()),
                 !UserManager.isDeviceInDemoMode(this), isAdmin)
                 || somethingChanged;
-        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
-        somethingChanged = setTileEnabled(new ComponentName(packageName,
-                        Settings.PaymentSettingsActivity.class.getName()),
-                pm.hasSystemFeature(PackageManager.FEATURE_NFC)
-                        && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
-                        && adapter != null && adapter.isEnabled(), isAdmin)
-                || somethingChanged;
 
         somethingChanged = setTileEnabled(new ComponentName(packageName,
                         Settings.PrintSettingsActivity.class.getName()),
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index dda55e4..c3acccd 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -50,7 +50,7 @@
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
-        mProgressiveDisclosureMixin.setTileLimit(2);
+        mProgressiveDisclosureMixin.setTileLimit(3);
     }
 
     @Override
diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/DefaultAppSettings.java
similarity index 90%
rename from src/com/android/settings/applications/AdvancedAppSettings.java
rename to src/com/android/settings/applications/DefaultAppSettings.java
index a237bb8..5b15e51 100644
--- a/src/com/android/settings/applications/AdvancedAppSettings.java
+++ b/src/com/android/settings/applications/DefaultAppSettings.java
@@ -22,6 +22,7 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
+import com.android.settings.applications.assist.DefaultAssistPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
@@ -29,6 +30,7 @@
 import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultWorkBrowserPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultWorkPhonePreferenceController;
+import com.android.settings.applications.defaultapps.DefaultPaymentSettingsPreferenceController;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -39,9 +41,9 @@
 import java.util.Arrays;
 import java.util.List;
 
-public class AdvancedAppSettings extends DashboardFragment {
+public class DefaultAppSettings extends DashboardFragment {
 
-    static final String TAG = "AdvancedAppSettings";
+    static final String TAG = "DefaultAppSettings";
 
     private static final String KEY_ASSIST_VOICE_INPUT = "assist_and_voice_input";
 
@@ -67,6 +69,8 @@
 
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
+        controllers.add(new DefaultAssistPreferenceController(context, KEY_ASSIST_VOICE_INPUT,
+                false /* showSetting */));
         controllers.add(new DefaultBrowserPreferenceController(context));
         controllers.add(new DefaultWorkBrowserPreferenceController(context));
         controllers.add(new DefaultPhonePreferenceController(context));
@@ -74,6 +78,7 @@
         controllers.add(new DefaultSmsPreferenceController(context));
         controllers.add(new DefaultEmergencyPreferenceController(context));
         controllers.add(new DefaultHomePreferenceController(context));
+        controllers.add(new DefaultPaymentSettingsPreferenceController(context));
         return controllers;
     }
 
@@ -100,7 +105,8 @@
                 }
 
                 @Override
-                public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+                public List<AbstractPreferenceController> getPreferenceControllers(
+                        Context context) {
                     return buildPreferenceControllers(context);
                 }
             };
@@ -152,7 +158,7 @@
                 @Override
                 public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
                         SummaryLoader summaryLoader) {
-                    return new AdvancedAppSettings.SummaryProvider(activity, summaryLoader);
+                    return new DefaultAppSettings.SummaryProvider(activity, summaryLoader);
                 }
             };
 }
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index d12fcf8..aca04cb 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -16,6 +16,8 @@
 
 package com.android.settings.applications;
 
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
 import android.Manifest.permission;
 import android.app.Activity;
 import android.app.ActivityManager;
@@ -83,6 +85,7 @@
 import com.android.settings.datausage.AppDataUsage;
 import com.android.settings.datausage.DataUsageList;
 import com.android.settings.datausage.DataUsageSummary;
+import com.android.settings.development.DevelopmentSettingsEnabler;
 import com.android.settings.fuelgauge.AdvancedPowerUsageDetail;
 import com.android.settings.fuelgauge.BatteryEntry;
 import com.android.settings.fuelgauge.BatteryStatsHelperLoader;
@@ -109,8 +112,6 @@
 import java.util.List;
 import java.util.Set;
 
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
 /**
  * Activity to display application information from Settings. This activity presents
  * extended information associated with a package like code, data, total size, permissions
@@ -176,7 +177,7 @@
     private Preference mMemoryPreference;
     private Preference mVersionPreference;
     private AppDomainsPreference mInstantAppDomainsPreference;
-
+    private DevelopmentSettingsEnabler mDevelopmentSettingsEnabler;
     private boolean mDisableAfterUninstall;
 
     // Used for updating notification preference.
@@ -376,6 +377,7 @@
 
         setHasOptionsMenu(true);
         addPreferencesFromResource(R.xml.installed_app_details);
+
         addDynamicPrefs();
         if (Utils.isBandwidthControlEnabled()) {
             INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
@@ -389,6 +391,8 @@
             removePreference(KEY_DATA);
         }
         mBatteryUtils = BatteryUtils.getInstance(getContext());
+        mDevelopmentSettingsEnabler = new DevelopmentSettingsEnabler(
+                activity, null /* lifecycle */);
     }
 
     @Override
@@ -412,7 +416,9 @@
             loaderManager.restartLoader(LOADER_STORAGE, Bundle.EMPTY, this);
         }
         restartBatteryStatsLoader();
-        new MemoryUpdater().execute();
+        if (mDevelopmentSettingsEnabler.getLastEnabledState()) {
+            new MemoryUpdater().execute();
+        }
         updateDynamicPrefs();
     }
 
@@ -466,6 +472,7 @@
         mBatteryPreference.setOnPreferenceClickListener(this);
         mMemoryPreference = findPreference(KEY_MEMORY);
         mMemoryPreference.setOnPreferenceClickListener(this);
+        mMemoryPreference.setVisible(mDevelopmentSettingsEnabler.getLastEnabledState());
         mVersionPreference = findPreference(KEY_VERSION);
         mInstantAppDomainsPreference =
                 (AppDomainsPreference) findPreference(KEY_INSTANT_APP_SUPPORTED_LINKS);
@@ -1070,27 +1077,27 @@
         final Context context = getContext();
         if (DefaultHomePreferenceController.hasHomePreference(mPackageName, context)) {
             screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    AdvancedAppSettings.class, "default_home", R.string.home_app,
+                    DefaultAppSettings.class, "default_home", R.string.home_app,
                     R.string.configure_apps));
         }
         if (DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, context)) {
             screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    AdvancedAppSettings.class, "default_browser", R.string.default_browser_title,
+                    DefaultAppSettings.class, "default_browser", R.string.default_browser_title,
                     R.string.configure_apps));
         }
         if (DefaultPhonePreferenceController.hasPhonePreference(mPackageName, context)) {
             screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    AdvancedAppSettings.class, "default_phone_app", R.string.default_phone_title,
+                    DefaultAppSettings.class, "default_phone_app", R.string.default_phone_title,
                     R.string.configure_apps));
         }
         if (DefaultEmergencyPreferenceController.hasEmergencyPreference(mPackageName, context)) {
             screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    AdvancedAppSettings.class, "default_emergency_app",
+                    DefaultAppSettings.class, "default_emergency_app",
                     R.string.default_emergency_app, R.string.configure_apps));
         }
         if (DefaultSmsPreferenceController.hasSmsPreference(mPackageName, context)) {
             screen.addPreference(new ShortcutPreference(getPrefContext(),
-                    AdvancedAppSettings.class, "default_sms_app", R.string.sms_application_title,
+                    DefaultAppSettings.class, "default_sms_app", R.string.sms_application_title,
                     R.string.configure_apps));
         }
 
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 454241a..7cc47e0 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -688,7 +688,7 @@
                             ADVANCED_SETTINGS);
                 } else {
                     ((SettingsActivity) getActivity()).startPreferencePanel(this,
-                            AdvancedAppSettings.class.getName(), null, R.string.configure_apps,
+                            DefaultAppSettings.class.getName(), null, R.string.configure_apps,
                             null, this, ADVANCED_SETTINGS);
                 }
                 return true;
diff --git a/src/com/android/settings/applications/SpacePreference.java b/src/com/android/settings/applications/SpacePreference.java
index 58a1dce..797bc92 100644
--- a/src/com/android/settings/applications/SpacePreference.java
+++ b/src/com/android/settings/applications/SpacePreference.java
@@ -22,7 +22,6 @@
 import android.support.v7.preference.PreferenceViewHolder;
 import android.util.AttributeSet;
 import android.view.ViewGroup.LayoutParams;
-
 import com.android.settings.R;
 
 /**
@@ -50,6 +49,7 @@
         final TypedArray a = context.obtainStyledAttributes(attrs,
                 new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes);
         mHeight = a.getDimensionPixelSize(0, 0);
+        a.recycle();
     }
 
     public void setHeight(int height) {
diff --git a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
index b8d6a87..7520155 100644
--- a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
+++ b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
@@ -23,8 +23,8 @@
 import android.content.pm.ResolveInfo;
 import android.service.voice.VoiceInteractionService;
 import android.service.voice.VoiceInteractionServiceInfo;
-
 import android.support.annotation.VisibleForTesting;
+
 import com.android.internal.app.AssistUtils;
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
 import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
@@ -33,17 +33,23 @@
 
 public class DefaultAssistPreferenceController extends DefaultAppPreferenceController {
 
-    private static final String KEY_DEFAULT_ASSIST = "default_assist";
+    private final AssistUtils mAssistUtils;
+    private final boolean mShowSetting;
+    private final String mPrefKey;
 
-    private AssistUtils mAssistUtils;
-
-    public DefaultAssistPreferenceController(Context context) {
+    public DefaultAssistPreferenceController(Context context, String prefKey,
+            boolean showSetting) {
         super(context);
+        mPrefKey = prefKey;
+        mShowSetting = showSetting;
         mAssistUtils = new AssistUtils(context);
     }
 
     @Override
     protected Intent getSettingIntent(DefaultAppInfo info) {
+        if (!mShowSetting) {
+            return null;
+        }
         final ComponentName cn = mAssistUtils.getAssistComponentForUser(mUserId);
         if (cn == null) {
             return null;
@@ -72,7 +78,7 @@
 
     @Override
     public String getPreferenceKey() {
-        return KEY_DEFAULT_ASSIST;
+        return mPrefKey;
     }
 
     @Override
diff --git a/src/com/android/settings/applications/assist/ManageAssist.java b/src/com/android/settings/applications/assist/ManageAssist.java
index a34d3f1..eb14ea1 100644
--- a/src/com/android/settings/applications/assist/ManageAssist.java
+++ b/src/com/android/settings/applications/assist/ManageAssist.java
@@ -71,7 +71,8 @@
     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
             Lifecycle lifecycle) {
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
-        controllers.add(new DefaultAssistPreferenceController(context));
+        controllers.add(new DefaultAssistPreferenceController(context, "default_assist",
+                true /* showSetting */));
         controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST,
                 true /* assistOnly */));
         controllers.add(new AssistContextPreferenceController(context, lifecycle));
@@ -81,7 +82,6 @@
         return controllers;
     }
 
-
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
                 @Override
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java b/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
index b40943f..12470eb 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppInfo.java
@@ -18,7 +18,6 @@
 
 import android.app.AppGlobals;
 import android.content.ComponentName;
-import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ComponentInfo;
 import android.content.pm.PackageItemInfo;
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
index 6b60abc..c7b450e 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAppPreferenceController.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
@@ -54,9 +55,11 @@
         CharSequence defaultAppLabel = getDefaultAppLabel();
         if (!TextUtils.isEmpty(defaultAppLabel)) {
             preference.setSummary(defaultAppLabel);
+            preference.setIcon(getDefaultAppIcon());
         } else {
             Log.d(TAG, "No default app");
             preference.setSummary(R.string.app_list_preference_none);
+            preference.setIcon(null);
         }
         mayUpdateGearIcon(app, preference);
     }
@@ -84,6 +87,17 @@
         return null;
     }
 
+    public Drawable getDefaultAppIcon() {
+        if (!isAvailable()) {
+            return null;
+        }
+        final DefaultAppInfo app = getDefaultAppInfo();
+        if (app != null) {
+            return app.loadIcon();
+        }
+        return null;
+    }
+
     public CharSequence getDefaultAppLabel() {
         if (!isAvailable()) {
             return null;
diff --git a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
index 219ce0f..a0bf0ca 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
@@ -21,6 +21,7 @@
 import android.content.pm.ComponentInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.support.v7.preference.Preference;
 import android.text.TextUtils;
@@ -86,6 +87,18 @@
         return getOnlyAppLabel();
     }
 
+    @Override
+    public Drawable getDefaultAppIcon() {
+        if (!isAvailable()) {
+            return null;
+        }
+        final DefaultAppInfo defaultApp = getDefaultAppInfo();
+        if (defaultApp != null) {
+            return defaultApp.loadIcon();
+        }
+        return getOnlyAppIcon();
+    }
+
     private List<ResolveInfo> getCandidates() {
         return mPackageManager.queryIntentActivitiesAsUser(BROWSE_PROBE, PackageManager.MATCH_ALL,
                 mUserId);
@@ -105,6 +118,18 @@
         return null;
     }
 
+    private Drawable getOnlyAppIcon() {
+        final List<ResolveInfo> list = getCandidates();
+        if (list != null && list.size() == 1) {
+            final ResolveInfo info = list.get(0);
+            final ComponentInfo cn = info.getComponentInfo();
+            final String packageName = cn == null ? null : cn.packageName;
+            Log.d(TAG, "Getting icon for the only browser app: " + packageName);
+            return info.loadIcon(mPackageManager.getPackageManager());
+        }
+        return null;
+    }
+
     /**
      * Whether or not the pkg contains browser capability
      */
diff --git a/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
index a89766f..88b36b2 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceController.java
@@ -23,8 +23,6 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.support.v7.preference.Preference;
-import android.text.TextUtils;
 
 import com.android.settings.applications.PackageManagerWrapper;
 
@@ -59,27 +57,20 @@
     }
 
     @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-        final DefaultAppInfo defaultApp = getDefaultAppInfo();
-        final CharSequence defaultAppLabel = defaultApp != null ? defaultApp.loadLabel() : null;
-        if (TextUtils.isEmpty(defaultAppLabel)) {
-            final String onlyAppLabel = getOnlyAppLabel();
-            if (!TextUtils.isEmpty(onlyAppLabel)) {
-                preference.setSummary(onlyAppLabel);
-            }
-        }
-    }
-
-    @Override
     protected DefaultAppInfo getDefaultAppInfo() {
         final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
         final ComponentName currentDefaultHome = mPackageManager.getHomeActivities(homeActivities);
-
-        return new DefaultAppInfo(mPackageManager, mUserId, currentDefaultHome);
+        if (currentDefaultHome != null) {
+            return new DefaultAppInfo(mPackageManager, mUserId, currentDefaultHome);
+        }
+        final ActivityInfo onlyAppInfo = getOnlyAppInfo();
+        if (onlyAppInfo != null) {
+            return new DefaultAppInfo(mPackageManager, mUserId, onlyAppInfo.getComponentName());
+        }
+        return null;
     }
 
-    private String getOnlyAppLabel() {
+    private ActivityInfo getOnlyAppInfo() {
         final List<ResolveInfo> homeActivities = new ArrayList<>();
         final List<ActivityInfo> appLabels = new ArrayList<>();
 
@@ -92,7 +83,7 @@
             appLabels.add(info);
         }
         return appLabels.size() == 1
-                ? appLabels.get(0).loadLabel(mPackageManager.getPackageManager()).toString()
+                ? appLabels.get(0)
                 : null;
     }
 
diff --git a/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceController.java
new file mode 100644
index 0000000..413e1d5
--- /dev/null
+++ b/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceController.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 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.applications.defaultapps;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.nfc.NfcAdapter;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.nfc.PaymentBackend;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class DefaultPaymentSettingsPreferenceController extends AbstractPreferenceController
+        implements PreferenceControllerMixin {
+
+    private final NfcAdapter mNfcAdapter;
+    private final PackageManager mPackageManager;
+    private final UserManager mUserManager;
+    private PaymentBackend mPaymentBackend;
+
+    public DefaultPaymentSettingsPreferenceController(Context context) {
+        super(context);
+        mPackageManager = context.getPackageManager();
+        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        mNfcAdapter = NfcAdapter.getDefaultAdapter(mContext);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC)
+                && mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
+                && mUserManager.isAdminUser()
+                && mNfcAdapter != null
+                && mNfcAdapter.isEnabled();
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        if (mPaymentBackend == null) {
+            if (mNfcAdapter != null) {
+                mPaymentBackend = new PaymentBackend(mContext);
+            } else {
+                mPaymentBackend = null;
+            }
+        }
+        if (mPaymentBackend == null) {
+            return;
+        }
+        mPaymentBackend.refresh();
+        final PaymentBackend.PaymentAppInfo app = mPaymentBackend.getDefaultApp();
+        if (app != null) {
+            preference.setSummary(app.label);
+        } else {
+            preference.setSummary(R.string.app_list_preference_none);
+        }
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return "default_payment_app";
+    }
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
index 6f9cf40..b64da26 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
@@ -21,6 +21,9 @@
 import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
 
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
@@ -30,11 +33,13 @@
     public static final String PREF_KEY = "bt_rename_device";
 
     private final Fragment mFragment;
+    private MetricsFeatureProvider mMetricsFeatureProvider;
 
     public BluetoothDeviceRenamePreferenceController(Context context, Fragment fragment,
             Lifecycle lifecycle) {
         super(context, lifecycle);
         mFragment = fragment;
+        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     }
 
     @VisibleForTesting
@@ -42,6 +47,7 @@
             LocalBluetoothAdapter localAdapter) {
         super(context, localAdapter);
         mFragment = fragment;
+        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     }
 
     @Override
@@ -57,6 +63,8 @@
     @Override
     public boolean handlePreferenceTreeClick(Preference preference) {
         if (PREF_KEY.equals(preference.getKey())) {
+            mMetricsFeatureProvider.action(mContext,
+                    MetricsProto.MetricsEvent.ACTION_BLUETOOTH_RENAME);
             LocalDeviceNameDialogFragment.newInstance()
                     .show(mFragment.getFragmentManager(), LocalDeviceNameDialogFragment.TAG);
             return true;
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 6c41f83..3d7c5b6 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -106,7 +106,7 @@
             mContext = context;
         }
 
-        maybeEnforceRestrictions();
+        final boolean restricted = maybeEnforceRestrictions();
 
         if (mLocalAdapter == null) {
             mSwitchWidget.setEnabled(false);
@@ -114,7 +114,9 @@
         }
 
         // Bluetooth state is not sticky, so set it manually
-        handleStateChanged(mLocalAdapter.getBluetoothState());
+        if (!restricted) {
+            handleStateChanged(mLocalAdapter.getBluetoothState());
+        }
 
         mSwitchWidget.startListening();
         mContext.registerReceiver(mReceiver, mIntentFilter);
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 273c313..9e664e5 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -31,7 +31,6 @@
 import com.android.settings.TestingSettings;
 import com.android.settings.TetherSettings;
 import com.android.settings.TrustedCredentialsSettings;
-import com.android.settings.UserDictionarySettings;
 import com.android.settings.WifiCallingSettings;
 import com.android.settings.accessibility.AccessibilitySettings;
 import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
@@ -41,7 +40,7 @@
 import com.android.settings.accounts.ChooseAccountActivity;
 import com.android.settings.accounts.ManagedProfileSettings;
 import com.android.settings.accounts.UserAndAccountDashboardFragment;
-import com.android.settings.applications.AdvancedAppSettings;
+import com.android.settings.applications.DefaultAppSettings;
 import com.android.settings.applications.AppAndNotificationDashboardFragment;
 import com.android.settings.applications.DrawOverlayDetails;
 import com.android.settings.applications.ExternalSourcesDetails;
@@ -91,6 +90,7 @@
 import com.android.settings.inputmethod.PhysicalKeyboardFragment;
 import com.android.settings.inputmethod.SpellCheckersSettings;
 import com.android.settings.inputmethod.UserDictionaryList;
+import com.android.settings.inputmethod.UserDictionarySettings;
 import com.android.settings.language.LanguageAndInputSettings;
 import com.android.settings.localepicker.LocaleListEditor;
 import com.android.settings.location.LocationSettings;
@@ -220,7 +220,7 @@
             DrawOverlayDetails.class.getName(),
             WriteSettingsDetails.class.getName(),
             ExternalSourcesDetails.class.getName(),
-            AdvancedAppSettings.class.getName(),
+            DefaultAppSettings.class.getName(),
             WallpaperTypeSettings.class.getName(),
             VrListenerSettings.class.getName(),
             PictureInPictureSettings.class.getName(),
@@ -254,7 +254,6 @@
     };
 
     public static final String[] SETTINGS_FOR_RESTRICTED = {
-            // New IA
             // Home page
             Settings.NetworkDashboardActivity.class.getName(),
             Settings.ConnectedDeviceDashboardActivity.class.getName(),
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 9e51486..f3374ff 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -62,9 +62,10 @@
     private static final String STATE_SUGGESTION_LIST = "suggestion_list";
     private static final String STATE_CATEGORY_LIST = "category_list";
     private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
-    private static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
 
     @VisibleForTesting
+    static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
+    @VisibleForTesting
     static final int SUGGESTION_CONDITION_HEADER_POSITION = 0;
 
     private final IconCache mCache;
@@ -421,8 +422,9 @@
             int position) {
         // If there is suggestions to show, it will be at position 0 as we don't show the suggestion
         // header anymore.
-        if (position == (SUGGESTION_CONDITION_HEADER_POSITION)
-                && mDashboardData.getSuggestions() != null) {
+        final List<Tile> suggestions = mDashboardData.getSuggestions();
+        if (position == SUGGESTION_CONDITION_HEADER_POSITION
+                && suggestions != null && suggestions.size() > 0) {
             mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
                 mDashboardData.getItemEntityByPosition(position), mSuggestionsShownLogged);
             mSuggestionDismissHandler = new SuggestionDismissController(mContext,
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index 7c8c8f1..fddd522 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -22,8 +22,8 @@
 import com.android.settings.SecuritySettings;
 import com.android.settings.accounts.AccountDetailDashboardFragment;
 import com.android.settings.accounts.UserAndAccountDashboardFragment;
-import com.android.settings.applications.AdvancedAppSettings;
 import com.android.settings.applications.AppAndNotificationDashboardFragment;
+import com.android.settings.applications.DefaultAppSettings;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
 import com.android.settings.development.DevelopmentSettings;
 import com.android.settings.deviceinfo.StorageDashboardFragment;
@@ -65,7 +65,7 @@
                 CategoryKey.CATEGORY_APPS);
         PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
                 CategoryKey.CATEGORY_BATTERY);
-        PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedAppSettings.class.getName(),
+        PARENT_TO_CATEGORY_KEY_MAP.put(DefaultAppSettings.class.getName(),
                 CategoryKey.CATEGORY_APPS_DEFAULT);
         PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),
                 CategoryKey.CATEGORY_DISPLAY);
diff --git a/src/com/android/settings/dashboard/conditional/ConditionAdapter.java b/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
index 4a7422f..5a12f9d 100644
--- a/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
+++ b/src/com/android/settings/dashboard/conditional/ConditionAdapter.java
@@ -16,6 +16,7 @@
 package com.android.settings.dashboard.conditional;
 
 import android.content.Context;
+import android.support.annotation.VisibleForTesting;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.helper.ItemTouchHelper;
 import android.util.Log;
@@ -58,6 +59,31 @@
         }
     };
 
+    @VisibleForTesting
+    ItemTouchHelper.SimpleCallback mSwipeCallback = new ItemTouchHelper.SimpleCallback(0,
+            ItemTouchHelper.START | ItemTouchHelper.END) {
+        @Override
+        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
+                RecyclerView.ViewHolder target) {
+            return true;
+        }
+
+        @Override
+        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
+            return viewHolder.getItemViewType() == R.layout.condition_tile_new_ui
+                    ? super.getSwipeDirs(recyclerView, viewHolder) : 0;
+        }
+
+        @Override
+        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
+            Object item = getItem(viewHolder.getItemId());
+            // item can become null when running monkey
+            if (item != null) {
+                ((Condition) item).silence();
+            }
+        }
+    };
+
     public ConditionAdapter(Context context, List<Condition> conditions, @HeaderMode int mode) {
         mContext = context;
         mConditions = conditions;
@@ -107,27 +133,7 @@
     }
 
     public void addDismissHandling(final RecyclerView recyclerView) {
-        ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0,
-                ItemTouchHelper.START | ItemTouchHelper.END) {
-            @Override
-            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
-                    RecyclerView.ViewHolder target) {
-                return true;
-            }
-
-            @Override
-            public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
-                return viewHolder.getItemViewType() == R.layout.condition_tile_new_ui
-                        ? super.getSwipeDirs(recyclerView, viewHolder) : 0;
-            }
-
-            @Override
-            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
-                Object item = getItem(viewHolder.getItemId());
-                ((Condition) item).silence();
-            }
-        };
-        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
+        final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mSwipeCallback);
         itemTouchHelper.attachToRecyclerView(recyclerView);
     }
 
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index 1025ad7..ea0bcf0 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -21,6 +21,8 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.res.Resources;
+import android.icu.text.MeasureFormat;
+import android.icu.util.MeasureUnit;
 import android.net.NetworkPolicy;
 import android.net.NetworkTemplate;
 import android.os.Bundle;
@@ -31,6 +33,7 @@
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.ArrayAdapter;
 import android.widget.EditText;
 import android.widget.NumberPicker;
 import android.widget.Spinner;
@@ -248,6 +251,17 @@
                     : editor.getPolicyWarningBytes(template);
             final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
 
+            final MeasureFormat formatter = MeasureFormat.getInstance(
+                    getContext().getResources().getConfiguration().locale,
+                    MeasureFormat.FormatWidth.SHORT);
+            final String[] unitNames = new String[] {
+                formatter.getUnitDisplayName(MeasureUnit.MEGABYTE),
+                formatter.getUnitDisplayName(MeasureUnit.GIGABYTE)
+            };
+            final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
+                    getContext(), android.R.layout.simple_spinner_item, unitNames);
+            type.setAdapter(adapter);
+
             if (bytes > 1.5f * GB_IN_BYTES) {
                 final String bytesText = formatText(bytes / (float) GB_IN_BYTES);
                 bytesPicker.setText(bytesText);
diff --git a/src/com/android/settings/datausage/DataUsageMeteredSettings.java b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
index c2a18e9..830fc96 100644
--- a/src/com/android/settings/datausage/DataUsageMeteredSettings.java
+++ b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
@@ -14,19 +14,21 @@
 
 package com.android.settings.datausage;
 
+import static android.net.wifi.WifiInfo.removeDoubleQuotes;
+
+import static com.android.settings.datausage.DataUsageSummary.hasWifiRadio;
+
 import android.app.backup.BackupManager;
 import android.content.Context;
 import android.content.res.Resources;
-import android.net.NetworkPolicy;
 import android.net.NetworkPolicyManager;
-import android.net.NetworkTemplate;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
-import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.DropDownPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceCategory;
-import android.telephony.TelephonyManager;
+import android.text.TextUtils;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
@@ -39,18 +41,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import static android.net.NetworkPolicy.LIMIT_DISABLED;
-import static android.net.wifi.WifiInfo.removeDoubleQuotes;
-import static com.android.settings.datausage.DataUsageList.hasReadyMobileRadio;
-import static com.android.settings.datausage.DataUsageSummary.hasWifiRadio;
-
 /**
- * Panel to configure {@link NetworkPolicy#metered} for networks.
+ * Panel to configure {@link WifiConfiguration#meteredOverride}.
  */
 public class DataUsageMeteredSettings extends SettingsPreferenceFragment implements Indexable {
 
-    private static final boolean SHOW_MOBILE_CATEGORY = false;
-
     private NetworkPolicyManager mPolicyManager;
     private WifiManager mWifiManager;
 
@@ -85,18 +80,14 @@
     }
 
     private void updateNetworks(Context context) {
-        if (SHOW_MOBILE_CATEGORY && hasReadyMobileRadio(context)) {
-            mMobileCategory.removeAll();
-            mMobileCategory.addPreference(buildMobilePref(context));
-        } else {
-            getPreferenceScreen().removePreference(mMobileCategory);
-        }
+        getPreferenceScreen().removePreference(mMobileCategory);
 
         mWifiCategory.removeAll();
         if (hasWifiRadio(context) && mWifiManager.isWifiEnabled()) {
             for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
-                if (config.SSID != null) {
-                    mWifiCategory.addPreference(buildWifiPref(config));
+                final Preference pref = new MeteredPreference(getPrefContext(), config);
+                if (!TextUtils.isEmpty(pref.getTitle())) {
+                    mWifiCategory.addPreference(pref);
                 }
             }
         } else {
@@ -104,57 +95,40 @@
         }
     }
 
-    private Preference buildMobilePref(Context context) {
-        final TelephonyManager tele = TelephonyManager.from(context);
-        final NetworkTemplate template = NetworkTemplate.buildTemplateMobileAll(
-                tele.getSubscriberId());
-        final MeteredPreference pref = new MeteredPreference(getPrefContext(), template);
-        pref.setTitle(tele.getNetworkOperatorName());
-        return pref;
-    }
+    private class MeteredPreference extends DropDownPreference {
+        private final WifiConfiguration mConfig;
 
-    private Preference buildWifiPref(WifiConfiguration config) {
-        final String networkId = config.isPasspoint() ?
-                config.providerFriendlyName : config.SSID;
-        final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(networkId);
-        final MeteredPreference pref = new MeteredPreference(getPrefContext(), template);
-        pref.setTitle(removeDoubleQuotes(networkId));
-        return pref;
-    }
-
-    private class MeteredPreference extends SwitchPreference {
-        private final NetworkTemplate mTemplate;
-        private boolean mBinding;
-
-        public MeteredPreference(Context context, NetworkTemplate template) {
+        public MeteredPreference(Context context, WifiConfiguration config) {
             super(context);
-            mTemplate = template;
+            mConfig = config;
 
             setPersistent(false);
+            setEntries(new CharSequence[] {
+                    getString(R.string.data_usage_metered_auto),
+                    getString(R.string.data_usage_metered_yes),
+                    getString(R.string.data_usage_metered_no),
+            });
+            setEntryValues(new CharSequence[] {
+                    Integer.toString(WifiConfiguration.METERED_OVERRIDE_NONE),
+                    Integer.toString(WifiConfiguration.METERED_OVERRIDE_METERED),
+                    Integer.toString(WifiConfiguration.METERED_OVERRIDE_NOT_METERED),
+            });
+            setValue(Integer.toString(mConfig.meteredOverride));
+            setTitle(NetworkPolicyManager.resolveNetworkId(mConfig));
+            setSummary(getEntries()[mConfig.meteredOverride]);
 
-            mBinding = true;
-            final NetworkPolicy policy = mPolicyEditor.getPolicyMaybeUnquoted(template);
-            if (policy != null) {
-                if (policy.limitBytes != LIMIT_DISABLED) {
-                    setChecked(true);
-                    setEnabled(false);
-                } else {
-                    setChecked(policy.metered);
+            setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    mConfig.meteredOverride = Integer.parseInt((String) newValue);
+                    setSummary(getEntries()[mConfig.meteredOverride]);
+
+                    mWifiManager.updateNetwork(mConfig);
+                    // Stage the backup of the SettingsProvider package which backs this up
+                    BackupManager.dataChanged("com.android.providers.settings");
+                    return true;
                 }
-            } else {
-                setChecked(false);
-            }
-            mBinding = false;
-        }
-
-        @Override
-        protected void notifyChanged() {
-            super.notifyChanged();
-            if (!mBinding) {
-                mPolicyEditor.setPolicyMetered(mTemplate, isChecked());
-                // Stage the backup of the SettingsProvider package which backs this up
-                BackupManager.dataChanged("com.android.providers.settings");
-            }
+            });
         }
     }
 
@@ -180,21 +154,6 @@
                 data.screenTitle = res.getString(R.string.data_usage_menu_metered);
                 result.add(data);
 
-                if (SHOW_MOBILE_CATEGORY && hasReadyMobileRadio(context)) {
-                    // Mobile networks category
-                    data = new SearchIndexableRaw(context);
-                    data.title = res.getString(R.string.data_usage_metered_mobile);
-                    data.screenTitle = res.getString(R.string.data_usage_menu_metered);
-                    result.add(data);
-
-                    final TelephonyManager tele = TelephonyManager.from(context);
-
-                    data = new SearchIndexableRaw(context);
-                    data.title = tele.getNetworkOperatorName();
-                    data.screenTitle = res.getString(R.string.data_usage_menu_metered);
-                    result.add(data);
-                }
-
                 // Wi-Fi networks category
                 data = new SearchIndexableRaw(context);
                 data.title = res.getString(R.string.data_usage_metered_wifi);
@@ -227,12 +186,8 @@
             @Override
             public List<String> getNonIndexableKeys(Context context) {
                 final List<String> result = super.getNonIndexableKeys(context);
-                if (!SHOW_MOBILE_CATEGORY || !hasReadyMobileRadio(context)) {
-                    result.add("mobile");
-                }
-
+                result.add("mobile");
                 return result;
             }
         };
-
 }
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index c5c32ba..e6fc5e7 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -14,13 +14,15 @@
 
 package com.android.settings.datausage;
 
+import static android.net.ConnectivityManager.TYPE_ETHERNET;
+import static android.net.ConnectivityManager.TYPE_WIFI;
+
 import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.net.ConnectivityManager;
 import android.net.INetworkStatsSession;
-import android.net.NetworkPolicy;
 import android.net.NetworkPolicyManager;
 import android.net.NetworkTemplate;
 import android.net.TrafficStats;
@@ -46,6 +48,7 @@
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.SummaryPreference;
@@ -55,13 +58,10 @@
 import com.android.settings.search.Indexable;
 import com.android.settingslib.NetworkPolicyEditor;
 import com.android.settingslib.net.DataUsageController;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import static android.net.ConnectivityManager.TYPE_ETHERNET;
-import static android.net.ConnectivityManager.TYPE_WIFI;
-import static android.net.NetworkPolicy.LIMIT_DISABLED;
-
 public class DataUsageSummary extends DataUsageBase implements Indexable, DataUsageEditController {
 
     static final boolean LOGD = false;
@@ -403,7 +403,7 @@
         mPolicyEditor.read();
         int count = 0;
         for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
-            if (isMetered(config)) {
+            if (WifiConfiguration.isMetered(config, null)) {
                 count++;
             }
         }
@@ -411,23 +411,6 @@
             R.plurals.network_restrictions_summary, count, count));
     }
 
-    @VisibleForTesting
-    boolean isMetered(WifiConfiguration config) {
-        if (config.SSID == null) {
-            return false;
-        }
-        final String networkId = config.isPasspoint() ? config.providerFriendlyName : config.SSID;
-        final NetworkPolicy policy =
-            mPolicyEditor.getPolicyMaybeUnquoted(NetworkTemplate.buildTemplateWifi(networkId));
-        if (policy == null) {
-            return false;
-        }
-        if (policy.limitBytes != LIMIT_DISABLED) {
-            return true;
-        }
-        return policy.metered;
-    }
-
     private static class SummaryProvider
             implements SummaryLoader.SummaryProvider {
 
diff --git a/src/com/android/settings/development/DevelopmentSettingsEnabler.java b/src/com/android/settings/development/DevelopmentSettingsEnabler.java
index 7132631..ed750e4 100644
--- a/src/com/android/settings/development/DevelopmentSettingsEnabler.java
+++ b/src/com/android/settings/development/DevelopmentSettingsEnabler.java
@@ -34,6 +34,7 @@
         mContext = context;
         mDevelopmentPreferences = context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
                 Context.MODE_PRIVATE);
+        updateEnabledState();
         if (lifecycle != null) {
             lifecycle.addObserver(this);
         }
@@ -41,8 +42,7 @@
 
     @Override
     public void onResume() {
-        mLastEnabledState = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+        updateEnabledState();
     }
 
     public static boolean enableDevelopmentSettings(Context context, SharedPreferences prefs) {
@@ -53,6 +53,11 @@
                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
     }
 
+    private void updateEnabledState() {
+        mLastEnabledState = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+    }
+
     public boolean getLastEnabledState() {
         return mLastEnabledState;
     }
diff --git a/src/com/android/settings/deviceinfo/StorageItemPreference.java b/src/com/android/settings/deviceinfo/StorageItemPreference.java
index 3dcf935..d0114e3 100644
--- a/src/com/android/settings/deviceinfo/StorageItemPreference.java
+++ b/src/com/android/settings/deviceinfo/StorageItemPreference.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.icu.util.MeasureUnit;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.util.AttributeSet;
@@ -51,7 +52,7 @@
                 FileSizeFormatter.formatFileSize(
                         getContext(),
                         size,
-                        getGigabyteSuffix(getContext().getResources()),
+                        MeasureUnit.GIGABYTE,
                         FileSizeFormatter.GIGABYTE_IN_BYTES));
         if (total == 0) {
             mProgressPercent = 0;
@@ -75,8 +76,4 @@
         updateProgressBar();
         super.onBindViewHolder(view);
     }
-
-    private static int getGigabyteSuffix(Resources res) {
-        return res.getIdentifier("gigabyteShort", "string", "android");
-    }
 }
diff --git a/src/com/android/settings/display/ConversationMessageView.java b/src/com/android/settings/display/ConversationMessageView.java
index 06e7b9b..b054444 100644
--- a/src/com/android/settings/display/ConversationMessageView.java
+++ b/src/com/android/settings/display/ConversationMessageView.java
@@ -29,7 +29,6 @@
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
 import android.widget.TextView;
-
 import com.android.settings.R;
 
 /**
@@ -76,7 +75,7 @@
         mIconTextColor = a.getColor(R.styleable.ConversationMessageView_iconTextColor, 0);
         mIconBackgroundColor = a.getColor(R.styleable.ConversationMessageView_iconBackgroundColor,
                 0);
-
+        a.recycle();
         LayoutInflater.from(context).inflate(R.layout.conversation_message_icon, this);
         LayoutInflater.from(context).inflate(R.layout.conversation_message_content, this);
     }
@@ -252,7 +251,7 @@
 
     private static Drawable getTintedDrawable(final Context context, final Drawable drawable,
             final int color) {
-        // For some reason occassionally drawables on JB has a null constant state
+        // For some reason occasionally drawables on JB has a null constant state
         final Drawable.ConstantState constantStateDrawable = drawable.getConstantState();
         final Drawable retDrawable = (constantStateDrawable != null)
                 ? constantStateDrawable.newDrawable(context.getResources()).mutate()
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index 2927002..a966beb 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -35,9 +35,10 @@
 
     private CharSequence mSummary;
     private TextView mSummaryView;
-    private boolean hideSummary;
 
     @VisibleForTesting
+    boolean hideSummary;
+    @VisibleForTesting
     BatteryInfo mBatteryInfo;
 
     public BatteryHistoryPreference(Context context, AttributeSet attrs) {
@@ -56,8 +57,10 @@
     public void setBottomSummary(CharSequence text) {
         mSummary = text;
         if (mSummaryView != null) {
+            mSummaryView.setVisibility(View.VISIBLE);
             mSummaryView.setText(mSummary);
         }
+        hideSummary = false;
     }
 
     public void hideBottomSummary() {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index 9d9353a..f8bc71b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -15,7 +15,10 @@
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.PackageManager;
+import android.os.BatteryManager;
 import android.os.BatteryStats;
 import android.os.Bundle;
 import android.os.Handler;
@@ -171,7 +174,11 @@
         updatePreference(mHistPref);
         refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
 
-        if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
+        Intent batteryIntent =
+                context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+        final boolean plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0;
+
+        if (mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context) && !plugged) {
             mHistPref.setBottomSummary(
                     mPowerUsageFeatureProvider.getAdvancedUsageScreenInfoString());
         } else {
diff --git a/src/com/android/settings/graph/UsageView.java b/src/com/android/settings/graph/UsageView.java
index 38eb027..bcf0441 100644
--- a/src/com/android/settings/graph/UsageView.java
+++ b/src/com/android/settings/graph/UsageView.java
@@ -81,6 +81,7 @@
             }
         }
         mUsageGraph.setAccentColor(a.getColor(R.styleable.UsageView_android_colorAccent, 0));
+        a.recycle();
     }
 
     public void clearPaths() {
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
index 98c4db2..620bc65 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java
@@ -27,7 +27,6 @@
 import android.widget.EditText;
 
 import com.android.settings.R;
-import com.android.settings.UserDictionarySettings;
 import com.android.settings.Utils;
 
 import java.util.ArrayList;
diff --git a/src/com/android/settings/inputmethod/UserDictionaryCursorLoader.java b/src/com/android/settings/inputmethod/UserDictionaryCursorLoader.java
new file mode 100644
index 0000000..d5b742d
--- /dev/null
+++ b/src/com/android/settings/inputmethod/UserDictionaryCursorLoader.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 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.inputmethod;
+
+import android.content.Context;
+import android.content.CursorLoader;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.provider.UserDictionary;
+import android.support.annotation.VisibleForTesting;
+import android.util.ArraySet;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+
+public class UserDictionaryCursorLoader extends CursorLoader {
+
+    @VisibleForTesting
+    static final String[] QUERY_PROJECTION = {
+            UserDictionary.Words._ID,
+            UserDictionary.Words.WORD,
+            UserDictionary.Words.SHORTCUT
+    };
+
+    // The index of the shortcut in the above array.
+    static final int INDEX_SHORTCUT = 2;
+
+    // Either the locale is empty (means the word is applicable to all locales)
+    // or the word equals our current locale
+    private static final String QUERY_SELECTION =
+            UserDictionary.Words.LOCALE + "=?";
+    private static final String QUERY_SELECTION_ALL_LOCALES =
+            UserDictionary.Words.LOCALE + " is null";
+
+
+    // Locale can be any of:
+    // - The string representation of a locale, as returned by Locale#toString()
+    // - The empty string. This means we want a cursor returning words valid for all locales.
+    // - null. This means we want a cursor for the current locale, whatever this is.
+    // Note that this contrasts with the data inside the database, where NULL means "all
+    // locales" and there should never be an empty string. The confusion is called by the
+    // historical use of null for "all locales".
+    // TODO: it should be easy to make this more readable by making the special values
+    // human-readable, like "all_locales" and "current_locales" strings, provided they
+    // can be guaranteed not to match locales that may exist.
+    private final String mLocale;
+
+    public UserDictionaryCursorLoader(Context context, String locale) {
+        super(context);
+        mLocale = locale;
+    }
+
+    @Override
+    public Cursor loadInBackground() {
+        final MatrixCursor result = new MatrixCursor(QUERY_PROJECTION);
+        final Cursor candidate;
+        if ("".equals(mLocale)) {
+            // Case-insensitive sort
+            candidate = getContext().getContentResolver().query(
+                    UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
+                    QUERY_SELECTION_ALL_LOCALES, null,
+                    "UPPER(" + UserDictionary.Words.WORD + ")");
+        } else {
+            final String queryLocale = null != mLocale ? mLocale : Locale.getDefault().toString();
+            candidate = getContext().getContentResolver().query(UserDictionary.Words.CONTENT_URI,
+                    QUERY_PROJECTION, QUERY_SELECTION,
+                    new String[]{queryLocale}, "UPPER(" + UserDictionary.Words.WORD + ")");
+        }
+        final Set<Integer> hashSet = new ArraySet<>();
+        for (candidate.moveToFirst(); !candidate.isAfterLast(); candidate.moveToNext()) {
+            final int id = candidate.getInt(0);
+            final String word = candidate.getString(1);
+            final String shortcut = candidate.getString(2);
+            final int hash = Objects.hash(word, shortcut);
+            if (hashSet.contains(hash)) {
+                continue;
+            }
+            hashSet.add(hash);
+            result.addRow(new Object[]{id, word, shortcut});
+        }
+        return result;
+    }
+}
diff --git a/src/com/android/settings/inputmethod/UserDictionaryList.java b/src/com/android/settings/inputmethod/UserDictionaryList.java
index b8e87ef..cf4eccd 100644
--- a/src/com/android/settings/inputmethod/UserDictionaryList.java
+++ b/src/com/android/settings/inputmethod/UserDictionaryList.java
@@ -180,7 +180,7 @@
             newPref.getExtras().putString("locale", locale);
         }
         newPref.setIntent(intent);
-        newPref.setFragment(com.android.settings.UserDictionarySettings.class.getName());
+        newPref.setFragment(UserDictionarySettings.class.getName());
         return newPref;
     }
 
diff --git a/src/com/android/settings/UserDictionarySettings.java b/src/com/android/settings/inputmethod/UserDictionarySettings.java
similarity index 68%
rename from src/com/android/settings/UserDictionarySettings.java
rename to src/com/android/settings/inputmethod/UserDictionarySettings.java
index 5571c2d..9680af1 100644
--- a/src/com/android/settings/UserDictionarySettings.java
+++ b/src/com/android/settings/inputmethod/UserDictionarySettings.java
@@ -1,25 +1,29 @@
-/**
- * Copyright (C) 2009 Google Inc.
+/*
+ * Copyright (C) 2009 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
+ * 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
+ *      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.
+ * 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;
+package com.android.settings.inputmethod;
 
+import android.annotation.Nullable;
+import android.app.ActionBar;
 import android.app.ListFragment;
+import android.app.LoaderManager;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.Loader;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.provider.UserDictionary;
@@ -38,28 +42,13 @@
 import android.widget.TextView;
 
 import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
-import com.android.settings.inputmethod.UserDictionaryAddWordContents;
-import com.android.settings.inputmethod.UserDictionarySettingsUtils;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.core.instrumentation.Instrumentable;
+import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
 
-import java.util.Locale;
-
-public class UserDictionarySettings extends ListFragment implements Instrumentable {
-
-    private static final String[] QUERY_PROJECTION = {
-        UserDictionary.Words._ID, UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT
-    };
-
-    // The index of the shortcut in the above array.
-    private static final int INDEX_SHORTCUT = 2;
-
-    // Either the locale is empty (means the word is applicable to all locales)
-    // or the word equals our current locale
-    private static final String QUERY_SELECTION =
-            UserDictionary.Words.LOCALE + "=?";
-    private static final String QUERY_SELECTION_ALL_LOCALES =
-            UserDictionary.Words.LOCALE + " is null";
+public class UserDictionarySettings extends ListFragment implements Instrumentable,
+        LoaderManager.LoaderCallbacks<Cursor> {
 
     private static final String DELETE_SELECTION_WITH_SHORTCUT = UserDictionary.Words.WORD
             + "=? AND " + UserDictionary.Words.SHORTCUT + "=?";
@@ -68,12 +57,13 @@
             + UserDictionary.Words.SHORTCUT + "=''";
 
     private static final int OPTIONS_MENU_ADD = Menu.FIRST;
+    private static final int LOADER_ID = 1;
 
     private final VisibilityLoggerMixin mVisibilityLoggerMixin =
             new VisibilityLoggerMixin(getMetricsCategory());
 
     private Cursor mCursor;
-    protected String mLocale;
+    private String mLocale;
 
     @Override
     public int getMetricsCategory() {
@@ -87,16 +77,8 @@
     }
 
     @Override
-    public View onCreateView(
-            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        return inflater.inflate(
-                com.android.internal.R.layout.preference_list_fragment, container, false);
-    }
-
-    @Override
-    public void onActivityCreated(Bundle savedInstanceState) {
-        super.onActivityCreated(savedInstanceState);
-        getActivity().getActionBar().setTitle(R.string.user_dict_settings_title);
+    public void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
 
         final Intent intent = getActivity().getIntent();
         final String localeFromIntent =
@@ -116,56 +98,49 @@
         }
 
         mLocale = locale;
-        mCursor = createCursor(locale);
-        TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
+
+        setHasOptionsMenu(true);
+        getLoaderManager().initLoader(LOADER_ID, null, this /* callback */);
+    }
+
+    @Override
+    public View onCreateView(
+            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        // Show the language as a subtitle of the action bar
+        final ActionBar actionBar = getActivity().getActionBar();
+        if (actionBar != null) {
+            actionBar.setTitle(R.string.user_dict_settings_title);
+            actionBar.setSubtitle(
+                    UserDictionarySettingsUtils.getLocaleDisplayName(getActivity(), mLocale));
+        }
+
+        return inflater.inflate(
+                com.android.internal.R.layout.preference_list_fragment, container, false);
+    }
+
+    @Override
+    public void onViewCreated(View view, Bundle savedInstanceState) {
+        super.onViewCreated(view, savedInstanceState);
+        TextView emptyView = getView().findViewById(android.R.id.empty);
         emptyView.setText(R.string.user_dict_settings_empty_text);
 
         final ListView listView = getListView();
-        listView.setAdapter(createAdapter());
         listView.setFastScrollEnabled(true);
         listView.setEmptyView(emptyView);
-
-        setHasOptionsMenu(true);
-        // Show the language as a subtitle of the action bar
-        getActivity().getActionBar().setSubtitle(
-                UserDictionarySettingsUtils.getLocaleDisplayName(getActivity(), mLocale));
     }
 
     @Override
     public void onResume() {
         super.onResume();
         mVisibilityLoggerMixin.onResume();
-    }
-
-    private Cursor createCursor(final String locale) {
-        // Locale can be any of:
-        // - The string representation of a locale, as returned by Locale#toString()
-        // - The empty string. This means we want a cursor returning words valid for all locales.
-        // - null. This means we want a cursor for the current locale, whatever this is.
-        // Note that this contrasts with the data inside the database, where NULL means "all
-        // locales" and there should never be an empty string. The confusion is called by the
-        // historical use of null for "all locales".
-        // TODO: it should be easy to make this more readable by making the special values
-        // human-readable, like "all_locales" and "current_locales" strings, provided they
-        // can be guaranteed not to match locales that may exist.
-        if ("".equals(locale)) {
-            // Case-insensitive sort
-            return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
-                    QUERY_SELECTION_ALL_LOCALES, null,
-                    "UPPER(" + UserDictionary.Words.WORD + ")");
-        } else {
-            final String queryLocale = null != locale ? locale : Locale.getDefault().toString();
-            return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION,
-                    QUERY_SELECTION, new String[] { queryLocale },
-                    "UPPER(" + UserDictionary.Words.WORD + ")");
-        }
+        getLoaderManager().restartLoader(LOADER_ID, null, this /* callback */);
     }
 
     private ListAdapter createAdapter() {
         return new MyAdapter(getActivity(),
                 R.layout.user_dictionary_item, mCursor,
-                new String[] { UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT },
-                new int[] { android.R.id.text1, android.R.id.text2 }, this);
+                new String[]{UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT},
+                new int[]{android.R.id.text1, android.R.id.text2});
     }
 
     @Override
@@ -181,7 +156,7 @@
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         MenuItem actionItem =
                 menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title)
-                .setIcon(R.drawable.ic_menu_add_white);
+                        .setIcon(R.drawable.ic_menu_add_white);
         actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
                 MenuItem.SHOW_AS_ACTION_WITH_TEXT);
     }
@@ -203,7 +178,8 @@
 
     /**
      * Add or edit a word. If editingWord is null, it's an add; otherwise, it's an edit.
-     * @param editingWord the word to edit, or null if it's an add.
+     *
+     * @param editingWord     the word to edit, or null if it's an add.
      * @param editingShortcut the shortcut for this entry, or null if none.
      */
     private void showAddOrEditDialog(final String editingWord, final String editingShortcut) {
@@ -245,14 +221,30 @@
         if (TextUtils.isEmpty(shortcut)) {
             resolver.delete(
                     UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITHOUT_SHORTCUT,
-                    new String[] { word });
+                    new String[]{word});
         } else {
             resolver.delete(
                     UserDictionary.Words.CONTENT_URI, DELETE_SELECTION_WITH_SHORTCUT,
-                    new String[] { word, shortcut });
+                    new String[]{word, shortcut});
         }
     }
 
+    @Override
+    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
+        return new UserDictionaryCursorLoader(getContext(), mLocale);
+    }
+
+    @Override
+    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
+        mCursor = data;
+        getListView().setAdapter(createAdapter());
+    }
+
+    @Override
+    public void onLoaderReset(Loader<Cursor> loader) {
+
+    }
+
     private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
 
         private AlphabetIndexer mIndexer;
@@ -261,12 +253,12 @@
 
             @Override
             public boolean setViewValue(View v, Cursor c, int columnIndex) {
-                if (columnIndex == INDEX_SHORTCUT) {
-                    final String shortcut = c.getString(INDEX_SHORTCUT);
+                if (columnIndex == UserDictionaryCursorLoader.INDEX_SHORTCUT) {
+                    final String shortcut = c.getString(UserDictionaryCursorLoader.INDEX_SHORTCUT);
                     if (TextUtils.isEmpty(shortcut)) {
                         v.setVisibility(View.GONE);
                     } else {
-                        ((TextView)v).setText(shortcut);
+                        ((TextView) v).setText(shortcut);
                         v.setVisibility(View.VISIBLE);
                     }
                     v.invalidate();
@@ -277,8 +269,7 @@
             }
         };
 
-        public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to,
-                UserDictionarySettings settings) {
+        public MyAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
             super(context, layout, c, from, to);
 
             if (null != c) {
diff --git a/src/com/android/settings/language/UserDictionaryPreferenceController.java b/src/com/android/settings/language/UserDictionaryPreferenceController.java
index 7d9a6ef..137f44a 100644
--- a/src/com/android/settings/language/UserDictionaryPreferenceController.java
+++ b/src/com/android/settings/language/UserDictionaryPreferenceController.java
@@ -21,9 +21,9 @@
 import android.os.Bundle;
 import android.support.v7.preference.Preference;
 
-import com.android.settings.UserDictionarySettings;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.inputmethod.UserDictionaryList;
+import com.android.settings.inputmethod.UserDictionarySettings;
 import com.android.settingslib.core.AbstractPreferenceController;
 
 import java.util.TreeSet;
diff --git a/src/com/android/settings/nfc/PaymentBackend.java b/src/com/android/settings/nfc/PaymentBackend.java
index eeb43e2..bc9dbbe 100644
--- a/src/com/android/settings/nfc/PaymentBackend.java
+++ b/src/com/android/settings/nfc/PaymentBackend.java
@@ -42,7 +42,7 @@
     }
 
     public static class PaymentAppInfo {
-        CharSequence label;
+        public CharSequence label;
         CharSequence description;
         Drawable banner;
         boolean isDefault;
diff --git a/src/com/android/settings/nfc/PaymentSettings.java b/src/com/android/settings/nfc/PaymentSettings.java
index d914cd8..10f1154 100644
--- a/src/com/android/settings/nfc/PaymentSettings.java
+++ b/src/com/android/settings/nfc/PaymentSettings.java
@@ -16,12 +16,10 @@
 
 package com.android.settings.nfc;
 
-import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
-import android.nfc.NfcAdapter;
 import android.os.Bundle;
 import android.support.v7.preference.PreferenceManager;
 import android.support.v7.preference.PreferenceScreen;
@@ -34,8 +32,6 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 import com.android.settings.search.SearchIndexableRaw;
@@ -109,40 +105,6 @@
         menuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_NEVER);
     }
 
-    private static class SummaryProvider implements SummaryLoader.SummaryProvider {
-
-        private final Context mContext;
-        private final SummaryLoader mSummaryLoader;
-
-        public SummaryProvider(Context context, SummaryLoader summaryLoader) {
-            mContext = context;
-            mSummaryLoader = summaryLoader;
-        }
-
-        @Override
-        public void setListening(boolean listening) {
-            if (listening && NfcAdapter.getDefaultAdapter(mContext) != null) {
-                PaymentBackend paymentBackend = new PaymentBackend(mContext);
-                paymentBackend.refresh();
-                PaymentAppInfo app = paymentBackend.getDefaultApp();
-                String summary = null;
-                if (app != null) {
-                    summary = mContext.getString(R.string.payment_summary, app.label);
-                }
-                mSummaryLoader.setSummary(this, summary);
-            }
-        }
-    }
-
-    public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
-            = new SummaryLoader.SummaryProviderFactory() {
-        @Override
-        public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
-                                                                   SummaryLoader summaryLoader) {
-            return new SummaryProvider(activity, summaryLoader);
-        }
-    };
-
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
         new BaseSearchIndexProvider() {
             @Override
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 0d9c78f..6087503 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -304,11 +304,8 @@
 
             try {
                 ApplicationInfo info = mPm.getApplicationInfo(rule.getOwner().getPackageName(), 0);
-                LoadIconTask task = new LoadIconTask(this);
-                task.execute(info);
                 setSummary(computeRuleSummary(rule, isSystemRule, info.loadLabel(mPm)));
             } catch (PackageManager.NameNotFoundException e) {
-                setIcon(R.drawable.ic_label);
                 appExists = false;
                 return;
             }
@@ -345,29 +342,6 @@
         };
     }
 
-    private class LoadIconTask extends AsyncTask<ApplicationInfo, Void, Drawable> {
-        private final WeakReference<Preference> prefReference;
-
-        public LoadIconTask(Preference pref) {
-            prefReference = new WeakReference<>(pref);
-        }
-
-        @Override
-        protected Drawable doInBackground(ApplicationInfo... params) {
-            return params[0].loadIcon(mPm);
-        }
-
-        @Override
-        protected void onPostExecute(Drawable icon) {
-            if (icon != null) {
-                final Preference pref = prefReference.get();
-                if (pref != null) {
-                    pref.setIcon(icon);
-                }
-            }
-        }
-    }
-
     public static class SummaryBuilder {
 
         private Context mContext;
diff --git a/src/com/android/settings/password/ConfirmLockPassword.java b/src/com/android/settings/password/ConfirmLockPassword.java
index edda361..328646b 100644
--- a/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/src/com/android/settings/password/ConfirmLockPassword.java
@@ -108,7 +108,6 @@
         private boolean mUsingFingerprint = false;
         private AppearAnimationUtils mAppearAnimationUtils;
         private DisappearAnimationUtils mDisappearAnimationUtils;
-        private boolean mBlockImm;
 
         // required constructor for fragments
         public ConfirmLockPasswordFragment() {
@@ -240,8 +239,8 @@
             mDetailsTextView.setAlpha(0f);
             mCancelButton.setAlpha(0f);
             mPasswordEntry.setAlpha(0f);
+            mErrorTextView.setAlpha(0f);
             mFingerprintIcon.setAlpha(0f);
-            mBlockImm = true;
         }
 
         private View[] getActiveViews() {
@@ -252,6 +251,7 @@
                 result.add(mCancelButton);
             }
             result.add(mPasswordEntry);
+            result.add(mErrorTextView);
             if (mFingerprintIcon.getVisibility() == View.VISIBLE) {
                 result.add(mFingerprintIcon);
             }
@@ -261,13 +261,7 @@
         @Override
         public void startEnterAnimation() {
             super.startEnterAnimation();
-            mAppearAnimationUtils.startAnimation(getActiveViews(), new Runnable() {
-                @Override
-                public void run() {
-                    mBlockImm = false;
-                    resetState();
-                }
-            });
+            mAppearAnimationUtils.startAnimation(getActiveViews(), this::updatePasswordEntry);
         }
 
         @Override
@@ -293,7 +287,7 @@
                 mCredentialCheckResultTracker.clearResult();
                 handleAttemptLockout(deadline);
             } else {
-                resetState();
+                updatePasswordEntry();
                 mErrorTextView.setText("");
                 updateErrorMessage(
                         mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
@@ -311,36 +305,24 @@
             mUsingFingerprint = visible;
         }
 
-        private void resetState() {
-            if (mBlockImm) return;
-            mPasswordEntry.setEnabled(true);
-            mPasswordEntryInputDisabler.setInputEnabled(true);
-            if (shouldAutoShowSoftKeyboard()) {
+        private void updatePasswordEntry() {
+            final boolean isLockedOut =
+                    mLockPatternUtils.getLockoutAttemptDeadline(mEffectiveUserId) != 0;
+            mPasswordEntry.setEnabled(!isLockedOut);
+            mPasswordEntryInputDisabler.setInputEnabled(!isLockedOut);
+            if (isLockedOut || mUsingFingerprint) {
+                mImm.hideSoftInputFromWindow(mPasswordEntry.getWindowToken(), 0 /*flags*/);
+            } else {
                 mPasswordEntry.scheduleShowSoftInput();
             }
         }
 
-        private boolean shouldAutoShowSoftKeyboard() {
-            return mPasswordEntry.isEnabled() && !mUsingFingerprint;
-        }
-
         public void onWindowFocusChanged(boolean hasFocus) {
-            if (!hasFocus || mBlockImm) {
+            if (!hasFocus) {
                 return;
             }
             // Post to let window focus logic to finish to allow soft input show/hide properly.
-            mPasswordEntry.post(new Runnable() {
-                @Override
-                public void run() {
-                    if (shouldAutoShowSoftKeyboard()) {
-                        resetState();
-                        return;
-                    }
-
-                    mImm.hideSoftInputFromWindow(mPasswordEntry.getWindowToken(),
-                            InputMethodManager.HIDE_IMPLICIT_ONLY);
-                }
-            });
+            mPasswordEntry.post(this::updatePasswordEntry);
         }
 
         private void handleNext() {
@@ -395,7 +377,7 @@
                                 }
                             }
                             mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs,
-                                    localUserId);
+                                    localEffectiveUserId);
                         }
             };
             mPendingLockCheck = (localEffectiveUserId == localUserId)
@@ -490,10 +472,8 @@
         }
 
         private void handleAttemptLockout(long elapsedRealtimeDeadline) {
-            long elapsedRealtime = SystemClock.elapsedRealtime();
-            mPasswordEntry.setEnabled(false);
             mCountdownTimer = new CountDownTimer(
-                    elapsedRealtimeDeadline - elapsedRealtime,
+                    elapsedRealtimeDeadline - SystemClock.elapsedRealtime(),
                     LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) {
 
                 @Override
@@ -506,12 +486,13 @@
 
                 @Override
                 public void onFinish() {
-                    resetState();
+                    updatePasswordEntry();
                     mErrorTextView.setText("");
                     updateErrorMessage(
                             mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId));
                 }
             }.start();
+            updatePasswordEntry();
         }
 
         public void onClick(View v) {
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 9b84bf1..dccdc65 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -20,8 +20,8 @@
 import android.support.annotation.DrawableRes;
 import android.support.annotation.VisibleForTesting;
 import android.support.annotation.XmlRes;
-
 import android.text.TextUtils;
+
 import com.android.settings.DateTimeSettings;
 import com.android.settings.DeviceInfoSettings;
 import com.android.settings.DisplaySettings;
@@ -34,15 +34,14 @@
 import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment;
 import com.android.settings.accessibility.MagnificationPreferenceFragment;
 import com.android.settings.accounts.UserAndAccountDashboardFragment;
-import com.android.settings.applications.AdvancedAppSettings;
 import com.android.settings.applications.AppAndNotificationDashboardFragment;
+import com.android.settings.applications.DefaultAppSettings;
 import com.android.settings.applications.SpecialAccessSettings;
 import com.android.settings.applications.assist.ManageAssist;
 import com.android.settings.backup.BackupSettingsActivity;
 import com.android.settings.backup.BackupSettingsFragment;
 import com.android.settings.bluetooth.BluetoothSettings;
 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
-import com.android.settings.support.SupportDashboardActivity;
 import com.android.settings.datausage.DataUsageMeteredSettings;
 import com.android.settings.datausage.DataUsageSummary;
 import com.android.settings.development.DevelopmentSettings;
@@ -78,6 +77,7 @@
 import com.android.settings.print.PrintSettingsFragment;
 import com.android.settings.security.LockscreenDashboardFragment;
 import com.android.settings.sim.SimSettings;
+import com.android.settings.support.SupportDashboardActivity;
 import com.android.settings.system.ResetDashboardFragment;
 import com.android.settings.system.SystemDashboardFragment;
 import com.android.settings.tts.TtsEnginePreferenceFragment;
@@ -101,7 +101,7 @@
     @XmlRes
     public static final int NO_DATA_RES_ID = 0;
 
-    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+    @VisibleForTesting
     static final HashMap<String, SearchIndexableResource> sResMap = new HashMap<>();
 
     @VisibleForTesting
@@ -156,7 +156,7 @@
         addIndex(PowerUsageAdvanced.class, NO_DATA_RES_ID, R.drawable.ic_settings_battery);
         addIndex(BatterySaverSettings.class,
                 R.xml.battery_saver_settings, R.drawable.ic_settings_battery);
-        addIndex(AdvancedAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
+        addIndex(DefaultAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
         addIndex(ManageAssist.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
         addIndex(SpecialAccessSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
         addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser);
@@ -201,7 +201,7 @@
         addIndex(
                 TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
         addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings,
-            R.drawable.ic_settings_security);
+                R.drawable.ic_settings_security);
         addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID,
                 R.drawable.ic_settings_accessibility);
         addIndex(AccessibilityShortcutPreferenceFragment.class, NO_DATA_RES_ID,
diff --git a/src/com/android/settings/search/XmlParserUtils.java b/src/com/android/settings/search/XmlParserUtils.java
index c81381c..b4ffc53 100644
--- a/src/com/android/settings/search/XmlParserUtils.java
+++ b/src/com/android/settings/search/XmlParserUtils.java
@@ -17,11 +17,11 @@
 
 package com.android.settings.search;
 
+import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
 import android.util.TypedValue;
-
 import com.android.settings.R;
 
 /**
@@ -87,17 +87,18 @@
                 R.styleable.Preference_android_fragment);
     }
 
+    @Nullable
     private static String getData(Context context, AttributeSet set, int[] attrs, int resId) {
         final TypedArray ta = context.obtainStyledAttributes(set, attrs);
         String data = ta.getString(resId);
         ta.recycle();
-        return (data != null) ? data.toString() : null;
+        return data;
     }
 
     private static String getDataEntries(Context context, AttributeSet set, int[] attrs, int resId) {
         final TypedArray sa = context.obtainStyledAttributes(set, attrs);
         final TypedValue tv = sa.peekValue(resId);
-
+        sa.recycle();
         String[] data = null;
         if (tv != null && tv.type == TypedValue.TYPE_REFERENCE) {
             if (tv.resourceId != 0) {
diff --git a/src/com/android/settings/security/SecurityFeatureProviderImpl.java b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
index 8c6d343..47f7a1b 100644
--- a/src/com/android/settings/security/SecurityFeatureProviderImpl.java
+++ b/src/com/android/settings/security/SecurityFeatureProviderImpl.java
@@ -17,31 +17,30 @@
 package com.android.settings.security;
 
 import android.content.Context;
-import android.content.Intent;
 import android.content.IContentProvider;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.os.Looper;
-import com.android.settings.R;
-import com.android.settings.trustagent.TrustAgentManager;
-import com.android.settings.trustagent.TrustAgentManagerImpl;
-import com.android.settingslib.drawer.DashboardCategory;
 import android.support.annotation.VisibleForTesting;
-import android.support.v4.content.ContextCompat;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Pair;
 
+import com.android.settings.R;
+import com.android.settings.trustagent.TrustAgentManager;
+import com.android.settings.trustagent.TrustAgentManagerImpl;
+import com.android.settingslib.drawer.DashboardCategory;
 import com.android.settingslib.drawer.Tile;
 import com.android.settingslib.drawer.TileUtils;
 
-import java.util.concurrent.Executors;
-import java.util.TreeMap;
 import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.Executors;
 
 /** Implementation for {@code SecurityFeatureProvider}. */
 public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
diff --git a/src/com/android/settings/utils/FileSizeFormatter.java b/src/com/android/settings/utils/FileSizeFormatter.java
index e56388a..c0d360f 100644
--- a/src/com/android/settings/utils/FileSizeFormatter.java
+++ b/src/com/android/settings/utils/FileSizeFormatter.java
@@ -16,11 +16,22 @@
 
 package com.android.settings.utils;
 
+import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.Resources;
+import android.icu.text.DecimalFormat;
+import android.icu.text.MeasureFormat;
+import android.icu.text.NumberFormat;
+import android.icu.util.Measure;
+import android.icu.util.MeasureUnit;
 import android.text.BidiFormatter;
+import android.text.TextUtils;
 import android.text.format.Formatter;
+import android.view.View;
+
+import java.math.BigDecimal;
+import java.util.Locale;
 
 /**
  * Utility class to aid in formatting file sizes always with the same unit. This is modified from
@@ -31,6 +42,61 @@
     public static final long MEGABYTE_IN_BYTES = KILOBYTE_IN_BYTES * 1000;
     public static final long GIGABYTE_IN_BYTES = MEGABYTE_IN_BYTES * 1000;
 
+    private static class RoundedBytesResult {
+        public final float value;
+        public final MeasureUnit units;
+        public final int fractionDigits;
+        public final long roundedBytes;
+
+        public RoundedBytesResult(
+                float value, MeasureUnit units, int fractionDigits, long roundedBytes) {
+            this.value = value;
+            this.units = units;
+            this.fractionDigits = fractionDigits;
+            this.roundedBytes = roundedBytes;
+        }
+    }
+
+    private static Locale localeFromContext(@NonNull Context context) {
+        return context.getResources().getConfiguration().locale;
+    }
+
+    private static String bidiWrap(@NonNull Context context, String source) {
+        final Locale locale = localeFromContext(context);
+        if (TextUtils.getLayoutDirectionFromLocale(locale) == View.LAYOUT_DIRECTION_RTL) {
+            return BidiFormatter.getInstance(true /* RTL*/).unicodeWrap(source);
+        } else {
+            return source;
+        }
+    }
+
+    private static NumberFormat getNumberFormatter(Locale locale, int fractionDigits) {
+        final NumberFormat numberFormatter = NumberFormat.getInstance(locale);
+        numberFormatter.setMinimumFractionDigits(fractionDigits);
+        numberFormatter.setMaximumFractionDigits(fractionDigits);
+        numberFormatter.setGroupingUsed(false);
+        if (numberFormatter instanceof DecimalFormat) {
+            // We do this only for DecimalFormat, since in the general NumberFormat case, calling
+            // setRoundingMode may throw an exception.
+            numberFormatter.setRoundingMode(BigDecimal.ROUND_HALF_UP);
+        }
+        return numberFormatter;
+    }
+
+    private static String formatMeasureShort(Locale locale, NumberFormat numberFormatter,
+            float value, MeasureUnit units) {
+        final MeasureFormat measureFormatter = MeasureFormat.getInstance(
+                locale, MeasureFormat.FormatWidth.SHORT, numberFormatter);
+        return measureFormatter.format(new Measure(value, units));
+    }
+
+    private static String formatRoundedBytesResult(
+            @NonNull Context context, @NonNull RoundedBytesResult input) {
+        final Locale locale = localeFromContext(context);
+        final NumberFormat numberFormatter = getNumberFormatter(locale, input.fractionDigits);
+        return formatMeasureShort(locale, numberFormatter, input.value, input.units);
+    }
+
     /**
      * Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.
      *
@@ -47,23 +113,17 @@
      *
      * @param context Context to use to load the localized units
      * @param sizeBytes size value to be formatted, in bytes
-     * @param suffix String id for the unit suffix.
-     * @param mult Amount of bytes in the unit. * @return formatted string with the number
+     * @param unit The unit used for formatting.
+     * @param mult Amount of bytes in the unit.
+     * @return formatted string with the number
      */
     public static String formatFileSize(
-            @Nullable Context context, long sizeBytes, int suffix, long mult) {
+            @Nullable Context context, long sizeBytes, MeasureUnit unit, long mult) {
         if (context == null) {
             return "";
         }
-        final Formatter.BytesResult res =
-                formatBytes(context.getResources(), sizeBytes, suffix, mult);
-        return BidiFormatter.getInstance()
-                .unicodeWrap(context.getString(getFileSizeSuffix(context), res.value, res.units));
-    }
-
-    private static int getFileSizeSuffix(Context context) {
-        final Resources res = context.getResources();
-        return res.getIdentifier("fileSizeSuffix", "string", "android");
+        final RoundedBytesResult res = formatBytes(sizeBytes, unit, mult);
+        return bidiWrap(context, formatRoundedBytesResult(context, res));
     }
 
     /**
@@ -76,8 +136,8 @@
      * @param suffix String id for the unit suffix.
      * @param mult Amount of bytes in the unit.
      */
-    private static Formatter.BytesResult formatBytes(
-            Resources res, long sizeBytes, int suffix, long mult) {
+    private static RoundedBytesResult formatBytes(
+            long sizeBytes, MeasureUnit unit, long mult) {
         final boolean isNegative = (sizeBytes < 0);
         float result = isNegative ? -sizeBytes : sizeBytes;
         result = result / mult;
@@ -85,32 +145,29 @@
         // compute the rounded value. String.format("%f", 0.1) might not return "0.1" due to
         // floating point errors.
         final int roundFactor;
-        final String roundFormat;
+        final int roundDigits;
         if (mult == 1) {
             roundFactor = 1;
-            roundFormat = "%.0f";
+            roundDigits = 0;
         } else if (result < 1) {
             roundFactor = 100;
-            roundFormat = "%.2f";
+            roundDigits = 2;
         } else if (result < 10) {
             roundFactor = 10;
-            roundFormat = "%.1f";
+            roundDigits = 1;
         } else { // 10 <= result < 100
             roundFactor = 1;
-            roundFormat = "%.0f";
+            roundDigits = 0;
         }
 
         if (isNegative) {
             result = -result;
         }
-        final String roundedString = String.format(roundFormat, result);
 
         // Note this might overflow if abs(result) >= Long.MAX_VALUE / 100, but that's like 80PB so
         // it's okay (for now)...
         final long roundedBytes = (((long) Math.round(result * roundFactor)) * mult / roundFactor);
 
-        final String units = res.getString(suffix);
-
-        return new Formatter.BytesResult(roundedString, units, roundedBytes);
+        return new RoundedBytesResult(result, unit, roundDigits, roundedBytes);
     }
 }
diff --git a/src/com/android/settings/webview/WebViewAppPreferenceController.java b/src/com/android/settings/webview/WebViewAppPreferenceController.java
index 2f3246c..c774093 100644
--- a/src/com/android/settings/webview/WebViewAppPreferenceController.java
+++ b/src/com/android/settings/webview/WebViewAppPreferenceController.java
@@ -26,7 +26,6 @@
 
     private static final String WEBVIEW_APP_KEY = "select_webview_provider";
 
-    private final Context mContext;
     private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
     private Preference mPreference;
 
@@ -37,7 +36,6 @@
     public WebViewAppPreferenceController(Context context,
             WebViewUpdateServiceWrapper webviewUpdateServiceWrapper) {
         super(context);
-        mContext = context;
         mWebViewUpdateServiceWrapper = webviewUpdateServiceWrapper;
     }
 
diff --git a/src/com/android/settings/wifi/WifiInfoPreferenceController.java b/src/com/android/settings/wifi/WifiInfoPreferenceController.java
index 97c4fb9..ad6ecba 100644
--- a/src/com/android/settings/wifi/WifiInfoPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiInfoPreferenceController.java
@@ -22,6 +22,7 @@
 import android.content.IntentFilter;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
+import android.support.v4.text.BidiFormatter;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
@@ -104,7 +105,7 @@
             final String ipAddress = Utils.getWifiIpAddresses(mContext);
             mWifiIpAddressPref.setSummary(ipAddress == null
                     ? mContext.getString(R.string.status_unavailable)
-                    : ipAddress);
+                    : BidiFormatter.getInstance().unicodeWrap(ipAddress));
         }
     }
 
diff --git a/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java b/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java
new file mode 100644
index 0000000..81413d2
--- /dev/null
+++ b/src/com/android/settings/wifi/details/WifiDetailActionBarObserver.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 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.wifi.details;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import com.android.settings.R;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnCreate;
+
+/**
+ * ActionBar lifecycle observer for {@link WifiNetworkDetailsFragment}.
+ */
+public class WifiDetailActionBarObserver implements LifecycleObserver, OnCreate {
+
+    private final Fragment mFragment;
+    private final Context mContext;
+
+    public WifiDetailActionBarObserver(Context context, Fragment fragment) {
+        mContext = context;
+        mFragment = fragment;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        if (mFragment.getActivity() != null) {
+            mFragment.getActivity().getActionBar()
+                    .setTitle(mContext.getString(R.string.wifi_details_title));
+        }
+    }
+}
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index d624a7f..d8870a8 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -40,6 +40,7 @@
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.Handler;
+import android.support.v4.text.BidiFormatter;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceScreen;
@@ -441,7 +442,8 @@
         updatePreference(mDnsPref, dnsServers);
 
         if (ipv6Addresses.length() > 0) {
-            mIpv6AddressPref.setSummary(ipv6Addresses.toString());
+            mIpv6AddressPref.setSummary(
+                    BidiFormatter.getInstance().unicodeWrap(ipv6Addresses.toString()));
             mIpv6Category.setVisible(true);
         } else {
             mIpv6Category.setVisible(false);
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index 0016010..8145d77 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -21,15 +21,14 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
-
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.R;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.wifi.AccessPoint;
-
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -39,13 +38,18 @@
  * {@link AccessPoint#saveWifiState(Bundle)} in order to properly render this page.
  */
 public class WifiNetworkDetailsFragment extends DashboardFragment {
+
     private static final String TAG = "WifiNetworkDetailsFrg";
 
     private AccessPoint mAccessPoint;
     private WifiDetailPreferenceController mWifiDetailPreferenceController;
+    private WifiDetailActionBarObserver mWifiDetailActionBarObserver;
 
     @Override
     public void onAttach(Context context) {
+        mWifiDetailActionBarObserver = new WifiDetailActionBarObserver(context, this);
+        getLifecycle().addObserver(mWifiDetailActionBarObserver);
+
         mAccessPoint = new AccessPoint(context, getArguments());
         super.onAttach(context);
     }
@@ -78,8 +82,6 @@
                 context.getSystemService(WifiManager.class),
                 mMetricsFeatureProvider);
 
-        ArrayList<AbstractPreferenceController> controllers = new ArrayList(1);
-        controllers.add(mWifiDetailPreferenceController);
-        return controllers;
+        return new ArrayList<>(Collections.singletonList(mWifiDetailPreferenceController));
     }
 }
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index 109aa91..fa276d9 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -186,7 +186,8 @@
         final Activity activity = getActivity();
         mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
         if (mWifiP2pManager != null) {
-            mChannel = mWifiP2pManager.initialize(activity, getActivity().getMainLooper(), null);
+            mChannel = mWifiP2pManager.initialize(activity.getApplicationContext(),
+                    getActivity().getMainLooper(), null);
             if (mChannel == null) {
                 //Failure to set up connection
                 Log.e(TAG, "Failed to set up connection with wifi p2p service");
diff --git a/tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java b/tests/app/src/com/android/settings/applications/DefaultAppSettingsTest.java
similarity index 97%
rename from tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java
rename to tests/app/src/com/android/settings/applications/DefaultAppSettingsTest.java
index 1831b59..bd03bc9 100644
--- a/tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java
+++ b/tests/app/src/com/android/settings/applications/DefaultAppSettingsTest.java
@@ -32,7 +32,7 @@
  * Test for Advanced App preferences.
  */
 @SmallTest
-public class AdvancedAppSettingsTest extends InstrumentationTestCase {
+public class DefaultAppSettingsTest extends InstrumentationTestCase {
 
     private UiDevice mDevice;
     private Context mTargetContext;
diff --git a/tests/robotests/src/com/android/settings/MasterClearTest.java b/tests/robotests/src/com/android/settings/MasterClearTest.java
index d913946..8e8578f 100644
--- a/tests/robotests/src/com/android/settings/MasterClearTest.java
+++ b/tests/robotests/src/com/android/settings/MasterClearTest.java
@@ -92,55 +92,32 @@
     @Test
     public void testShowWipeEuicc_euiccDisabled() {
         prepareEuiccState(
-                false /* isEuiccEnabled */, true /* isEuiccProvisioned */,
-                true /* isDevelopmentSettingsEnabled */);
+                false /* isEuiccEnabled */, true /* isEuiccProvisioned */);
         assertThat(mMasterClear.showWipeEuicc()).isFalse();
     }
 
     @Test
     public void testShowWipeEuicc_euiccEnabled_unprovisioned() {
         prepareEuiccState(
-                true /* isEuiccEnabled */, false /* isEuiccProvisioned */,
-                false /* isDevelopmentSettingsEnabled */);
+                true /* isEuiccEnabled */, false /* isEuiccProvisioned */);
         assertThat(mMasterClear.showWipeEuicc()).isFalse();
     }
 
     @Test
     public void testShowWipeEuicc_euiccEnabled_provisioned() {
         prepareEuiccState(
-                true /* isEuiccEnabled */, true /* isEuiccProvisioned */,
-                false /* isDevelopmentSettingsEnabled */);
-        assertThat(mMasterClear.showWipeEuicc()).isTrue();
-    }
-
-    @Test
-    public void testShowWipeEuicc_euiccEnabled_developmentSettingsEnabled() {
-        prepareEuiccState(
-                true /* isEuiccEnabled */, false /* isEuiccProvisioned */,
-                true /* isDevelopmentSettingsEnabled */);
-        assertThat(mMasterClear.showWipeEuicc()).isTrue();
-    }
-
-    @Test
-    public void testShowWipeEuicc_euiccEnabled_provisioned_developmentSettingsEnabled() {
-        prepareEuiccState(
-                true /* isEuiccEnabled */, true /* isEuiccProvisioned */,
-                true /* isDevelopmentSettingsEnabled */);
+                true /* isEuiccEnabled */, true /* isEuiccProvisioned */);
         assertThat(mMasterClear.showWipeEuicc()).isTrue();
     }
 
     private void prepareEuiccState(
             boolean isEuiccEnabled,
-            boolean isEuiccProvisioned,
-            boolean isDevelopmentSettingsEnabled) {
+            boolean isEuiccProvisioned) {
         doReturn(mActivity).when(mMasterClear).getContext();
         doReturn(isEuiccEnabled).when(mMasterClear).isEuiccEnabled(any());
         ContentResolver cr = mActivity.getContentResolver();
         Settings.Global.putInt(
                 cr, android.provider.Settings.Global.EUICC_PROVISIONED, isEuiccProvisioned ? 1 : 0);
-        Settings.Global.putInt(
-                cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
-                isDevelopmentSettingsEnabled ? 1 : 0);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/AdvancedAppSettingsTest.java b/tests/robotests/src/com/android/settings/applications/DefaultAppSettingsTest.java
similarity index 93%
rename from tests/robotests/src/com/android/settings/applications/AdvancedAppSettingsTest.java
rename to tests/robotests/src/com/android/settings/applications/DefaultAppSettingsTest.java
index 968421b..9054a8e 100644
--- a/tests/robotests/src/com/android/settings/applications/AdvancedAppSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/DefaultAppSettingsTest.java
@@ -16,18 +16,29 @@
 
 package com.android.settings.applications;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.os.UserManager;
 import android.telephony.TelephonyManager;
 
 import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
 import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
 import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.XmlTestUtils;
 
 import org.junit.Before;
@@ -40,31 +51,19 @@
 
 import java.util.List;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class AdvancedAppSettingsTest {
+public class DefaultAppSettingsTest {
 
     private Context mContext;
 
-    private AdvancedAppSettings mFragment;
+    private DefaultAppSettings mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-
         mContext = RuntimeEnvironment.application;
-        mFragment = new AdvancedAppSettings();
+        mFragment = new DefaultAppSettings();
         mFragment.onAttach(mContext);
     }
 
@@ -77,8 +76,8 @@
     @Test
     public void setListening_shouldUpdateSummary() {
         final SummaryLoader summaryLoader = mock(SummaryLoader.class);
-        final AdvancedAppSettings.SummaryProvider summaryProvider =
-                new AdvancedAppSettings.SummaryProvider(mContext, summaryLoader);
+        final DefaultAppSettings.SummaryProvider summaryProvider =
+                new DefaultAppSettings.SummaryProvider(mContext, summaryLoader);
         final DefaultSmsPreferenceController defaultSms =
                 mock(DefaultSmsPreferenceController.class);
         final DefaultBrowserPreferenceController defaultBrowser =
@@ -149,6 +148,7 @@
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = spy(RuntimeEnvironment.application);
         final Context mockContext = mock(Context.class);
+        when(mockContext.getApplicationContext()).thenReturn(mockContext);
         final UserManager userManager = mock(UserManager.class, RETURNS_DEEP_STUBS);
 
         when(mockContext.getSystemService(Context.USER_SERVICE))
@@ -159,10 +159,10 @@
                 .thenReturn(mock(TelephonyManager.class));
         when(mockContext.getPackageManager())
                 .thenReturn(mock(PackageManager.class));
-        final List<String> niks = AdvancedAppSettings.SEARCH_INDEX_DATA_PROVIDER
+        final List<String> niks = DefaultAppSettings.SEARCH_INDEX_DATA_PROVIDER
                 .getNonIndexableKeys(mockContext);
 
-        final int xmlId = (new AdvancedAppSettings()).getPreferenceScreenResId();
+        final int xmlId = (new DefaultAppSettings()).getPreferenceScreenResId();
 
         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
 
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
index f382b90..180abbb 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
@@ -16,6 +16,16 @@
 
 package com.android.settings.applications.assist;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
 import android.Manifest;
 import android.app.SearchManager;
 import android.content.ComponentName;
@@ -28,33 +38,29 @@
 import android.content.pm.ServiceInfo;
 import android.provider.Settings;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.internal.app.AssistUtils;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.defaultapps.DefaultAppInfo;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.shadow.ShadowSecureSettings;
 
-import java.util.ArrayList;
-import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
+import java.util.ArrayList;
+import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DefaultAssistPreferenceControllerTest {
 
+    private static final String TEST_KEY = "test_pref_key";
+
     @Mock
     private Context mContext;
     @Mock
@@ -66,7 +72,8 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mController = new DefaultAssistPreferenceController(mContext);
+        mController = new DefaultAssistPreferenceController(mContext, TEST_KEY,
+                true /* showSetting */);
     }
 
     @Test
@@ -75,6 +82,12 @@
     }
 
     @Test
+    public void getPrefKey_shouldReturnKey() {
+        assertThat(mController.getPreferenceKey())
+                .isEqualTo(TEST_KEY);
+    }
+
+    @Test
     @Config(shadows = {ShadowSecureSettings.class})
     public void getDefaultAppInfo_hasDefaultAssist_shouldReturnKey() {
         final String flattenKey = "com.android.settings/assist";
@@ -89,15 +102,15 @@
         final String flattenKey = "com.android.settings/assist";
         Settings.Secure.putString(null, Settings.Secure.ASSISTANT, flattenKey);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
-        DefaultAssistPreferenceController controller =
-            spy(new DefaultAssistPreferenceController(mContext));
+        DefaultAssistPreferenceController controller = spy(
+                new DefaultAssistPreferenceController(mContext, TEST_KEY, true /* showSetting */));
         final ResolveInfo resolveInfo = new ResolveInfo();
         resolveInfo.activityInfo = new ActivityInfo();
         resolveInfo.activityInfo.name = "assist";
         resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
         resolveInfo.activityInfo.applicationInfo.packageName = "com.android.settings";
         when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), anyInt()))
-            .thenReturn(resolveInfo);
+                .thenReturn(resolveInfo);
         when(mContext.getSystemService(Context.SEARCH_SERVICE)).thenReturn(mSearchManager);
         when(mSearchManager.getAssistIntent(anyBoolean())).thenReturn(mock(Intent.class));
         final ServiceInfo serviceInfo = new ServiceInfo();
@@ -107,9 +120,21 @@
         services.add(resolveInfo);
         when(mPackageManager.queryIntentServices(any(Intent.class), anyInt())).thenReturn(services);
         doReturn(null).when(controller).getAssistSettingsActivity(
-            ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
+                ComponentName.unflattenFromString(flattenKey), resolveInfo, mPackageManager);
 
         controller.getSettingIntent(null);
         // should not crash
     }
+
+    @Test
+    public void getSettingIntent_doNotShowSetting_shouldNotTryToGetSettingIntent() {
+        final AssistUtils assistUtils = mock(AssistUtils.class);
+        final DefaultAssistPreferenceController controller = new DefaultAssistPreferenceController(
+                mContext, TEST_KEY, false /* showSetting */);
+        ReflectionHelpers.setField(controller, "mAssistUtils", assistUtils);
+
+        controller.getSettingIntent(null);
+
+        verifyZeroInteractions(assistUtils);
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
index d7e5192..22b30bd 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultHomePreferenceControllerTest.java
@@ -17,14 +17,22 @@
 package com.android.settings.applications.defaultapps;
 
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyList;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.content.ComponentName;
 import android.content.Context;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.applications.PackageManagerWrapper;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -35,14 +43,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyList;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DefaultHomePreferenceControllerTest {
@@ -79,11 +79,10 @@
 
     @Test
     public void updateState_noDefaultApp_shouldAskPackageManagerForOnlyApp() {
-        doReturn(null).when(mController).getDefaultAppInfo();
-
+        when(mPackageManager.getHomeActivities(anyList())).thenReturn(null);
         mController.updateState(mock(Preference.class));
 
-        verify(mPackageManager).getHomeActivities(anyList());
+        verify(mPackageManager, atLeastOnce()).getHomeActivities(anyList());
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceControllerTest.java
new file mode 100644
index 0000000..6a73269
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultPaymentSettingsPreferenceControllerTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 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.applications.defaultapps;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.nfc.NfcAdapter;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.nfc.PaymentBackend;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DefaultPaymentSettingsPreferenceControllerTest {
+
+    @Mock
+    private NfcAdapter mNfcAdapter;
+    @Mock
+    private Context mContext;
+    @Mock
+    private UserManager mUserManager;
+    @Mock
+    private PackageManager mPackageManager;
+    @Mock
+    private PaymentBackend mPaymentBackend;
+
+    private DefaultPaymentSettingsPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        when(mContext.getApplicationContext()).thenReturn(mContext);
+        when(mContext.getPackageManager()).thenReturn(mPackageManager);
+        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+        mController = new DefaultPaymentSettingsPreferenceController(mContext);
+        ReflectionHelpers.setField(mController, "mNfcAdapter", mNfcAdapter);
+
+        mPreference = new Preference(RuntimeEnvironment.application);
+    }
+
+    @Test
+    public void isAvailable_hasNfc_shouldReturnTrue() {
+        when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        when(mNfcAdapter.isEnabled()).thenReturn(true);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void isAvailable_noNfcAdapter_shouldReturnFalse() {
+        when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
+        when(mUserManager.isAdminUser()).thenReturn(true);
+        ReflectionHelpers.setField(mController, "mNfcAdapter", null);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void updateState_shouldSetSummaryToDefaultPaymentApp() {
+        final PaymentBackend.PaymentAppInfo defaultApp = mock(PaymentBackend.PaymentAppInfo.class);
+        defaultApp.label = "test_payment_app";
+        when(mPaymentBackend.getDefaultApp()).thenReturn(defaultApp);
+        ReflectionHelpers.setField(mController, "mPaymentBackend", mPaymentBackend);
+
+        mController.updateState(mPreference);
+
+        verify(mPaymentBackend).refresh();
+        assertThat(mPreference.getSummary()).isEqualTo(defaultApp.label);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 2d64396..74c47e2 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -24,6 +24,7 @@
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.widget.MasterSwitchController;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
 import com.android.settingslib.bluetooth.LocalBluetoothManager;
 
 import org.junit.Before;
@@ -58,17 +59,22 @@
     private MasterSwitchController mMasterSwitchController;
     @Mock
     private RestrictionUtils mRestrictionUtils;
+    @Mock
+    private LocalBluetoothManager mBluetoothManager;
+    @Mock
+    private LocalBluetoothAdapter mBluetoothAdapter;
 
     private BluetoothEnabler mBluetoothEnabler;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
         mBluetoothEnabler = new BluetoothEnabler(
                 mContext,
                 mMasterSwitchController,
                 mMetricsFeatureProvider,
-                mock(LocalBluetoothManager.class),
+                mBluetoothManager,
                 123,
                 mRestrictionUtils);
     }
@@ -136,4 +142,17 @@
         verify(mMasterSwitchController).setChecked(false);
     }
 
+    @Test
+    public void maybeEnforceRestrictions_disallowBluetoothNotOverriden() {
+        // GIVEN Bluetooth has been disallowed...
+        when(mRestrictionUtils.checkIfRestrictionEnforced(
+                mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN);
+        when(mRestrictionUtils.checkIfRestrictionEnforced(
+                mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null);
+
+        mBluetoothEnabler.resume(mContext);
+
+        verify(mMasterSwitchController, never()).setEnabled(true);
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index 1fc4536..d78cff6 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -21,6 +21,7 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.drawable.Icon;
+import android.os.Bundle;
 import android.support.v7.widget.RecyclerView;
 import android.util.DisplayMetrics;
 import android.view.LayoutInflater;
@@ -32,6 +33,7 @@
 import com.android.settings.SettingsActivity;
 import com.android.settings.TestConfig;
 import com.android.settings.dashboard.conditional.Condition;
+import com.android.settings.dashboard.conditional.ConditionAdapter;
 import com.android.settings.dashboard.suggestions.SuggestionAdapter;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -93,6 +95,7 @@
     private DashboardAdapter mDashboardAdapter;
     private DashboardAdapter.SuggestionAndConditionHeaderHolder mSuggestionHolder;
     private DashboardData.SuggestionConditionHeaderData mSuggestionHeaderData;
+    private List<Condition> mConditionList;
 
     @Before
     public void setUp() {
@@ -111,10 +114,11 @@
         when(mResources.getQuantityString(any(int.class), any(int.class), any()))
                 .thenReturn("");
 
-        List<Condition> conditions = new ArrayList<>();
-        conditions.add(mCondition);
-        mDashboardAdapter = new DashboardAdapter(mContext, null, conditions, null, null);
-        mSuggestionHeaderData = new DashboardData.SuggestionConditionHeaderData(conditions, 1);
+        mConditionList = new ArrayList<>();
+        mConditionList.add(mCondition);
+        when(mCondition.shouldShow()).thenReturn(true);
+        mDashboardAdapter = new DashboardAdapter(mContext, null, mConditionList, null, null);
+        mSuggestionHeaderData = new DashboardData.SuggestionConditionHeaderData(mConditionList, 1);
         when(mView.getTag()).thenReturn(mCondition);
     }
 
@@ -408,6 +412,36 @@
         // should not crash
     }
 
+    @Test
+    public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
+        final Bundle savedInstance = new Bundle();
+        savedInstance.putInt(DashboardAdapter.STATE_SUGGESTION_CONDITION_MODE,
+                DashboardData.HEADER_MODE_FULLY_EXPANDED);
+        mDashboardAdapter = new DashboardAdapter(mContext, savedInstance, mConditionList,
+                null /* SuggestionParser */, null /* SuggestionDismissController.Callback */);
+
+        final List<Tile> suggestions = new ArrayList<>();
+        final DashboardCategory category = mock(DashboardCategory.class);
+        final List<Tile> tiles = new ArrayList<>();
+        tiles.add(mock(Tile.class));
+        category.tiles = tiles;
+        mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
+
+        final RecyclerView data = mock(RecyclerView.class);
+        when(data.getResources()).thenReturn(mResources);
+        when(data.getContext()).thenReturn(mContext);
+        when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
+        final View itemView = mock(View.class);
+        when(itemView.findViewById(R.id.data)).thenReturn(data);
+        final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
+                new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
+
+        mDashboardAdapter.onBindConditionAndSuggestion(
+                holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
+
+        verify(data).setAdapter(any(ConditionAdapter.class));
+    }
+
     private List<Tile> makeSuggestions(String... pkgNames) {
         final List<Tile> suggestions = new ArrayList<>();
         for (String pkgName : pkgNames) {
diff --git a/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
index f0412d6..c651132 100644
--- a/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/conditional/ConditionAdapterTest.java
@@ -16,6 +16,7 @@
 package com.android.settings.dashboard.conditional;
 
 import android.content.Context;
+import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.LinearLayout;
@@ -130,4 +131,20 @@
         verify(mCondition1).onPrimaryClick();
     }
 
+    @Test
+    public void onSwiped_nullCondition_shouldNotCrash() {
+        final RecyclerView recyclerView = new RecyclerView(mContext);
+        final View view = LayoutInflater.from(mContext).inflate(
+                R.layout.condition_tile_new_ui, new LinearLayout(mContext), true);
+        final DashboardAdapter.DashboardItemHolder viewHolder =
+                new DashboardAdapter.DashboardItemHolder(view);
+        mConditionAdapter = new ConditionAdapter(
+                mContext, mOneCondition, DashboardData.HEADER_MODE_SUGGESTION_EXPANDED);
+        mConditionAdapter.addDismissHandling(recyclerView);
+
+        // do not bind viewholder to simulate the null condition scenario
+        mConditionAdapter.mSwipeCallback.onSwiped(viewHolder, 0);
+        // no crash
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/datausage/DataPlansSyncTimePreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/DataPlansSyncTimePreferenceTest.java
new file mode 100644
index 0000000..ba2d5f1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datausage/DataPlansSyncTimePreferenceTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 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.datausage;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class DataPlansSyncTimePreferenceTest {
+    private static final String SYNC_TIME = "Today 12:24pm";
+
+    private Preference mPreference;
+    private PreferenceViewHolder mHolder;
+
+    @Before
+    public void setUp() {
+        Context context = RuntimeEnvironment.application;
+        mPreference = new Preference(context);
+        mPreference.setLayoutResource(R.layout.data_plans_sync_time_preference);
+
+        LayoutInflater inflater = LayoutInflater.from(context);
+        View view = inflater.inflate(mPreference.getLayoutResource(),
+                new LinearLayout(context), false);
+        mHolder = PreferenceViewHolder.createInstanceForTests(view);
+    }
+
+    @Test
+    public void shouldRender_withData() {
+        mPreference.setTitle(SYNC_TIME);
+
+        mPreference.onBindViewHolder(mHolder);
+
+        TextView syncTimeTextView = (TextView) mHolder.findViewById(android.R.id.title);
+        assertThat(syncTimeTextView.getText()).isEqualTo(SYNC_TIME);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 77e0fe9..13e3aee 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -95,60 +95,6 @@
     }
 
     @Test
-    public void testIsMetered_noSsid_shouldReturnFalse() {
-        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
-        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
-        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
-        WifiConfiguration config = mock(WifiConfiguration.class);
-
-        assertThat(dataUsageSummary.isMetered(config)).isFalse();
-    }
-
-    @Test
-    public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
-        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
-        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
-        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
-        WifiConfiguration config = mock(WifiConfiguration.class);
-        config.SSID = "network1";
-        doReturn(null).when(policyEditor).getPolicyMaybeUnquoted(any());
-
-        assertThat(dataUsageSummary.isMetered(config)).isFalse();
-    }
-
-    @Test
-    public void testIsMetered_policyHasLimit_shouldReturnTrue() {
-        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
-        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
-        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
-        WifiConfiguration config = mock(WifiConfiguration.class);
-        config.SSID = "network1";
-        NetworkPolicy policy = mock(NetworkPolicy.class);
-        policy.limitBytes = 100;
-        doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
-
-        assertThat(dataUsageSummary.isMetered(config)).isTrue();
-    }
-
-    @Test
-    public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
-        final DataUsageSummary dataUsageSummary = new DataUsageSummary();
-        final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
-        ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
-        WifiConfiguration config = mock(WifiConfiguration.class);
-        config.SSID = "network1";
-        NetworkPolicy policy = mock(NetworkPolicy.class);
-        policy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
-        doReturn(policy).when(policyEditor).getPolicyMaybeUnquoted(any());
-
-        policy.metered = true;
-        assertThat(dataUsageSummary.isMetered(config)).isTrue();
-
-        policy.metered = false;
-        assertThat(dataUsageSummary.isMetered(config)).isFalse();
-    }
-
-    @Test
     public void testNonIndexableKeys_existInXmlLayout() {
         final Context context = RuntimeEnvironment.application;
         final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
diff --git a/tests/robotests/src/com/android/settings/datausage/ManageDataPlansPreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/ManageDataPlansPreferenceTest.java
new file mode 100644
index 0000000..6eff393
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datausage/ManageDataPlansPreferenceTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2017 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.datausage;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class ManageDataPlansPreferenceTest {
+    private Preference mPreference;
+    private PreferenceViewHolder mHolder;
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        mContext = RuntimeEnvironment.application;
+        mPreference = new Preference(mContext);
+        mPreference.setLayoutResource(R.layout.manage_data_plans_preference);
+        LayoutInflater inflater = LayoutInflater.from(mContext);
+        View view = inflater.inflate(mPreference.getLayoutResource(),
+                new LinearLayout(mContext), false);
+        mHolder = PreferenceViewHolder.createInstanceForTests(view);
+    }
+
+    @Test
+    public void shouldRender_withData() {
+        mPreference.onBindViewHolder(mHolder);
+        Button managePlanButton = (Button) mHolder.findViewById(R.id.manage_data_plans);
+        assertThat(managePlanButton.getText())
+                .isEqualTo(mContext.getString(R.string.data_plan_usage_manage_plans_button_text));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java
index c937841..223f98d 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentSettingsEnablerTest.java
@@ -16,12 +16,14 @@
 
 package com.android.settings.development;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.provider.Settings;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -33,8 +35,6 @@
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class DevelopmentSettingsEnablerTest {
@@ -53,6 +53,16 @@
     }
 
     @Test
+    public void constructor_shouldInitEnabledState() {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
+
+        mEnabler = new DevelopmentSettingsEnabler(mContext, null);
+
+        assertThat(mEnabler.getLastEnabledState()).isTrue();
+    }
+
+    @Test
     public void onResume_shouldReadStateFromSettingProvider() {
         Settings.Global.putInt(mContext.getContentResolver(),
                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java
index a154c03..5b34c7d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageItemPreferenceTest.java
@@ -55,7 +55,7 @@
     @Test
     public void testAfterLoad() {
         mPreference.setStorageSize(MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 100);
-        assertThat(((String) mPreference.getSummary())).isEqualTo("0.01GB");
+        assertThat(((String) mPreference.getSummary())).isEqualTo("0.01 GB");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
index fcda085..a871c19 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java
@@ -104,7 +104,7 @@
         verify(mGroup).addPreference(argumentCaptor.capture());
 
         Preference preference = argumentCaptor.getValue();
-        assertThat(preference.getSummary()).isEqualTo("0.01GB");
+        assertThat(preference.getSummary()).isEqualTo("0.01 GB");
     }
 
     @Test
@@ -177,7 +177,7 @@
         verify(mGroup).addPreference(argumentCaptor.capture());
         Preference preference = argumentCaptor.getValue();
 
-        assertThat(preference.getSummary()).isEqualTo("0.03GB");
+        assertThat(preference.getSummary()).isEqualTo("0.03 GB");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index 0d6a4d7..1599440 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -84,8 +84,6 @@
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        SettingsShadowResources.overrideResource("android:string/fileSizeSuffix", "%1$s %2$s");
-        SettingsShadowResources.overrideResource("android:string/gigabyteShort", "GB");
         mContext = spy(RuntimeEnvironment.application.getApplicationContext());
         FakeFeatureFactory.setupForTest(mContext);
         mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
@@ -287,12 +285,12 @@
         results.put(0, result);
         mController.onLoadFinished(results, 0);
 
-        assertThat(audio.getSummary().toString()).isEqualTo("0.14GB");
-        assertThat(image.getSummary().toString()).isEqualTo("0.35GB");
-        assertThat(games.getSummary().toString()).isEqualTo("0.08GB");
-        assertThat(movies.getSummary().toString()).isEqualTo("0.16GB");
-        assertThat(apps.getSummary().toString()).isEqualTo("0.09GB");
-        assertThat(files.getSummary().toString()).isEqualTo("0.05GB");
+        assertThat(audio.getSummary().toString()).isEqualTo("0.14 GB");
+        assertThat(image.getSummary().toString()).isEqualTo("0.35 GB");
+        assertThat(games.getSummary().toString()).isEqualTo("0.08 GB");
+        assertThat(movies.getSummary().toString()).isEqualTo("0.16 GB");
+        assertThat(apps.getSummary().toString()).isEqualTo("0.09 GB");
+        assertThat(files.getSummary().toString()).isEqualTo("0.05 GB");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
index db7c9f7..a2e57b9 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/UserProfileControllerTest.java
@@ -122,7 +122,7 @@
         verify(mScreen).addPreference(argumentCaptor.capture());
         Preference preference = argumentCaptor.getValue();
 
-        assertThat(preference.getSummary()).isEqualTo("0.10GB");
+        assertThat(preference.getSummary()).isEqualTo("0.10 GB");
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
index 4f8f222..0d03512 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHistoryPreferenceTest.java
@@ -97,6 +97,7 @@
         TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
         assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
         assertThat(view.getText()).isEqualTo(TEST_STRING);
+        assertThat(mBatteryHistoryPreference.hideSummary).isFalse();
     }
 
     @Test
@@ -107,5 +108,6 @@
         TextView view = (TextView) mViewHolder.findViewById(R.id.bottom_summary);
         assertThat(view.getVisibility()).isEqualTo(View.GONE);
         assertThat(view.getText()).isEqualTo("");
+        assertThat(mBatteryHistoryPreference.hideSummary).isTrue();
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index c5e4707..796e63c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
@@ -30,6 +30,7 @@
 import android.os.BatteryStats;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.TestConfig;
+import com.android.settings.testutils.BatteryTestUtils;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import org.junit.Before;
@@ -64,12 +65,7 @@
                 .setupForTest(mContext)
                 .getPowerUsageFeatureProvider(mContext);
 
-        mDisChargingBatteryBroadcast = new Intent();
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 0);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
-                BatteryManager.BATTERY_STATUS_FULL);
+        mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
 
         doReturn(mContext).when(mContext).getApplicationContext();
         when(mStats.computeBatteryTimeRemaining(anyLong())).thenReturn(TEST_TIME_REMAINING);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index 24d1bf9..9bd0b6f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -39,6 +39,7 @@
 
 import com.android.settings.TestConfig;
 import com.android.settings.graph.UsageView;
+import com.android.settings.testutils.BatteryTestUtils;
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
@@ -63,6 +64,7 @@
     private static final String STATUS_FULL = "Full";
     private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
     private static final String STATUS_CHARGING_TIME = "50% - 0m until fully charged";
+    private static final String STATUS_NOT_CHARGING = "Not charging";
     private static final int PLUGGED_IN = 1;
     private static final long REMAINING_TIME_NULL = -1;
     private static final long REMAINING_TIME = 2;
@@ -87,20 +89,9 @@
         mContext = spy(RuntimeEnvironment.application);
         mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
 
-        mDisChargingBatteryBroadcast = new Intent();
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED, 0);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 0);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
-        mDisChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
-                BatteryManager.BATTERY_STATUS_FULL);
+        mDisChargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
 
-        mChargingBatteryBroadcast = new Intent();
-        mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_PLUGGED,
-                BatteryManager.BATTERY_PLUGGED_AC);
-        mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 50);
-        mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_SCALE, 100);
-        mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_STATUS,
-                BatteryManager.BATTERY_STATUS_UNKNOWN);
+        mChargingBatteryBroadcast = BatteryTestUtils.getChargingIntent();
     }
 
     @Test
@@ -110,7 +101,7 @@
                 mDisChargingBatteryBroadcast, mBatteryStats, SystemClock.elapsedRealtime() * 1000,
                 true /* shortString */);
 
-        assertThat(info.statusLabel).isEqualTo(STATUS_FULL);
+        assertThat(info.statusLabel).isEqualTo(STATUS_NOT_CHARGING);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index aa8607f..bf89cac 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -20,6 +20,7 @@
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
@@ -28,16 +29,19 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.UserManager;
 import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceGroup;
 import android.support.v7.preference.PreferenceManager;
 
+import android.view.View;
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatterySipper.DrainType;
 import com.android.internal.os.BatteryStatsHelper;
 import com.android.settings.R;
+import com.android.settings.testutils.BatteryTestUtils;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.Utils;
@@ -90,11 +94,12 @@
     private PowerUsageAdvanced mPowerUsageAdvanced;
     private PowerUsageData mPowerUsageData;
     private Context mShadowContext;
+    private Intent mDischargingBatteryIntent;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mShadowContext = RuntimeEnvironment.application;
+        mShadowContext = spy(RuntimeEnvironment.application);
         mPowerUsageAdvanced = spy(new PowerUsageAdvanced());
 
         List<BatterySipper> batterySippers = new ArrayList<>();
@@ -107,6 +112,8 @@
         batterySippers.add(new BatterySipper(DrainType.WIFI, new FakeUid(FAKE_UID_1),
                 TYPE_WIFI_USAGE));
 
+        mDischargingBatteryIntent = BatteryTestUtils.getDischargingIntent();
+        doReturn(mDischargingBatteryIntent).when(mShadowContext).registerReceiver(any(), any());
         when(mBatteryStatsHelper.getStats().getDischargeAmount(anyInt())).thenReturn(
                 DISCHARGE_AMOUNT);
         when(mBatteryStatsHelper.getUsageList()).thenReturn(batterySippers);
diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
new file mode 100644
index 0000000..a76aebc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryCursorLoaderTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2017 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.inputmethod;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.net.Uri;
+import android.provider.UserDictionary;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowContentResolver;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class UserDictionaryCursorLoaderTest {
+
+    private ContentProvider mContentProvider;
+    private UserDictionaryCursorLoader mLoader;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContentProvider = new FakeProvider();
+        mLoader = new UserDictionaryCursorLoader(RuntimeEnvironment.application, "" /* locale */);
+        ShadowContentResolver.registerProvider(UserDictionary.AUTHORITY, mContentProvider);
+    }
+
+    @Test
+    public void testLoad_shouldRemoveDuplicate() {
+        final Cursor cursor = mLoader.loadInBackground();
+
+        assertThat(cursor.getCount()).isEqualTo(4);
+    }
+
+    public static class FakeProvider extends ContentProvider {
+
+
+        @Override
+        public boolean onCreate() {
+            return false;
+        }
+
+        @Override
+        public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+                String sortOrder) {
+            final MatrixCursor cursor = new MatrixCursor(
+                    UserDictionaryCursorLoader.QUERY_PROJECTION);
+            cursor.addRow(new Object[]{1, "word1", "shortcut1"});
+            cursor.addRow(new Object[]{2, "word2", "shortcut2"});
+            cursor.addRow(new Object[]{3, "word3", "shortcut3"});
+            cursor.addRow(new Object[]{4, "word3", "shortcut3"});   // dupe of 3
+            cursor.addRow(new Object[]{5, "word5", null});          // no shortcut
+            return cursor;
+        }
+
+        @Override
+        public String getType(Uri uri) {
+            return null;
+        }
+
+        @Override
+        public Uri insert(Uri uri, ContentValues values) {
+            return null;
+        }
+
+        @Override
+        public int delete(Uri uri, String selection, String[] selectionArgs) {
+            return 0;
+        }
+
+        @Override
+        public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+            return 0;
+        }
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
index 3fc99d2..fd1f722 100644
--- a/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/UserDictionaryPreferenceControllerTest.java
@@ -16,15 +16,16 @@
 
 package com.android.settings.language;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import android.content.Context;
-import android.speech.tts.TtsEngines;
 import android.support.v7.preference.Preference;
 
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
-import com.android.settings.UserDictionarySettings;
 import com.android.settings.inputmethod.UserDictionaryList;
+import com.android.settings.inputmethod.UserDictionarySettings;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -37,16 +38,12 @@
 
 import java.util.TreeSet;
 
-import static com.google.common.truth.Truth.assertThat;
-
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
 public class UserDictionaryPreferenceControllerTest {
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
-    @Mock
-    private TtsEngines mTtsEngines;
     private Preference mPreference;
     private TestController mController;
 
diff --git a/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
new file mode 100644
index 0000000..2bdab27
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 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.testutils;
+
+import android.content.Intent;
+import android.os.BatteryManager;
+
+public class BatteryTestUtils {
+
+    public static Intent getChargingIntent() {
+        return getCustomBatteryIntent(
+                BatteryManager.BATTERY_PLUGGED_AC,
+                50 /* level */,
+                100 /* scale */,
+                BatteryManager.BATTERY_STATUS_CHARGING);
+    }
+
+    public static Intent getDischargingIntent() {
+        return getCustomBatteryIntent(
+                0 /* plugged */,
+                10 /* level */,
+                100 /* scale */,
+                BatteryManager.BATTERY_STATUS_DISCHARGING);
+    }
+
+    public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
+        Intent intent = new Intent();
+        intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
+        intent.putExtra(BatteryManager.EXTRA_LEVEL, level);
+        intent.putExtra(BatteryManager.EXTRA_SCALE, scale);
+        intent.putExtra(BatteryManager.EXTRA_STATUS, status);
+
+        return intent;
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java
new file mode 100644
index 0000000..c573d3c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailActionBarObserverTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 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.wifi.details;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WifiDetailActionBarObserverTest {
+
+    @Mock private Bundle mockBundle;
+    @Mock private Activity mockActivity;
+    @Mock private ActionBar mockActionBar;
+    @Mock private WifiNetworkDetailsFragment mockFragment;
+
+    private Context mContext = RuntimeEnvironment.application;
+    private Lifecycle mLifecycle;
+    private WifiDetailActionBarObserver mObserver;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mLifecycle = new Lifecycle();
+
+        when(mockFragment.getActivity()).thenReturn(mockActivity);
+        when(mockActivity.getActionBar()).thenReturn(mockActionBar);
+
+        mObserver = new WifiDetailActionBarObserver(mContext, mockFragment);
+        mLifecycle.addObserver(mObserver);
+    }
+
+    @Test
+    public void actionBarIsSetToNetworkInfo() {
+        mLifecycle.onCreate(mockBundle);
+
+        verify(mockActionBar).setTitle(mContext.getString(R.string.wifi_details_title));
+    }
+}
diff --git a/tests/unit/README b/tests/unit/README
index 5184b07..2544ea5 100644
--- a/tests/unit/README
+++ b/tests/unit/README
@@ -1,8 +1,8 @@
 To build the tests you can use the following command at the root of your android source tree
-$ make SettingsUnitTests
+$ make -j SettingsUnitTests
 
 The test apk then needs to be installed onto your test device via for example
-$ adb install -r out/target/product/shamu/data/app/SettingsUnitTests/SettingsUnitTests.apk
+$ adb install -r ${ANDROID_PRODUCT_OUT}/data/app/SettingsUnitTests/SettingsUnitTests.apk
 
 To run all tests:
 $ adb shell am instrument -w com.android.settings.tests.unit/android.support.test.runner.AndroidJUnitRunner
diff --git a/tests/unit/src/com/android/settings/utils/FileSizeFormatterTest.java b/tests/unit/src/com/android/settings/utils/FileSizeFormatterTest.java
index c5b050a..41b236c 100644
--- a/tests/unit/src/com/android/settings/utils/FileSizeFormatterTest.java
+++ b/tests/unit/src/com/android/settings/utils/FileSizeFormatterTest.java
@@ -22,6 +22,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import android.content.Context;
+import android.icu.util.MeasureUnit;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
@@ -46,7 +47,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 0 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("0.00 GB");
     }
@@ -57,7 +58,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 MEGABYTE_IN_BYTES * 11 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("0.01 GB");
     }
@@ -68,7 +69,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 MEGABYTE_IN_BYTES * 155 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("0.16 GB");
     }
@@ -79,7 +80,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 MEGABYTE_IN_BYTES * 1551 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("1.6 GB");
     }
@@ -91,7 +92,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 GIGABYTE_IN_BYTES * 15 + MEGABYTE_IN_BYTES * 50 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("15 GB");
     }
@@ -102,7 +103,7 @@
                         FileSizeFormatter.formatFileSize(
                                 mContext,
                                 MEGABYTE_IN_BYTES * -155 /* size */,
-                                com.android.internal.R.string.gigabyteShort,
+                                MeasureUnit.GIGABYTE,
                                 GIGABYTE_IN_BYTES))
                 .isEqualTo("-0.16 GB");
     }