Merge "Return back-up slices for unavailable settings" into pi-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c21eaba..ca30263 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -985,7 +985,7 @@
         </activity>
 
         <activity android:name=".Settings$MyDeviceInfoActivity"
-                  android:label="@string/device_info_settings"
+                  android:label="@string/about_settings"
                   android:icon="@drawable/ic_settings_about"
                   android:taskAffinity="com.android.settings"
                   android:parentActivityName="Settings">
@@ -2397,6 +2397,10 @@
             android:taskAffinity="com.android.settings"
             android:parentActivityName="Settings">
             <!-- TODO(b/70950124): add shortcut intent-filter -->
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.DATA_USAGE_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
             <intent-filter android:priority="10">
                 <action android:name="com.android.settings.action.SETTINGS" />
             </intent-filter>
@@ -2412,6 +2416,10 @@
             android:icon="@drawable/ic_settings_data_usage"
             android:taskAffinity="com.android.settings"
             android:parentActivityName="Settings">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.DATA_USAGE_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/res/layout/choose_lock_pattern_common_footer.xml b/res/layout/choose_lock_pattern_common_footer.xml
index d80702e..fc36624 100644
--- a/res/layout/choose_lock_pattern_common_footer.xml
+++ b/res/layout/choose_lock_pattern_common_footer.xml
@@ -22,7 +22,15 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
-    <!-- left : cancel, or re-try -->
+    <!-- left : skip -->
+    <Button android:id="@+id/skip_button"
+        style="@style/SuwGlifButton.Secondary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/skip_label"
+        android:visibility="gone" />
+
+    <!-- left : retry -->
     <Button android:id="@+id/footerLeftButton"
         style="@style/SuwGlifButton.Secondary"
         android:layout_width="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 512c214..8f82ae0 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -754,10 +754,14 @@
     <string name="date_time_set_date_title">Date</string>
     <!-- Date & time setting screen setting option title -->
     <string name="date_time_set_date">Set date</string>
+    <!-- Text hint to search region in time zone setting screen -->
+    <string name="date_time_search_region">Search region</string>
     <!-- Setting option title to select region in time zone setting screen [CHAR LIMIT=30] -->
     <string name="date_time_select_region">Region</string>
     <!-- Setting option title to select time zone in time zone setting screen [CHAR LIMIT=30]-->
     <string name="date_time_select_zone">Time Zone</string>
+    <!-- Setting option title to select time zone in a region -->
+    <string name="date_time_set_timezone_in_region">Time zones in <xliff:g id="region" example="United States">%1$s</xliff:g></string>
     <!-- Setting option title in time zone setting screen [CHAR LIMIT=30] -->
     <string name="date_time_select_fixed_offset_time_zones">Select UTC offset</string>
     <!-- Menu item on Select time zone screen -->
@@ -1153,7 +1157,7 @@
     <string name="suggested_lock_settings_summary" product="default">Set screen lock to protect phone</string>
 
     <!-- Title for suggested actions for settings up a fingerprint lock [CHAR LIMIT=46] -->
-    <string name="suggested_fingerprint_lock_settings_title">Unlock with fingerprint</string>
+    <string name="suggested_fingerprint_lock_settings_title">Add fingerprint to unlock</string>
 
     <!-- Summary for suggested actions for settings up a fingerprint lock (tablet) [CHAR LIMIT=55] -->
     <string name="suggested_fingerprint_lock_settings_summary" product="tablet"></string>
@@ -1903,6 +1907,14 @@
     <string name="wifi_more">More</string>
     <!-- Wi-Fi settings. wps menu title [CHAR LIMIT=25]-->
     <string name="wifi_setup_wps">Automatic setup (WPS)</string>
+    <!-- Wi-Fi settings dialog. Title of dialog displayed asking user to enable Wi-Fi Scanning [CHAR LIMIT=60]-->
+    <string name="wifi_settings_scanning_required_title">Turn on Wi\u2011Fi scanning?</string>
+    <!-- Wi-Fi settings dialog. Summary text describing why we need Wi-Fi scanning on. [CHAR LIMIT=NONE]-->
+    <string name="wifi_settings_scanning_required_summary">To turn on Wi\u2011Fi automatically, you first need to turn on Wi\u2011Fi scanning.</string>
+    <!-- Wi-Fi settings dialog. Informational text describing what Wi-Fi scanning does. [CHAR LIMIT=NONE]-->
+    <string name="wifi_settings_scanning_required_info">Wi\2011Fi scanning allows apps and services to scan for Wi\u2011Fi networks at any time, even when Wi\u2011Fi is off. This can be used, for example, to improve location\u2011based features and services.</string>
+    <!-- Wi-Fi settings dialog. Text for the button that takes users to a help article about Wi-Fi scanning. [CHAR LIMIT = 20]-->
+    <string name="wifi_settings_scanning_required_turn_on">Turn on</string>
 
     <!-- Dialog for Access Points --> <skip />
     <!-- Label to show/hide advanced options [CHAR LIMIT=40] -->
@@ -1917,6 +1929,10 @@
     <string name="wifi_ssid_hint">Enter the SSID</string>
     <!-- Label for the security of the connection -->
     <string name="wifi_security">Security</string>
+    <!-- Label for the hidden network status of this network -->
+    <string name="wifi_hidden_network">Hidden network</string>
+    <!-- Label for the warning shown to users if they try to connect to a network as "hidden" -->
+    <string name="wifi_hidden_network_warning">Hidden network might create privacy risk as this device has to broadcast this SSID name in order to connect.</string>
     <!-- Label for the signal strength of the connection -->
     <string name="wifi_signal">Signal strength</string>
     <!-- Label for the status of the connection -->
@@ -1956,7 +1972,11 @@
     <!-- Label for the radio button to choose wifi ap 2.4 GHz band -->
     <string name="wifi_ap_choose_2G">2.4 GHz Band</string>
     <!-- Label for the radio button to choose wifi ap 5GHz band -->
-    <string name="wifi_ap_choose_5G">5 GHz Band</string>
+    <string name="wifi_ap_choose_5G">5.0 GHz Band</string>
+    <!-- Label for adding to the list of selected bands when 2.4 GHz is selected -->
+    <string name="wifi_ap_2G">2.4 GHz</string>
+    <!-- Label for adding to the list of selected bands when 5.0 GHz is selected -->
+    <string name="wifi_ap_5G">5.0 GHz</string>
     <!-- Label for the spinner to show ip settings [CHAR LIMIT=25] -->
     <string name="wifi_ip_settings">IP settings</string>
     <!-- Label for the check box to share a network with other users on the same device -->
@@ -2441,6 +2461,12 @@
     <string name="color_mode_option_boosted">Boosted</string>
     <!-- Display settings screen, Color mode option for "Saturated color"  [CHAR LIMIT=45] -->
     <string name="color_mode_option_saturated">Saturated</string>
+    <!-- Display settings screen, Color mode option for "Automatic color"  [CHAR LIMIT=45] -->
+    <string name="color_mode_option_automatic">Automatic</string>
+    <!-- Display settings screen, "natural(sRGB) color" setting option summary [CHAR LIMIT=NONE] -->
+    <string name="color_mode_summary_natural">Use accurate colors only</string>
+    <!-- Display settings screen, "Automatic color" setting option summary [CHAR LIMIT=NONE] -->
+    <string name="color_mode_summary_automatic">Adjust between vivid and accurate colors</string>
 
     <!-- Sound & display settings screen, accelerometer-based rotation summary text when check box is selected -->
     <string name="accelerometer_summary_on" product="tablet">Switch orientation automatically when rotating tablet</string>
@@ -4456,6 +4482,24 @@
     <!-- Used in the Captions settings screen to control turning on/off the feature entirely -->
     <string name="accessibility_caption_master_switch_title">Use captions</string>
 
+    <!-- Title for the accessibility preference for hearing aid. [CHAR LIMIT=35] -->
+    <string name="accessibility_hearingaid_title">Hearing aids</string>
+    <!-- Summary for the accessibility preference for hearing aid when not connected. [CHAR LIMIT=50] -->
+    <string name="accessibility_hearingaid_not_connected_summary">No hearing aids connected</string>
+    <!-- Summary for the accessibility preference for hearing aid when adding new devices. [CHAR LIMIT=50] -->
+    <string name="accessibility_hearingaid_adding_summary">Add hearing aid</string>
+    <!-- Message to ask the user that if they want to pair the hearing aid, then they should find and tap the hearing aid device from the list on the next screen. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_hearingaid_pair_instructions_first_message">To pair your hearing aids, find and tap your device on the next screen.</string>
+    <!-- Message to ask the user to make sure that their hearing aid devices are in pairing mode. [CHAR LIMIT=NONE] -->
+    <string name="accessibility_hearingaid_pair_instructions_second_message">Make sure your hearing aids are in pairing mode.</string>
+    <!-- Summary for the accessibility preference for hearing aid when there is an active device. [CHAR LIMIT=50] -->
+    <string name="accessibility_hearingaid_active_device_summary"><xliff:g id="device_name">%1$s</xliff:g> currently active</string>
+    <!-- Summary for the accessibility preference for hearing aid when there are saved devices. [CHAR LIMIT=50] -->
+    <plurals name="show_number_hearingaid_count">
+        <item quantity="one"><xliff:g id="number_device_count">%1$d</xliff:g> saved hearing aid</item>
+        <item quantity="other"><xliff:g id="number_device_count">%1$d</xliff:g> saved hearing aids</item>
+    </plurals>
+
     <!-- Preference's state when enabled. -->
     <string name="accessibility_summary_state_enabled">On</string>
     <!-- Preference's state when disabled. -->
@@ -7940,11 +7984,13 @@
     <string name="change_storage">Change storage</string>
 
     <!-- Label for notification settings for an specific app [CHAR LIMIT=40] -->
-    <string name="notifications_label">App notifications</string>
+    <string name="notifications_label">Notifications</string>
     <!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
     <string name="notifications_enabled">On</string>
+    <!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
+    <string name="notifications_enabled_with_info">On / <xliff:g id="notifications_categories_off" example="3 categories turned off">%1$s</xliff:g> </string>
     <!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
-    <string name="notifications_disabled">Everything turned off</string>
+    <string name="notifications_disabled">Off</string>
     <!-- Label for showing apps with some blocked notifications in list [CHAR LIMIT=30] -->
     <string name="notifications_partly_blocked"><xliff:g id="count" example="1">%1$d</xliff:g> of <xliff:g id="count" example="10">%2$d</xliff:g> categories turned off</string>
     <!-- App notification summary with notifications silenced [CHAR LIMIT=40] -->
@@ -7962,6 +8008,11 @@
     <!-- App notification summary channel divider-->
     <string name="notification_summary_channel"><xliff:g id="channel_name">%1$s</xliff:g> \u2022 <xliff:g id="group_name">%2$s</xliff:g></string>
 
+    <!-- Permissions preference summary [CHAR LIMIT=40] -->
+    <plurals name="notifications_categories_off">
+        <item quantity="one"><xliff:g id="count" example="1">%d</xliff:g> category turned off</item>
+        <item quantity="other"><xliff:g id="count" example="10">%d</xliff:g> categories turned off</item>
+    </plurals>
 
     <!-- Permissions preference summary [CHAR LIMIT=40] -->
     <plurals name="permissions_summary">
@@ -8633,8 +8684,8 @@
     <!-- Summary of Android version info (when there is a pending upgrade available) [CHAR LIMIT=NONE] -->
     <string name="android_version_pending_update_summary">Update available</string>
 
-    <!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
-    <string name="disabled_by_policy_title">Action not allowed</string>
+    <!-- Title for dialog displayed when user selects on a setting locked by an admin [CHAR LIMIT=30] -->
+    <string name="disabled_by_policy_title">Can\'t change this setting</string>
     <!-- Title for dialog displayed to tell user that changing volume was disallowed by an admin [CHAR LIMIT=50] -->
     <string name="disabled_by_policy_title_adjust_volume">Can\'t change volume</string>
     <!-- Title for dialog displayed to tell user that outgoing calls were disabled by an admin [CHAR LIMIT=50] -->
@@ -8648,8 +8699,7 @@
     <!-- Title for dialog displayed to tell user that turning off backups is disallowed by an admin [CHAR LIMIT=50] -->
     <string name="disabled_by_policy_title_turn_off_backups">Can\'t turn off backups</string>
     <!-- Shown when the user tries to change a settings locked by an admin [CHAR LIMIT=200] -->
-    <string name="default_admin_support_msg">This action is disabled. To learn more, contact your
-        organization\'s admin.</string>
+    <string name="default_admin_support_msg">If you have questions, contact your IT admin</string>
     <!-- Shown in dialog to allow user to see more information about the device admin [CHAR LIMIT=30] -->
     <string name="admin_support_more_info">More details</string>
     <!-- Shown in admin details page to warn user about policies the admin can set in a work profile. [CHAR LIMIT=NONE] -->
@@ -8963,6 +9013,9 @@
     <!-- Summary for the Data Saver feature being off [CHAR LIMIT=NONE] -->
     <string name="data_saver_off">Off</string>
 
+    <!-- Switch label to enable the Data Saver feature [CHAR LIMIT=NONE] -->
+    <string name="data_saver_switch_title">Use Data Saver</string>
+
     <!-- Title for switch to allow app unrestricted data usage [CHAR LIMIT=30] -->
     <string name="unrestricted_app_title">Unrestricted data usage</string>
 
@@ -9647,12 +9700,6 @@
          [DO NOT TRANSLATE] -->
     <string name="account_confirmation_class" translatable="false"></string>
 
-    <!-- Title for the new About Phone screen [CHAR LIMIT=40] -->
-    <string name="my_device_info_title" product="default">My Phone</string>
-    <!-- Title for the new About Phone screen [CHAR LIMIT=40] -->
-    <string name="my_device_info_title" product="tablet">My Tablet</string>
-    <!-- Title for the new About Phone screen [CHAR LIMIT=40] -->
-    <string name="my_device_info_title" product="device">My Device</string>
     <!-- Title for preference showing the primary account on the device [CHAR LIMIT=60]-->
     <string name="my_device_info_account_preference_title">Account</string>
     <!-- Title for preference showing the name of the device. [CHAR LIMIT=60]-->
@@ -9724,4 +9771,7 @@
     <!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
     <string name="pref_title_network_details">Network details</string>
 
+    <!--  Warning text about the visibility of device name. [CHAR LIMIT=NONE] -->
+    <string name="about_phone_device_name_warning">Your device name is visible to apps on your phone. It may also be seen by other people when you connect to Bluetooth devices or set up a Wi-Fi hotspot.</string>
+
 </resources>
diff --git a/res/xml/app_info_settings.xml b/res/xml/app_info_settings.xml
index 99c76b8..4695b44 100644
--- a/res/xml/app_info_settings.xml
+++ b/res/xml/app_info_settings.xml
@@ -25,13 +25,13 @@
         android:key="header_view"
         android:layout="@layout/settings_entity_header"
         android:selectable="false"
-        android:order="-10000"/>
+        android:order="-10000" />
 
     <com.android.settings.applications.LayoutPreference
         android:key="instant_app_buttons"
         android:layout="@layout/instant_app_buttons"
         android:selectable="false"
-        android:order="-9999"/>
+        android:order="-9999" />
 
     <com.android.settings.widget.ActionButtonPreference
         android:key="action_buttons"
@@ -39,7 +39,7 @@
 
     <Preference
         android:key="notification_settings"
-        android:title="@string/notifications_label"/>
+        android:title="@string/notifications_label" />
 
     <com.android.settings.widget.FixedLineSummaryPreference
         android:key="permission_settings"
@@ -50,7 +50,7 @@
     <Preference
         android:key="storage_settings"
         android:title="@string/storage_settings"
-        android:summary="@string/summary_placeholder"/>
+        android:summary="@string/summary_placeholder" />
 
     <com.android.settings.applications.AppDomainsPreference
         android:key="instant_app_launch_supported_domain_urls"
@@ -60,24 +60,29 @@
     <Preference
         android:key="data_settings"
         android:title="@string/data_usage_summary_title"
-        android:summary="@string/summary_placeholder"/>
+        android:summary="@string/summary_placeholder" />
+
+    <Preference
+        android:key="time_spent_in_app"
+        android:title="@string/time_spent_in_app_pref_title"
+        app:controller="com.android.settings.applications.appinfo.TimeSpentInAppPreferenceController" />
 
     <Preference
         android:key="battery"
         android:title="@string/power_usage_summary_title"
-        android:summary="@string/summary_placeholder"/>
+        android:summary="@string/summary_placeholder" />
 
     <Preference
         android:key="preferred_settings"
         android:title="@string/launch_by_default"
         android:summary="@string/summary_placeholder"
-        android:selectable="true"/>
+        android:selectable="true" />
 
     <Preference
         android:key="memory"
         android:title="@string/memory_settings_title"
         android:summary="@string/summary_placeholder"
-        android:enabled="false"/>
+        android:enabled="false" />
 
     <!-- Default apps shortcuts -->
     <Preference
@@ -146,6 +151,6 @@
     <Preference
         android:key="app_version"
         android:selectable="false"
-        android:order="9999"/>
+        android:order="9999" />
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml
index 8c93f97..619bd66 100644
--- a/res/xml/my_device_info.xml
+++ b/res/xml/my_device_info.xml
@@ -19,7 +19,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="my_device_info_pref_screen"
-    android:title="@string/my_device_info_title"
+    android:title="@string/about_settings"
     settings:initialExpandedChildrenCount="7">
 
     <com.android.settings.applications.LayoutPreference
diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
index 7428e53..daed1e1 100755
--- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
@@ -45,20 +45,16 @@
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
-import android.view.View;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.DeviceAdminAdd;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
-import com.android.settings.applications.LayoutPreference;
 import com.android.settings.applications.manageapplications.ManageApplications;
 import com.android.settings.core.SubSettingLauncher;
 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
 import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.widget.EntityHeaderController;
 import com.android.settings.widget.PreferenceCategoryController;
 import com.android.settings.wrapper.DevicePolicyManagerWrapper;
 import com.android.settingslib.RestrictedLockUtils;
@@ -157,7 +153,12 @@
                 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
     }
 
-    /** Called when the activity is first created. */
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+        use(TimeSpentInAppPreferenceController.class).setPackageName(getPackageName());
+    }
+
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -191,9 +192,10 @@
     @Override
     public void onResume() {
         super.onResume();
-        mAppsControlDisallowedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(getActivity(),
+        final Activity activity = getActivity();
+        mAppsControlDisallowedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(activity,
                 UserManager.DISALLOW_APPS_CONTROL, mUserId);
-        mAppsControlDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(getActivity(),
+        mAppsControlDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(activity,
                 UserManager.DISALLOW_APPS_CONTROL, mUserId);
 
         if (!refreshUi()) {
@@ -300,7 +302,7 @@
      *
      * @return true if packageInfo is available.
      */
-    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+    @VisibleForTesting
     boolean ensurePackageInfoAvailable(Activity activity) {
         if (mPackageInfo == null) {
             mFinishing = true;
diff --git a/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceController.java b/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceController.java
new file mode 100644
index 0000000..047d38e
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceController.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2018 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.appinfo;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.core.BasePreferenceController;
+
+import java.util.List;
+
+public class TimeSpentInAppPreferenceController extends BasePreferenceController {
+
+    @VisibleForTesting
+    static final Intent SEE_TIME_IN_APP_TEMPLATE =
+            new Intent("com.android.settings.action.TIME_SPENT_IN_APP");
+
+    private final PackageManager mPackageManager;
+
+    private Intent mIntent;
+    private String mPackageName;
+
+    public TimeSpentInAppPreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+        mPackageManager = context.getPackageManager();
+    }
+
+    public void setPackageName(String packageName) {
+        mPackageName = packageName;
+        mIntent = new Intent(SEE_TIME_IN_APP_TEMPLATE)
+                .putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        if (TextUtils.isEmpty(mPackageName)) {
+            return DISABLED_UNSUPPORTED;
+        }
+        final List<ResolveInfo> resolved = mPackageManager.queryIntentActivities(mIntent,
+                0 /* flags */);
+        if (resolved == null || resolved.isEmpty()) {
+            return DISABLED_UNSUPPORTED;
+        }
+        return AVAILABLE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        final Preference pref = screen.findPreference(getPreferenceKey());
+        if (pref != null) {
+            pref.setIntent(mIntent);
+        }
+    }
+}
diff --git a/src/com/android/settings/core/PreferenceControllerListHelper.java b/src/com/android/settings/core/PreferenceControllerListHelper.java
index a4808a1..738a695 100644
--- a/src/com/android/settings/core/PreferenceControllerListHelper.java
+++ b/src/com/android/settings/core/PreferenceControllerListHelper.java
@@ -56,7 +56,7 @@
             preferenceMetadata = PreferenceXmlParserUtils.extractMetadata(context, xmlResId,
                     MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
         } catch (IOException | XmlPullParserException e) {
-            Log.e(TAG, "Failed to parse preference xml for getting controllers");
+            Log.e(TAG, "Failed to parse preference xml for getting controllers", e);
             return controllers;
         }
 
diff --git a/src/com/android/settings/display/ColorModePreferenceFragment.java b/src/com/android/settings/display/ColorModePreferenceFragment.java
index f1bb6e1..5f5445b 100644
--- a/src/com/android/settings/display/ColorModePreferenceFragment.java
+++ b/src/com/android/settings/display/ColorModePreferenceFragment.java
@@ -38,6 +38,9 @@
     static final String KEY_COLOR_MODE_BOOSTED = "color_mode_boosted";
     @VisibleForTesting
     static final String KEY_COLOR_MODE_SATURATED = "color_mode_saturated";
+    // TODO have a real key for "automatic" rather than just re-using "saturated"
+    @VisibleForTesting
+    static final String KEY_COLOR_MODE_AUTOMATIC = "color_mode_saturated";
 
     private ColorDisplayController mController;
 
@@ -74,7 +77,9 @@
             new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_boosted),
                     KEY_COLOR_MODE_BOOSTED),
             new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_saturated),
-                    KEY_COLOR_MODE_SATURATED)
+                    KEY_COLOR_MODE_SATURATED),
+            new ColorModeCandidateInfo(c.getString(R.string.color_mode_option_automatic),
+                    KEY_COLOR_MODE_AUTOMATIC)
         );
     }
 
diff --git a/src/com/android/settings/password/SetupChooseLockPattern.java b/src/com/android/settings/password/SetupChooseLockPattern.java
index 8853950..c9858b8 100644
--- a/src/com/android/settings/password/SetupChooseLockPattern.java
+++ b/src/com/android/settings/password/SetupChooseLockPattern.java
@@ -25,7 +25,6 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
-import android.widget.TextView;
 
 import com.android.settings.R;
 import com.android.settings.SetupRedactionInterstitial;
@@ -70,6 +69,17 @@
                         ChooseLockTypeDialogFragment.newInstance(mUserId)
                                 .show(getChildFragmentManager(), null));
             }
+            // enable skip button only during setup wizard and not with fingerprint flow.
+            if (!mForFingerprint) {
+                Button skipButton = view.findViewById(R.id.skip_button);
+                skipButton.setVisibility(View.VISIBLE);
+                skipButton.setOnClickListener(v -> {
+                    SetupSkipDialog dialog = SetupSkipDialog.newInstance(
+                            getActivity().getIntent()
+                                    .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
+                    dialog.show(getFragmentManager());
+                });
+            }
             return view;
         }
 
@@ -82,16 +92,6 @@
         }
 
         @Override
-        protected void updateFooterLeftButton(Stage stage, TextView footerLeftButton) {
-            super.updateFooterLeftButton(stage, footerLeftButton);
-            // enable skip button only during setupwizard and not with fingerprint flow.
-            if (!mForFingerprint) {
-                footerLeftButton.setVisibility(View.VISIBLE);
-                footerLeftButton.setText(R.string.skip_label);
-            }
-        }
-
-        @Override
         protected void updateStage(Stage stage) {
             super.updateStage(stage);
             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)
@@ -102,14 +102,6 @@
         }
 
         @Override
-        public void handleLeftButton() {
-            SetupSkipDialog dialog = SetupSkipDialog.newInstance(
-                    getActivity().getIntent()
-                            .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
-            dialog.show(getFragmentManager());
-        }
-
-        @Override
         protected Intent getRedactionInterstitialIntent(Context context) {
             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
             // optional step if the lock screen was set up.
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
index dc6c6c9..bdad9e6 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
@@ -27,6 +27,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
 
 import com.android.settings.datausage.DataSaverBackend;
 import com.android.settings.widget.SwitchWidgetController;
@@ -44,6 +45,16 @@
     private final ConnectivityManager mConnectivityManager;
     private final DataSaverBackend mDataSaverBackend;
     private final WifiManager mWifiManager;
+    @VisibleForTesting
+    final ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback =
+            new ConnectivityManager.OnStartTetheringCallback() {
+                @Override
+                public void onTetheringFailed() {
+                    super.onTetheringFailed();
+                    mSwitchBar.setChecked(false);
+                    updateWifiSwitch();
+                }
+            };
 
     static {
         WIFI_INTENT_FILTER = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
@@ -92,7 +103,7 @@
     void startTether() {
         mSwitchBar.setEnabled(false);
         mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
-                NoOpOnStartTetheringCallback.newInstance(), new Handler(Looper.getMainLooper()));
+                mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
     }
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceControllerTest.java
new file mode 100644
index 0000000..ab3e066
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/TimeSpentInAppPreferenceControllerTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2018 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.appinfo;
+
+import static android.content.Intent.EXTRA_PACKAGE_NAME;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+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.Shadows;
+import org.robolectric.shadows.ShadowPackageManager;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class TimeSpentInAppPreferenceControllerTest {
+
+    private static final String TEST_KEY = "test_tey";
+    private static final Intent TEST_INTENT = new Intent(
+            TimeSpentInAppPreferenceController.SEE_TIME_IN_APP_TEMPLATE)
+            .putExtra(EXTRA_PACKAGE_NAME, "com.android.settings");
+
+    @Mock
+    private PreferenceScreen mScreen;
+
+    private Context mContext;
+    private ShadowPackageManager mPackageManager;
+    private TimeSpentInAppPreferenceController mController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
+        mController = new TimeSpentInAppPreferenceController(mContext, TEST_KEY);
+        mPreference = new Preference(mContext);
+        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+    }
+
+    @Test
+    public void noPackageName_shouldBeDisabled() {
+        mController.setPackageName(null);
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
+    }
+
+    @Test
+    public void noIntentHandler_shouldBeDisabled() {
+        mController.setPackageName(TEST_INTENT.getStringExtra(EXTRA_PACKAGE_NAME));
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
+    }
+
+    @Test
+    public void hasIntentHandler_shouldBeAvailable() {
+        mPackageManager.addResolveInfoForIntent(TEST_INTENT, new ResolveInfo());
+        mController.setPackageName(TEST_INTENT.getStringExtra(EXTRA_PACKAGE_NAME));
+
+        assertThat(mController.getAvailabilityStatus())
+                .isEqualTo(BasePreferenceController.AVAILABLE);
+
+        mController.displayPreference(mScreen);
+
+        final Intent intent = mPreference.getIntent();
+        assertThat(intent.getAction()).isEqualTo(TEST_INTENT.getAction());
+        assertThat(intent.getStringExtra(EXTRA_PACKAGE_NAME))
+                .isEqualTo(TEST_INTENT.getStringExtra(EXTRA_PACKAGE_NAME));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
index 4352e1c..e962441 100644
--- a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
@@ -73,13 +73,15 @@
         when(mFragment.getContext()).thenReturn(RuntimeEnvironment.application);
         List<? extends CandidateInfo> candidates = mFragment.getCandidates();
 
-        assertThat(candidates.size()).isEqualTo(3);
+        assertThat(candidates.size()).isEqualTo(4);
         assertThat(candidates.get(0).getKey())
                 .isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
         assertThat(candidates.get(1).getKey())
                 .isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
         assertThat(candidates.get(2).getKey())
                 .isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
+        assertThat(candidates.get(3).getKey())
+                .isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_AUTOMATIC);
     }
 
     @Test
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
index a98db11..63bf711 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
@@ -29,6 +29,8 @@
 import android.widget.Button;
 
 import com.android.internal.widget.LockPatternView;
+import com.android.internal.widget.LockPatternView.Cell;
+import com.android.internal.widget.LockPatternView.DisplayMode;
 import com.android.settings.R;
 import com.android.settings.SetupRedactionInterstitial;
 import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
@@ -47,6 +49,9 @@
 import org.robolectric.shadows.ShadowAlertDialog;
 import org.robolectric.shadows.ShadowPackageManager;
 import org.robolectric.util.ReflectionHelpers;
+import org.robolectric.util.ReflectionHelpers.ClassParameter;
+
+import java.util.Arrays;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(shadows = {
@@ -120,16 +125,28 @@
 
     @Test
     public void skipButton_shouldBeVisible_duringNonFingerprintFlow() {
-        Button button = mActivity.findViewById(R.id.footerLeftButton);
-        assertThat(button).isNotNull();
-        assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
+        Button skipButton = mActivity.findViewById(R.id.skip_button);
+        assertThat(skipButton).isNotNull();
+        assertThat(skipButton.getVisibility()).isEqualTo(View.VISIBLE);
 
-        button.performClick();
+        skipButton.performClick();
         AlertDialog chooserDialog = ShadowAlertDialog.getLatestAlertDialog();
         assertThat(chooserDialog).isNotNull();
     }
 
     @Test
+    public void clearButton_shouldBeVisible_duringRetryStage() {
+        enterPattern();
+
+        Button clearButton = mActivity.findViewById(R.id.footerLeftButton);
+        assertThat(clearButton.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(clearButton.isEnabled()).isTrue();
+
+        clearButton.performClick();
+        assertThat(findFragment(mActivity).mChosenPattern).isNull();
+    }
+
+    @Test
     public void skipButton_shouldNotBeVisible_duringFingerprintFlow() {
         mActivity = Robolectric.buildActivity(
                 SetupChooseLockPattern.class,
@@ -140,13 +157,32 @@
                                 .setForFingerprint(true)
                                 .build()))
                 .setup().get();
-        Button button = mActivity.findViewById(R.id.footerLeftButton);
-        assertThat(button).isNotNull();
-        assertThat(button.getVisibility()).isEqualTo(View.GONE);
+        Button skipButton = mActivity.findViewById(R.id.skip_button);
+        assertThat(skipButton).isNotNull();
+        assertThat(skipButton.getVisibility()).isEqualTo(View.GONE);
     }
 
     private ChooseLockPatternFragment findFragment(Activity activity) {
         return (ChooseLockPatternFragment)
                 activity.getFragmentManager().findFragmentById(R.id.main_content);
     }
+
+    private void enterPattern() {
+        LockPatternView lockPatternView = mActivity.findViewById(R.id.lockPattern);
+        lockPatternView.setPattern(
+                DisplayMode.Animate,
+                Arrays.asList(
+                        createCell(0, 0),
+                        createCell(0, 1),
+                        createCell(1, 1),
+                        createCell(1, 0)));
+        ReflectionHelpers.callInstanceMethod(lockPatternView, "notifyPatternDetected");
+    }
+
+    private Cell createCell(int row, int column) {
+        return ReflectionHelpers.callConstructor(
+                Cell.class,
+                ClassParameter.from(int.class, row),
+                ClassParameter.from(int.class, column));
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java
index 660f335..db8baab 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java
@@ -22,6 +22,8 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkPolicyManager;
 import android.net.wifi.WifiManager;
 import android.provider.Settings;
 
@@ -40,9 +42,14 @@
 public class WifiTetherSwitchBarControllerTest {
     @Mock
     private WifiManager mWifiManager;
+    @Mock
+    private ConnectivityManager mConnectivityManager;
+    @Mock
+    private NetworkPolicyManager mNetworkPolicyManager;
 
     private Context mContext;
     private SwitchBar mSwitchBar;
+    private WifiTetherSwitchBarController mController;
 
     @Before
     public void setUp() {
@@ -51,6 +58,13 @@
         mContext = spy(RuntimeEnvironment.application);
         mSwitchBar = new SwitchBar(mContext);
         when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
+        when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
+                mConnectivityManager);
+        when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
+                mNetworkPolicyManager);
+
+        mController = new WifiTetherSwitchBarController(mContext,
+                new SwitchBarController(mSwitchBar));
     }
 
     @Test
@@ -63,4 +77,15 @@
 
         assertThat(mSwitchBar.isEnabled()).isFalse();
     }
+
+    @Test
+    public void testStartTether_fail_resetSwitchBar() {
+        when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
+
+        mController.startTether();
+        mController.mOnStartTetheringCallback.onTetheringFailed();
+
+        assertThat(mSwitchBar.isChecked()).isFalse();
+        assertThat(mSwitchBar.isEnabled()).isTrue();
+    }
 }