Merge "Block location accuracy when DISALLOW_CONFIG_LOCATION is set." into pi-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e5c7cec..45d6e9c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7549,10 +7549,10 @@
     <string name="zen_mode_alarms">Alarms</string>
 
     <!-- [CHAR LIMIT=50] Zen mode settings: Media option -->
-    <string name="zen_mode_media_system_other">Media</string>
+    <string name="zen_mode_media">Media</string>
 
-    <!-- [CHAR LIMIT=120] Zen mode settings: Media secondary text explaining sounds include system feedback such as system tapping sounds, haptic feedback, etc. -->
-    <string name="zen_mode_media_system_other_secondary_text">Includes system feedback like touch and charging sounds</string>
+    <!-- [CHAR LIMIT=50] Zen mode settings: System option which includes sounds such as touch and charging sounds -->
+    <string name="zen_mode_system">Touch and charging sounds</string>
 
     <!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
     <string name="zen_mode_reminders">Reminders</string>
diff --git a/res/xml/data_usage_cellular.xml b/res/xml/data_usage_cellular.xml
index 0c1e014..b50eaba 100644
--- a/res/xml/data_usage_cellular.xml
+++ b/res/xml/data_usage_cellular.xml
@@ -16,8 +16,7 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:key="data_usage_cellular_screen"
-    android:title="@string/data_usage_summary_title">
+    android:key="data_usage_cellular_screen">
 
     <com.android.settings.datausage.TemplatePreferenceCategory
         android:key="mobile_category"
diff --git a/res/xml/data_usage_wifi.xml b/res/xml/data_usage_wifi.xml
index 905b15a..693a931 100644
--- a/res/xml/data_usage_wifi.xml
+++ b/res/xml/data_usage_wifi.xml
@@ -16,8 +16,7 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
-    android:key="data_usage_wifi_screen"
-    android:title="@string/data_usage_summary_title">
+    android:key="data_usage_wifi_screen">
 
     <com.android.settings.datausage.TemplatePreferenceCategory
         android:key="wifi_category"
diff --git a/res/xml/time_zone_prefs.xml b/res/xml/time_zone_prefs.xml
new file mode 100644
index 0000000..f80de8c
--- /dev/null
+++ b/res/xml/time_zone_prefs.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:key="time_zone_settings_screen"
+    android:title="@string/date_time_set_timezone">
+
+    <PreferenceCategory
+        android:key="time_zone_region_preference_category">
+        <com.android.settingslib.RestrictedPreference
+            android:key="region"
+            android:title="@string/date_time_select_region"
+            android:summary="@string/summary_placeholder" />
+        <com.android.settingslib.RestrictedPreference
+            android:key="region_zone"
+            android:title="@string/date_time_select_zone"
+            android:summary="@string/summary_placeholder" />
+        <com.android.settingslib.widget.FooterPreference/>
+    </PreferenceCategory>
+
+    <PreferenceCategory
+        android:key="time_zone_fixed_offset_preference_category">
+        <com.android.settingslib.RestrictedPreference
+            android:key="fixed_offset"
+            android:title="@string/date_time_select_fixed_offset_time_zones"
+            android:summary="@string/summary_placeholder"/>
+    </PreferenceCategory>
+</PreferenceScreen>
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
index 8d2c28c..084b78d 100644
--- a/res/xml/zen_mode_behavior_settings.xml
+++ b/res/xml/zen_mode_behavior_settings.xml
@@ -20,7 +20,7 @@
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="zen_mode_behavior_settings_page"
     android:title="@string/zen_mode_behavior_settings_title"
-    settings:initialExpandedChildrenCount="7">
+    settings:initialExpandedChildrenCount="8">
 
    <PreferenceCategory
        android:title="@string/zen_mode_behavior_allow_title"
@@ -34,8 +34,12 @@
        <!-- Media -->
        <SwitchPreference
            android:key="zen_mode_media"
-           android:title="@string/zen_mode_media_system_other"
-           android:summary="@string/zen_mode_media_system_other_secondary_text"/>
+           android:title="@string/zen_mode_media"/>
+
+       <!-- System -->
+       <SwitchPreference
+           android:key="zen_mode_system"
+           android:title="@string/zen_mode_system"/>
 
        <!-- Reminders -->
        <SwitchPreference
diff --git a/src/com/android/settings/backup/BackupSettingsActivity.java b/src/com/android/settings/backup/BackupSettingsActivity.java
index 7ffc6cd..d78af32 100644
--- a/src/com/android/settings/backup/BackupSettingsActivity.java
+++ b/src/com/android/settings/backup/BackupSettingsActivity.java
@@ -58,9 +58,17 @@
                         "No manufacturer settings found, launching the backup settings directly");
             }
             Intent intent = backupHelper.getIntentForBackupSettings();
-            // enable the activity before launching it
-            getPackageManager().setComponentEnabledSetting(intent.getComponent(),
-                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
+            try {
+                // enable the activity before launching it
+                getPackageManager().setComponentEnabledSetting(
+                        intent.getComponent(),
+                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
+                        PackageManager.DONT_KILL_APP);
+            } catch (SecurityException e) {
+                Log.w(TAG, "Trying to enable activity " + intent.getComponent() + " but couldn't: "
+                        + e.getMessage());
+                // the activity may already be enabled
+            }
 
             // use startActivityForResult to let the activity check the caller signature
             startActivityForResult(intent, 1);
diff --git a/src/com/android/settings/datetime/TimeZonePreferenceController.java b/src/com/android/settings/datetime/TimeZonePreferenceController.java
index e29e245..aff204d 100644
--- a/src/com/android/settings/datetime/TimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/TimeZonePreferenceController.java
@@ -19,11 +19,11 @@
 import android.content.Context;
 import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
-
 import android.util.FeatureFlagUtils;
+
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.datetime.timezone.ZonePicker;
+import com.android.settings.datetime.timezone.TimeZoneSettings;
 import com.android.settingslib.RestrictedPreference;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.datetime.ZoneGetter;
@@ -51,7 +51,7 @@
             return;
         }
         if (mZonePickerV2) {
-            preference.setFragment(ZonePicker.class.getName());
+            preference.setFragment(TimeZoneSettings.class.getName());
         }
         preference.setSummary(getTimeZoneOffsetAndName());
         if( !((RestrictedPreference) preference).isDisabledByAdmin()) {
diff --git a/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceController.java b/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceController.java
new file mode 100644
index 0000000..846fce0
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceController.java
@@ -0,0 +1,51 @@
+/*
+ * 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.datetime.timezone;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+
+import com.google.common.base.Objects;
+
+public abstract class BaseTimeZonePreferenceController extends BasePreferenceController {
+    private OnPreferenceClickListener mOnClickListener;
+
+    protected BaseTimeZonePreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (mOnClickListener == null || !Objects.equal(getPreferenceKey(), preference.getKey())) {
+            return false;
+        }
+
+        mOnClickListener.onClick();
+        return true;
+    }
+
+    public void setOnClickListener(OnPreferenceClickListener listener) {
+        mOnClickListener = listener;
+    }
+}
diff --git a/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceController.java b/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceController.java
new file mode 100644
index 0000000..16c1f19
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceController.java
@@ -0,0 +1,46 @@
+/*
+ * 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.datetime.timezone;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+public class FixedOffsetPreferenceController extends BaseTimeZonePreferenceController {
+
+    private static final String PREFERENCE_KEY = "fixed_offset";
+
+    private TimeZoneInfo mTimeZoneInfo;
+
+    public FixedOffsetPreferenceController(Context context) {
+        super(context, PREFERENCE_KEY);
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        // This is a Spannable object, which contains TTS span. It shouldn't be converted to String.
+        return mTimeZoneInfo == null ? "" : mTimeZoneInfo.getGmtOffset();
+    }
+
+    public void setTimeZoneInfo(TimeZoneInfo timeZoneInfo) {
+        mTimeZoneInfo = timeZoneInfo;
+    }
+
+    public TimeZoneInfo getTimeZoneInfo() {
+        return mTimeZoneInfo;
+    }
+}
+
diff --git a/src/com/android/settings/datetime/timezone/OnPreferenceClickListener.java b/src/com/android/settings/datetime/timezone/OnPreferenceClickListener.java
new file mode 100644
index 0000000..3e4d715
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/OnPreferenceClickListener.java
@@ -0,0 +1,24 @@
+/*
+ * 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.datetime.timezone;
+
+/**
+ * Callback when a preference is clicked in {@class TimeZoneSettings}
+ */
+public interface OnPreferenceClickListener {
+    void onClick();
+}
diff --git a/src/com/android/settings/datetime/timezone/RegionPreferenceController.java b/src/com/android/settings/datetime/timezone/RegionPreferenceController.java
new file mode 100644
index 0000000..201b9bd
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/RegionPreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * 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.datetime.timezone;
+
+import android.content.Context;
+import android.icu.text.LocaleDisplayNames;
+import android.support.v7.preference.Preference;
+
+import java.util.Locale;
+
+public class RegionPreferenceController extends BaseTimeZonePreferenceController {
+    private static final String PREFERENCE_KEY = "region";
+
+    private final LocaleDisplayNames mLocaleDisplayNames;
+    private String mRegionId = "";
+
+    public RegionPreferenceController(Context context) {
+        super(context, PREFERENCE_KEY);
+        Locale locale = context.getResources().getConfiguration().getLocales().get(0);
+        mLocaleDisplayNames = LocaleDisplayNames.getInstance(locale);
+
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return mLocaleDisplayNames.regionDisplayName(mRegionId);
+    }
+
+    public void setRegionId(String regionId) {
+        mRegionId = regionId;
+    }
+
+    public String getRegionId() {
+        return mRegionId;
+    }
+}
diff --git a/src/com/android/settings/datetime/timezone/RegionZonePreferenceController.java b/src/com/android/settings/datetime/timezone/RegionZonePreferenceController.java
new file mode 100644
index 0000000..85f4165
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/RegionZonePreferenceController.java
@@ -0,0 +1,68 @@
+/*
+ * 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.datetime.timezone;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+
+public class RegionZonePreferenceController extends BaseTimeZonePreferenceController {
+    private static final String PREFERENCE_KEY = "region_zone";
+
+    private TimeZoneInfo mTimeZoneInfo;
+    private boolean mIsClickable;
+
+    public RegionZonePreferenceController(Context context) {
+        super(context, PREFERENCE_KEY);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+        preference.setEnabled(isClickable());
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return mTimeZoneInfo == null ? ""
+                : SpannableUtil.getResourcesText(mContext.getResources(),
+                        R.string.zone_info_exemplar_location_and_offset,
+                mTimeZoneInfo.getExemplarLocation(), mTimeZoneInfo.getGmtOffset());
+    }
+
+    public void setTimeZoneInfo(TimeZoneInfo timeZoneInfo) {
+        mTimeZoneInfo = timeZoneInfo;
+    }
+
+    public TimeZoneInfo getTimeZoneInfo() {
+        return mTimeZoneInfo;
+    }
+
+    public void setClickable(boolean clickable) {
+        mIsClickable = clickable;
+    }
+
+    public boolean isClickable() {
+        return mIsClickable;
+    }
+}
diff --git a/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceController.java b/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceController.java
new file mode 100644
index 0000000..0f0264f
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceController.java
@@ -0,0 +1,137 @@
+/*
+ * 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.datetime.timezone;
+
+import android.content.Context;
+import android.icu.impl.OlsonTimeZone;
+import android.icu.text.DateFormat;
+import android.icu.text.DisplayContext;
+import android.icu.text.SimpleDateFormat;
+import android.icu.util.Calendar;
+import android.icu.util.TimeZone;
+import android.icu.util.TimeZoneTransition;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settingslib.widget.FooterPreference;
+
+import java.util.Date;
+
+public class TimeZoneInfoPreferenceController extends BaseTimeZonePreferenceController {
+    private static final String PREFERENCE_KEY = FooterPreference.KEY_FOOTER;
+
+    private TimeZoneInfo mTimeZoneInfo;
+    private final DateFormat mDateFormat;
+    private final Date mDate;
+
+    public TimeZoneInfoPreferenceController(Context context) {
+        this(context, new Date());
+    }
+
+    @VisibleForTesting
+    TimeZoneInfoPreferenceController(Context context, Date date) {
+        super(context, PREFERENCE_KEY);
+        mDateFormat = DateFormat.getDateInstance(SimpleDateFormat.LONG);
+        mDateFormat.setContext(DisplayContext.CAPITALIZATION_NONE);
+        mDate = date;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        CharSequence formattedTimeZone = mTimeZoneInfo == null ? "" : formatInfo(mTimeZoneInfo);
+        preference.setTitle(formattedTimeZone);
+        preference.setVisible(mTimeZoneInfo != null);
+    }
+
+    public void setTimeZoneInfo(TimeZoneInfo timeZoneInfo) {
+        mTimeZoneInfo = timeZoneInfo;
+    }
+
+    public TimeZoneInfo getTimeZoneInfo() {
+        return mTimeZoneInfo;
+    }
+
+    private CharSequence formatOffsetAndName(TimeZoneInfo item) {
+        String name = item.getGenericName();
+        if (name == null) {
+            if (item.getTimeZone().inDaylightTime(mDate)) {
+                name = item.getDaylightName();
+            } else {
+                name = item.getStandardName();
+            }
+        }
+        if (name == null) {
+            return item.getGmtOffset().toString();
+        } else {
+            return SpannableUtil.getResourcesText(mContext.getResources(),
+                    R.string.zone_info_offset_and_name, item.getGmtOffset(),
+                    name);
+        }
+    }
+
+    private CharSequence formatInfo(TimeZoneInfo item) {
+        final CharSequence offsetAndName = formatOffsetAndName(item);
+        final TimeZone timeZone = item.getTimeZone();
+        if (!timeZone.observesDaylightTime()) {
+            return mContext.getString(R.string.zone_info_footer_no_dst, offsetAndName);
+        }
+
+        final TimeZoneTransition nextDstTransition = findNextDstTransition(timeZone);
+        if (nextDstTransition == null) {
+            return null;
+        }
+        final boolean toDst = nextDstTransition.getTo().getDSTSavings() != 0;
+        String timeType = toDst ? item.getDaylightName() : item.getStandardName();
+        if (timeType == null) {
+            // Fall back to generic "summer time" and "standard time" if the time zone has no
+            // specific names.
+            timeType = toDst ?
+                    mContext.getString(R.string.zone_time_type_dst) :
+                    mContext.getString(R.string.zone_time_type_standard);
+
+        }
+        final Calendar transitionTime = Calendar.getInstance(timeZone);
+        transitionTime.setTimeInMillis(nextDstTransition.getTime());
+        final String date = mDateFormat.format(transitionTime);
+        return SpannableUtil.getResourcesText(mContext.getResources(),
+                R.string.zone_info_footer, offsetAndName, timeType, date);
+    }
+
+    private TimeZoneTransition findNextDstTransition(TimeZone timeZone) {
+        if (!(timeZone instanceof OlsonTimeZone)) {
+            return null;
+        }
+        final OlsonTimeZone olsonTimeZone = (OlsonTimeZone) timeZone;
+        TimeZoneTransition transition = olsonTimeZone.getNextTransition(
+                mDate.getTime(), /* inclusive */ false);
+        do {
+            if (transition.getTo().getDSTSavings() != transition.getFrom().getDSTSavings()) {
+                break;
+            }
+            transition = olsonTimeZone.getNextTransition(
+                    transition.getTime(), /*inclusive */ false);
+        } while (transition != null);
+        return transition;
+    }
+
+}
diff --git a/src/com/android/settings/datetime/timezone/TimeZoneSettings.java b/src/com/android/settings/datetime/timezone/TimeZoneSettings.java
new file mode 100644
index 0000000..aeb5a80
--- /dev/null
+++ b/src/com/android/settings/datetime/timezone/TimeZoneSettings.java
@@ -0,0 +1,372 @@
+/*
+ * 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.datetime.timezone;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.icu.util.TimeZone;
+import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.PreferenceCategory;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.datetime.timezone.model.FilteredCountryTimeZones;
+import com.android.settings.datetime.timezone.model.TimeZoneData;
+import com.android.settings.datetime.timezone.model.TimeZoneDataLoader;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * The class displays a time zone picker either by regions or fixed offset time zones.
+ */
+public class TimeZoneSettings extends DashboardFragment {
+
+    private static final String TAG = "TimeZoneSettings";
+
+    private static final int MENU_BY_REGION = Menu.FIRST;
+    private static final int MENU_BY_OFFSET = Menu.FIRST + 1;
+
+    private static final int REQUEST_CODE_REGION_PICKER = 1;
+    private static final int REQUEST_CODE_ZONE_PICKER = 2;
+    private static final int REQUEST_CODE_FIXED_OFFSET_ZONE_PICKER = 3;
+
+    private static final String PREF_KEY_REGION = "time_zone_region";
+    private static final String PREF_KEY_REGION_CATEGORY = "time_zone_region_preference_category";
+    private static final String PREF_KEY_FIXED_OFFSET_CATEGORY =
+            "time_zone_fixed_offset_preference_category";
+
+    private Locale mLocale;
+    private boolean mSelectByRegion;
+    private TimeZoneData mTimeZoneData;
+
+    private String mSelectedTimeZoneId;
+    private TimeZoneInfo.Formatter mTimeZoneInfoFormatter;
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.ZONE_PICKER;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.time_zone_prefs;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    /**
+     * Called during onAttach
+     */
+    @VisibleForTesting
+    @Override
+    public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        mLocale = context.getResources().getConfiguration().getLocales().get(0);
+        mTimeZoneInfoFormatter = new TimeZoneInfo.Formatter(mLocale, new Date());
+        final List<AbstractPreferenceController> controllers = new ArrayList<>();
+        RegionPreferenceController regionPreferenceController =
+                new RegionPreferenceController(context);
+        regionPreferenceController.setOnClickListener(this::onRegionPreferenceClicked);
+        RegionZonePreferenceController regionZonePreferenceController =
+                new RegionZonePreferenceController(context);
+        regionZonePreferenceController.setOnClickListener(this::onRegionZonePreferenceClicked);
+        TimeZoneInfoPreferenceController timeZoneInfoPreferenceController =
+                new TimeZoneInfoPreferenceController(context);
+        FixedOffsetPreferenceController fixedOffsetPreferenceController =
+                new FixedOffsetPreferenceController(context);
+        fixedOffsetPreferenceController.setOnClickListener(this::onFixedOffsetPreferenceClicked);
+
+        controllers.add(regionPreferenceController);
+        controllers.add(regionZonePreferenceController);
+        controllers.add(timeZoneInfoPreferenceController);
+        controllers.add(fixedOffsetPreferenceController);
+        return controllers;
+    }
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        // Hide all interactive preferences
+        setPreferenceCategoryVisible((PreferenceCategory) findPreference(
+            PREF_KEY_REGION_CATEGORY), false);
+        setPreferenceCategoryVisible((PreferenceCategory) findPreference(
+            PREF_KEY_FIXED_OFFSET_CATEGORY), false);
+
+        // Start loading TimeZoneData
+        getLoaderManager().initLoader(0, null, new TimeZoneDataLoader.LoaderCreator(
+                getContext(), this::onTimeZoneDataReady));
+    }
+
+    @Override
+    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+        if (resultCode != Activity.RESULT_OK || data == null) {
+            return;
+        }
+
+        switch (requestCode) {
+            case REQUEST_CODE_REGION_PICKER:
+            case REQUEST_CODE_ZONE_PICKER: {
+                String regionId = data.getStringExtra(RegionSearchPicker.EXTRA_RESULT_REGION_ID);
+                String tzId = data.getStringExtra(RegionZonePicker.EXTRA_RESULT_TIME_ZONE_ID);
+                // Ignore the result if user didn't change the region or time zone.
+                if (!Objects.equals(regionId, use(RegionPreferenceController.class).getRegionId())
+                        || !Objects.equals(tzId, mSelectedTimeZoneId)) {
+                    onRegionZoneChanged(regionId, tzId);
+                }
+                break;
+            }
+            case REQUEST_CODE_FIXED_OFFSET_ZONE_PICKER: {
+                String tzId = data.getStringExtra(FixedOffsetPicker.EXTRA_RESULT_TIME_ZONE_ID);
+                // Ignore the result if user didn't change the time zone.
+                if (tzId != null && !tzId.equals(mSelectedTimeZoneId)) {
+                    onFixedOffsetZoneChanged(tzId);
+                }
+                break;
+            }
+        }
+    }
+
+    @VisibleForTesting
+    void setTimeZoneData(TimeZoneData timeZoneData) {
+        mTimeZoneData = timeZoneData;
+    }
+
+    private void onTimeZoneDataReady(TimeZoneData timeZoneData) {
+        if (mTimeZoneData == null && timeZoneData != null) {
+            mTimeZoneData = timeZoneData;
+            setupForCurrentTimeZone();
+            getActivity().invalidateOptionsMenu();
+        }
+
+    }
+
+    private void onRegionPreferenceClicked() {
+        startPickerFragment(RegionSearchPicker.class, new Bundle(), REQUEST_CODE_REGION_PICKER);
+    }
+
+    private void onRegionZonePreferenceClicked() {
+        final Bundle args = new Bundle();
+        args.putString(RegionZonePicker.EXTRA_REGION_ID,
+                use(RegionPreferenceController.class).getRegionId());
+        startPickerFragment(RegionZonePicker.class, args, REQUEST_CODE_ZONE_PICKER);
+    }
+
+    private void onFixedOffsetPreferenceClicked() {
+        startPickerFragment(FixedOffsetPicker.class, new Bundle(),
+                REQUEST_CODE_FIXED_OFFSET_ZONE_PICKER);
+    }
+
+    private void startPickerFragment(Class<? extends BaseTimeZonePicker> fragmentClass, Bundle args,
+            int resultRequestCode) {
+        new SubSettingLauncher(getContext())
+                .setDestination(fragmentClass.getCanonicalName())
+                .setArguments(args)
+                .setSourceMetricsCategory(getMetricsCategory())
+                .setResultListener(this, resultRequestCode)
+                .launch();
+    }
+
+    private void setDisplayedRegion(String regionId) {
+        use(RegionPreferenceController.class).setRegionId(regionId);
+        updatePreferenceStates();
+    }
+
+    private void setDisplayedTimeZoneInfo(String regionId, String tzId) {
+        final TimeZoneInfo tzInfo = tzId == null ? null : mTimeZoneInfoFormatter.format(tzId);
+        final FilteredCountryTimeZones countryTimeZones =
+                mTimeZoneData.lookupCountryTimeZones(regionId);
+
+        use(RegionZonePreferenceController.class).setTimeZoneInfo(tzInfo);
+        // Only clickable when the region has more than 1 time zones or no time zone is selected.
+
+        use(RegionZonePreferenceController.class).setClickable(tzInfo == null ||
+                (countryTimeZones != null && countryTimeZones.getTimeZoneIds().size() > 1));
+        use(TimeZoneInfoPreferenceController.class).setTimeZoneInfo(tzInfo);
+
+        updatePreferenceStates();
+    }
+
+    private void setDisplayedFixedOffsetTimeZoneInfo(String tzId) {
+        if (isFixedOffset(tzId)) {
+            use(FixedOffsetPreferenceController.class).setTimeZoneInfo(
+                    mTimeZoneInfoFormatter.format(tzId));
+        } else {
+            use(FixedOffsetPreferenceController.class).setTimeZoneInfo(null);
+        }
+        updatePreferenceStates();
+    }
+
+    private void onRegionZoneChanged(String regionId, String tzId) {
+        FilteredCountryTimeZones countryTimeZones =
+                mTimeZoneData.lookupCountryTimeZones(regionId);
+        if (countryTimeZones == null || !countryTimeZones.getTimeZoneIds().contains(tzId)) {
+            Log.e(TAG, "Unknown time zone id is selected: " + tzId);
+            return;
+        }
+
+        mSelectedTimeZoneId = tzId;
+        setDisplayedRegion(regionId);
+        setDisplayedTimeZoneInfo(regionId, mSelectedTimeZoneId);
+        saveTimeZone(regionId, mSelectedTimeZoneId);
+    }
+
+    private void onFixedOffsetZoneChanged(String tzId) {
+        mSelectedTimeZoneId = tzId;
+        setDisplayedFixedOffsetTimeZoneInfo(tzId);
+        saveTimeZone(null, mSelectedTimeZoneId);
+    }
+
+    private void saveTimeZone(String regionId, String tzId) {
+        SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
+        if (regionId == null) {
+            editor.remove(PREF_KEY_REGION);
+        } else {
+            editor.putString(PREF_KEY_REGION, regionId);
+        }
+        editor.apply();
+        getActivity().getSystemService(AlarmManager.class).setTimeZone(tzId);
+    }
+
+    @Override
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        menu.add(0, MENU_BY_REGION, 0, R.string.zone_menu_by_region);
+        menu.add(0, MENU_BY_OFFSET, 0, R.string.zone_menu_by_offset);
+        super.onCreateOptionsMenu(menu, inflater);
+    }
+
+    @Override
+    public void onPrepareOptionsMenu(Menu menu) {
+        // Do not show menu when data is not ready,
+        menu.findItem(MENU_BY_REGION).setVisible(mTimeZoneData != null && !mSelectByRegion);
+        menu.findItem(MENU_BY_OFFSET).setVisible(mTimeZoneData != null && mSelectByRegion);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case MENU_BY_REGION:
+                setSelectByRegion(true);
+                return true;
+
+            case MENU_BY_OFFSET:
+                setSelectByRegion(false);
+                return true;
+
+            default:
+                return false;
+        }
+    }
+
+    private void setupForCurrentTimeZone() {
+        mSelectedTimeZoneId = TimeZone.getDefault().getID();
+        setSelectByRegion(!isFixedOffset(mSelectedTimeZoneId));
+    }
+
+    private static boolean isFixedOffset(String tzId) {
+        return tzId.startsWith("Etc/GMT") || tzId.equals("Etc/UTC");
+    }
+
+    /**
+     * Switch the current view to select region or select fixed offset time zone.
+     * When showing the selected region, it guess the selected region from time zone id.
+     * See {@link #findRegionIdForTzId} for more info.
+     */
+    private void setSelectByRegion(boolean selectByRegion) {
+        mSelectByRegion = selectByRegion;
+        setPreferenceCategoryVisible((PreferenceCategory) findPreference(
+            PREF_KEY_REGION_CATEGORY), selectByRegion);
+        setPreferenceCategoryVisible((PreferenceCategory) findPreference(
+            PREF_KEY_FIXED_OFFSET_CATEGORY), !selectByRegion);
+        final String localeRegionId = getLocaleRegionId();
+        final Set<String> allCountryIsoCodes = mTimeZoneData.getRegionIds();
+
+        String displayRegion = allCountryIsoCodes.contains(localeRegionId) ? localeRegionId : null;
+        setDisplayedRegion(displayRegion);
+        setDisplayedTimeZoneInfo(displayRegion, null);
+
+        if (!mSelectByRegion) {
+            setDisplayedFixedOffsetTimeZoneInfo(mSelectedTimeZoneId);
+            return;
+        }
+
+        String regionId = findRegionIdForTzId(mSelectedTimeZoneId);
+        if (regionId != null) {
+            setDisplayedRegion(regionId);
+            setDisplayedTimeZoneInfo(regionId, mSelectedTimeZoneId);
+        }
+    }
+
+    /**
+     * Find the a region associated with the specified time zone, based on the time zone data.
+     * If there are multiple regions associated with the given time zone, the priority will be given
+     * to the region the user last picked and the country in user's locale.
+     * @return null if no region associated with the time zone
+     */
+    private String findRegionIdForTzId(String tzId) {
+        return findRegionIdForTzId(tzId,
+                getPreferenceManager().getSharedPreferences().getString(PREF_KEY_REGION, null),
+                getLocaleRegionId());
+    }
+
+    @VisibleForTesting
+    String findRegionIdForTzId(String tzId, String sharePrefRegionId, String localeRegionId) {
+        final Set<String> matchedRegions = mTimeZoneData.lookupCountryCodesForZoneId(tzId);
+        if (matchedRegions.size() == 0) {
+            return null;
+        }
+        if (sharePrefRegionId != null && matchedRegions.contains(sharePrefRegionId)) {
+            return sharePrefRegionId;
+        }
+        if (localeRegionId != null && matchedRegions.contains(localeRegionId)) {
+            return localeRegionId;
+        }
+
+        return matchedRegions.toArray(new String[matchedRegions.size()])[0];
+    }
+
+    private void setPreferenceCategoryVisible(PreferenceCategory category,
+        boolean isVisible) {
+        // Hiding category doesn't hide all the children preference. Set visibility of its children.
+        // Do not care grandchildren as time_zone_pref.xml has only 2 levels.
+        category.setVisible(isVisible);
+        for (int i = 0; i < category.getPreferenceCount(); i++) {
+            category.getPreference(i).setVisible(isVisible);
+        }
+    }
+
+    private String getLocaleRegionId() {
+        return mLocale.getCountry().toUpperCase(Locale.US);
+    }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 9d4f86f..ff71525 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -128,14 +128,14 @@
                     Log.e(TAG, "Excessive detected uid=" + uid);
                     batteryUtils.setForceAppStandby(uid, packageName,
                             AppOpsManager.MODE_IGNORED);
-                    databaseManager.insertAnomaly(packageName, anomalyType,
+                    databaseManager.insertAnomaly(uid, packageName, anomalyType,
                             smartBatteryOn
                                     ? AnomalyDatabaseHelper.State.AUTO_HANDLED
                                     : AnomalyDatabaseHelper.State.NEW,
                             timeMs);
                 }
             } else {
-                databaseManager.insertAnomaly(packageName, anomalyType,
+                databaseManager.insertAnomaly(uid, packageName, anomalyType,
                         AnomalyDatabaseHelper.State.NEW, timeMs);
             }
         } catch (NullPointerException | IndexOutOfBoundsException e) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/AppInfo.java b/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
index 1daff36..9557d9a 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AppInfo.java
@@ -33,11 +33,13 @@
      */
     public final int anomalyType;
     public final long screenOnTimeMs;
+    public final int uid;
 
     private AppInfo(AppInfo.Builder builder) {
         packageName = builder.mPackageName;
         anomalyType = builder.mAnomalyType;
         screenOnTimeMs = builder.mScreenOnTimeMs;
+        uid = builder.mUid;
     }
 
     @VisibleForTesting
@@ -45,6 +47,7 @@
         packageName = in.readString();
         anomalyType = in.readInt();
         screenOnTimeMs = in.readLong();
+        uid = in.readInt();
     }
 
     @Override
@@ -62,6 +65,13 @@
         dest.writeString(packageName);
         dest.writeInt(anomalyType);
         dest.writeLong(screenOnTimeMs);
+        dest.writeInt(uid);
+    }
+
+    @Override
+    public String toString() {
+        return "packageName=" + packageName + ",anomalyType=" + anomalyType + ",screenTime="
+                + screenOnTimeMs;
     }
 
     public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@@ -78,6 +88,7 @@
         private int mAnomalyType;
         private String mPackageName;
         private long mScreenOnTimeMs;
+        private int mUid;
 
         public Builder setAnomalyType(int type) {
             mAnomalyType = type;
@@ -94,6 +105,11 @@
             return this;
         }
 
+        public Builder setUid(int uid) {
+            mUid = uid;
+            return this;
+        }
+
         public AppInfo build() {
             return new AppInfo(this);
         }
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java b/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
index 935d493..d0bddec 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryDatabaseManager.java
@@ -24,6 +24,7 @@
         .ANOMALY_TYPE;
 import static com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper.AnomalyColumns
         .TIME_STAMP_MS;
+import static com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper.AnomalyColumns.UID;
 import static com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper.Tables.TABLE_ANOMALY;
 
 import android.content.ContentValues;
@@ -65,10 +66,11 @@
      * @param anomalyState  the state of the anomaly
      * @param timestampMs   the time when it is happened
      */
-    public synchronized void insertAnomaly(String packageName, int type, int anomalyState,
+    public synchronized void insertAnomaly(int uid, String packageName, int type, int anomalyState,
             long timestampMs) {
         try (SQLiteDatabase db = mDatabaseHelper.getWritableDatabase()) {
             ContentValues values = new ContentValues();
+            values.put(UID, uid);
             values.put(PACKAGE_NAME, packageName);
             values.put(ANOMALY_TYPE, type);
             values.put(ANOMALY_STATE, anomalyState);
@@ -83,7 +85,7 @@
     public synchronized List<AppInfo> queryAllAnomalies(long timestampMsAfter, int state) {
         final List<AppInfo> appInfos = new ArrayList<>();
         try (SQLiteDatabase db = mDatabaseHelper.getReadableDatabase()) {
-            final String[] projection = {PACKAGE_NAME, ANOMALY_TYPE};
+            final String[] projection = {PACKAGE_NAME, ANOMALY_TYPE, UID};
             final String orderBy = AnomalyDatabaseHelper.AnomalyColumns.TIME_STAMP_MS + " DESC";
 
             try (Cursor cursor = db.query(TABLE_ANOMALY, projection,
@@ -94,6 +96,7 @@
                     AppInfo appInfo = new AppInfo.Builder()
                             .setPackageName(cursor.getString(cursor.getColumnIndex(PACKAGE_NAME)))
                             .setAnomalyType(cursor.getInt(cursor.getColumnIndex(ANOMALY_TYPE)))
+                            .setUid(cursor.getInt(cursor.getColumnIndex(UID)))
                             .build();
                     appInfos.add(appInfo);
                 }
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index 3257d94..f252638 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -158,4 +158,9 @@
     public int compareTo(BatteryTip o) {
         return TIP_ORDER.get(mType) - TIP_ORDER.get(o.mType);
     }
+
+    @Override
+    public String toString() {
+        return "type=" + mType + " state=" + mState;
+    }
 }
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
index 6091131..475ea56 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -86,6 +86,19 @@
         return mHighUsageAppList;
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder stringBuilder = new StringBuilder(super.toString());
+        stringBuilder.append(" {");
+        for (int i = 0, size = mHighUsageAppList.size(); i < size; i++) {
+            final AppInfo appInfo = mHighUsageAppList.get(i);
+            stringBuilder.append(" " + appInfo.toString() + " ");
+        }
+        stringBuilder.append('}');
+
+        return stringBuilder.toString();
+    }
+
     public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
         public BatteryTip createFromParcel(Parcel in) {
             return new HighUsageTip(in);
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
index 4d286be..037457a 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTip.java
@@ -98,6 +98,19 @@
     }
 
     @Override
+    public String toString() {
+        final StringBuilder stringBuilder = new StringBuilder(super.toString());
+        stringBuilder.append(" {");
+        for (int i = 0, size = mRestrictAppList.size(); i < size; i++) {
+            final AppInfo appInfo = mRestrictAppList.get(i);
+            stringBuilder.append(" " + appInfo.toString() + " ");
+        }
+        stringBuilder.append('}');
+
+        return stringBuilder.toString();
+    }
+
+    @Override
     public void writeToParcel(Parcel dest, int flags) {
         super.writeToParcel(dest, flags);
         dest.writeTypedList(mRestrictAppList);
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
index 2dd5ebd..7b5fa04 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -40,7 +40,8 @@
             Lifecycle lifecycle) {
         List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
-        controllers.add(new ZenModeMediaSystemOtherPreferenceController(context, lifecycle));
+        controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
+        controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
         controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
         controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
         controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
@@ -85,7 +86,7 @@
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> keys = super.getNonIndexableKeys(context);
                     keys.add(ZenModeAlarmsPreferenceController.KEY);
-                    keys.add(ZenModeMediaSystemOtherPreferenceController.KEY);
+                    keys.add(ZenModeMediaPreferenceController.KEY);
                     keys.add(ZenModeEventsPreferenceController.KEY);
                     keys.add(ZenModeRemindersPreferenceController.KEY);
                     keys.add(ZenModeMessagesPreferenceController.KEY);
diff --git a/src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java b/src/com/android/settings/notification/ZenModeMediaPreferenceController.java
similarity index 83%
rename from src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java
rename to src/com/android/settings/notification/ZenModeMediaPreferenceController.java
index 8afe881..12cedf2 100644
--- a/src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeMediaPreferenceController.java
@@ -25,13 +25,13 @@
 
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
-public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenModePreferenceController
+public class ZenModeMediaPreferenceController extends AbstractZenModePreferenceController
         implements Preference.OnPreferenceChangeListener {
 
     protected static final String KEY = "zen_mode_media";
     private final ZenModeBackend mBackend;
 
-    public ZenModeMediaSystemOtherPreferenceController(Context context, Lifecycle lifecycle) {
+    public ZenModeMediaPreferenceController(Context context, Lifecycle lifecycle) {
         super(context, KEY, lifecycle);
         mBackend = ZenModeBackend.getInstance(context);
     }
@@ -63,7 +63,7 @@
             default:
                 pref.setEnabled(true);
                 pref.setChecked(mBackend.isPriorityCategoryEnabled(
-                        Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER));
+                        Policy.PRIORITY_CATEGORY_MEDIA));
         }
     }
 
@@ -71,9 +71,9 @@
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         final boolean allowMedia = (Boolean) newValue;
         if (ZenModeSettingsBase.DEBUG) {
-            Log.d(TAG, "onPrefChange allowMediaSystemOther=" + allowMedia);
+            Log.d(TAG, "onPrefChange allowMedia=" + allowMedia);
         }
-        mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allowMedia);
+        mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA, allowMedia);
         return true;
     }
 }
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 272bb41..4e8793b 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -77,9 +77,11 @@
             mContext = context;
         }
 
+        // these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
         private static final int[] ALL_PRIORITY_CATEGORIES = {
                 Policy.PRIORITY_CATEGORY_ALARMS,
-                Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
+                Policy.PRIORITY_CATEGORY_MEDIA,
+                Policy.PRIORITY_CATEGORY_SYSTEM,
                 Policy.PRIORITY_CATEGORY_REMINDERS,
                 Policy.PRIORITY_CATEGORY_EVENTS,
                 Policy.PRIORITY_CATEGORY_MESSAGES,
@@ -104,10 +106,10 @@
                 return mContext.getString(R.string.zen_mode_behavior_total_silence);
             }
 
-            // only alarms and media/system can bypass dnd
+            // only alarms and media can bypass dnd
             if (numCategories == 2 &&
                     isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_ALARMS) &&
-                    isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER)) {
+                    isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MEDIA)) {
                 return mContext.getString(R.string.zen_mode_behavior_alarms_only);
             }
 
@@ -164,9 +166,12 @@
                 if (isCategoryEnabled(policy, category)) {
                     if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
                         enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
-                    } else if (category == Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) {
+                    } else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
                         enabledCategories.add(mContext.getString(
-                                R.string.zen_mode_media_system_other));
+                                R.string.zen_mode_media));
+                    } else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
+                        enabledCategories.add(mContext.getString(
+                                R.string.zen_mode_system));
                     } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
                         enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
                     } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
diff --git a/src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java b/src/com/android/settings/notification/ZenModeSystemPreferenceController.java
similarity index 69%
copy from src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java
copy to src/com/android/settings/notification/ZenModeSystemPreferenceController.java
index 8afe881..364c829 100644
--- a/src/com/android/settings/notification/ZenModeMediaSystemOtherPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeSystemPreferenceController.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -23,17 +23,16 @@
 import android.support.v7.preference.Preference;
 import android.util.Log;
 
+import com.android.internal.logging.nano.MetricsProto;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
-public class ZenModeMediaSystemOtherPreferenceController extends AbstractZenModePreferenceController
-        implements Preference.OnPreferenceChangeListener {
+public class ZenModeSystemPreferenceController extends
+        AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
 
-    protected static final String KEY = "zen_mode_media";
-    private final ZenModeBackend mBackend;
+    protected static final String KEY = "zen_mode_system";
 
-    public ZenModeMediaSystemOtherPreferenceController(Context context, Lifecycle lifecycle) {
+    public ZenModeSystemPreferenceController(Context context, Lifecycle lifecycle) {
         super(context, KEY, lifecycle);
-        mBackend = ZenModeBackend.getInstance(context);
     }
 
     @Override
@@ -58,22 +57,25 @@
                 break;
             case Settings.Global.ZEN_MODE_ALARMS:
                 pref.setEnabled(false);
-                pref.setChecked(true);
+                pref.setChecked(false);
                 break;
             default:
                 pref.setEnabled(true);
                 pref.setChecked(mBackend.isPriorityCategoryEnabled(
-                        Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER));
+                        Policy.PRIORITY_CATEGORY_SYSTEM));
         }
     }
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        final boolean allowMedia = (Boolean) newValue;
+        final boolean allowSystem = (Boolean) newValue;
         if (ZenModeSettingsBase.DEBUG) {
-            Log.d(TAG, "onPrefChange allowMediaSystemOther=" + allowMedia);
+            Log.d(TAG, "onPrefChange allowSystem=" + allowSystem);
         }
-        mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allowMedia);
+
+        mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_SYSTEM,
+                allowSystem);
+        mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_SYSTEM, allowSystem);
         return true;
     }
 }
diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java
index c438d81..21b4c92 100644
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -22,10 +22,10 @@
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
-import com.android.settings.users.AddUserWhenLockedPreferenceController;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.notification.LockScreenNotificationPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.users.AddUserWhenLockedPreferenceController;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 
@@ -130,6 +130,7 @@
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> niks = super.getNonIndexableKeys(context);
                     niks.add(KEY_ADD_USER_FROM_LOCK_SCREEN);
+                    niks.add(KEY_LOCK_SCREEN_NOTIFICATON_WORK_PROFILE);
                     return niks;
                 }
             };
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 3c16b07..4ca7e63 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -41,6 +41,7 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.provider.ContactsContract;
+import android.provider.SearchIndexableResource;
 import android.provider.Settings.Global;
 import android.support.annotation.VisibleForTesting;
 import android.support.annotation.WorkerThread;
@@ -68,7 +69,6 @@
 import com.android.settings.password.ChooseLockGeneric;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
-import com.android.settings.search.SearchIndexableRaw;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 import com.android.settingslib.RestrictedPreference;
@@ -203,7 +203,6 @@
         final Context context = getActivity();
         mAddUserWhenLockedPreferenceController = new AddUserWhenLockedPreferenceController(
                 context, KEY_ADD_USER_WHEN_LOCKED, getLifecycle());
-
         mAutoSyncDataPreferenceController = new AutoSyncDataPreferenceController(context, this);
         mAutoSyncPersonalDataPreferenceController =
                 new AutoSyncPersonalDataPreferenceController(context, this);
@@ -1186,41 +1185,41 @@
     }
 
     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);
-            }
-        };
+            (activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
 
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
-                @Override
-                public List<SearchIndexableRaw> getRawDataToIndex(Context context,
-                        boolean enabled) {
-                    final List<SearchIndexableRaw> result = new ArrayList<>();
-                    final UserCapabilities userCaps = UserCapabilities.create(context);
-                    if (!userCaps.mEnabled) {
-                        return result;
-                    }
-                    final Resources res = context.getResources();
-                    SearchIndexableRaw data = new SearchIndexableRaw(context);
-                    data.title = res.getString(R.string.user_settings_title);
-                    data.key = "users_settings";
-                    data.screenTitle = res.getString(R.string.user_settings_title);
-                    result.add(data);
 
-                    if (userCaps.mCanAddUser || userCaps.mDisallowAddUserSetByAdmin) {
-                        data = new SearchIndexableRaw(context);
-                        data.title = res.getString(userCaps.mCanAddRestrictedProfile ?
-                                R.string.user_add_user_or_profile_menu
-                                : R.string.user_add_user_menu);
-                        data.screenTitle = res.getString(R.string.user_settings_title);
-                        data.key = "user_settings_add_users";
-                        result.add(data);
-                    }
-                    return result;
+                @Override
+                protected boolean isPageSearchEnabled(Context context) {
+                    final UserCapabilities userCaps = UserCapabilities.create(context);
+                    return userCaps.mEnabled;
+                }
+
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final List<SearchIndexableResource> index = new ArrayList<>();
+                    // Append the rest of the settings
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.user_settings;
+                    index.add(sir);
+                    return index;
+                }
+
+                @Override
+                public List<String> getNonIndexableKeysFromXml(Context context, int xmlResId) {
+                    final List<String> niks = super.getNonIndexableKeysFromXml(context, xmlResId);
+                    new AddUserWhenLockedPreferenceController(
+                            context, KEY_ADD_USER_WHEN_LOCKED, null /* lifecycle */)
+                            .updateNonIndexableKeys(niks);
+                    new AutoSyncDataPreferenceController(context, null /* parent */)
+                            .updateNonIndexableKeys(niks);
+                    new AutoSyncPersonalDataPreferenceController(context, null /* parent */)
+                            .updateNonIndexableKeys(niks);
+                    new AutoSyncWorkDataPreferenceController(context, null /* parent */)
+                            .updateNonIndexableKeys(niks);
+                    return niks;
                 }
             };
 
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index 43697bd..223d8f8 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -24,3 +24,4 @@
 com.android.settings.notification.ZenModeEventRuleSettings
 com.android.settings.notification.ZenModeScheduleRuleSettings
 com.android.settings.fuelgauge.RestrictedAppDetails
+com.android.settings.datetime.timezone.TimeZoneSettings
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceControllerTest.java
new file mode 100644
index 0000000..49c468e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/BaseTimeZonePreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.datetime.timezone;
+
+import android.app.Activity;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class BaseTimeZonePreferenceControllerTest {
+
+    private Activity mActivity;
+
+    @Before
+    public void setUp() {
+        mActivity = Robolectric.setupActivity(Activity.class);
+    }
+
+    @Test
+    public void handlePreferenceTreeClick_correctKey_triggerOnClickListener() {
+        String prefKey = "key1";
+        TestClickListener clickListener = new TestClickListener();
+        TestPreference preference = new TestPreference(mActivity, prefKey);
+        TestPreferenceController controller = new TestPreferenceController(mActivity, prefKey);
+        controller.setOnClickListener(clickListener);
+
+        controller.handlePreferenceTreeClick(preference);
+        assertThat(clickListener.isClicked()).isTrue();
+    }
+
+    @Test
+    public void handlePreferenceTreeClick_wrongKey_triggerOnClickListener() {
+        String prefKey = "key1";
+        TestClickListener clickListener = new TestClickListener();
+        TestPreference preference = new TestPreference(mActivity, "wrong_key");
+        TestPreferenceController controller = new TestPreferenceController(mActivity, prefKey);
+        controller.setOnClickListener(clickListener);
+
+        controller.handlePreferenceTreeClick(preference);
+        assertThat(clickListener.isClicked()).isFalse();
+    }
+
+    private static class TestPreferenceController extends BaseTimeZonePreferenceController {
+
+        private final Preference mTestPreference;
+
+        public TestPreferenceController(Context context, String preferenceKey) {
+            super(context, preferenceKey);
+            mTestPreference = new Preference(context);
+            mTestPreference.setKey(preferenceKey);
+        }
+    }
+
+    private static class TestPreference extends Preference {
+        public TestPreference(Context context, String preferenceKey) {
+            super(context);
+            setKey(preferenceKey);
+        }
+    }
+
+    private static class TestClickListener implements OnPreferenceClickListener {
+
+        private boolean isClicked = false;
+
+        @Override
+        public void onClick() {
+            isClicked = true;
+        }
+
+        public boolean isClicked() {
+            return isClicked;
+        }
+
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceControllerTest.java
new file mode 100644
index 0000000..0ffb7d2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/FixedOffsetPreferenceControllerTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.datetime.timezone;
+
+import android.app.Activity;
+import android.icu.util.TimeZone;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class FixedOffsetPreferenceControllerTest {
+
+    private Activity mActivity;
+
+    @Before
+    public void setUp() {
+        mActivity = Robolectric.setupActivity(Activity.class);
+    }
+
+    @Test
+    public void updateState_matchTimeZoneSummary() {
+        TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
+                    TimeZone.getFrozenTimeZone("Etc/GMT-8"))
+                    .setExemplarLocation("Los Angeles")
+                    .setGmtOffset("GMT-08:00")
+                    .setItemId(0)
+                    .build();
+        Preference preference = new Preference(mActivity);
+        FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
+        controller.setTimeZoneInfo(fixedOffsetZone);
+        controller.updateState(preference);
+        assertThat(preference.getSummary()).isEqualTo("GMT-08:00");
+
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/RegionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/RegionPreferenceControllerTest.java
new file mode 100644
index 0000000..7a8f267
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/RegionPreferenceControllerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.datetime.timezone;
+
+import android.app.Activity;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class RegionPreferenceControllerTest {
+
+    private Activity mActivity;
+
+    @Before
+    public void setUp() {
+        mActivity = Robolectric.setupActivity(Activity.class);
+    }
+
+    @Test
+    public void updateState_matchCountryName() {
+        Preference preference = new Preference(mActivity);
+        RegionPreferenceController controller = new RegionPreferenceController(mActivity);
+        controller.setRegionId("US");
+        controller.updateState(preference);
+        assertThat(controller.getSummary()).isEqualTo("United States");
+        assertThat(preference.getSummary()).isEqualTo("United States");
+
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/RegionZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/RegionZonePreferenceControllerTest.java
new file mode 100644
index 0000000..b39641f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/RegionZonePreferenceControllerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.datetime.timezone;
+
+import android.app.Activity;
+import android.icu.util.TimeZone;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+
+import static com.google.common.truth.Truth.assertThat;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class RegionZonePreferenceControllerTest {
+
+    private Activity mActivity;
+
+    @Before
+    public void setUp() {
+        mActivity = Robolectric.setupActivity(Activity.class);
+    }
+
+    @Test
+    public void updateState_matchTimeZoneName() {
+        TimeZoneInfo tzInfo = new TimeZoneInfo.Builder(
+                TimeZone.getFrozenTimeZone("America/Los_Angeles"))
+                .setGenericName("Pacific Time")
+                .setStandardName("Pacific Standard Time")
+                .setDaylightName("Pacific Daylight Time")
+                .setExemplarLocation("Los Angeles")
+                .setGmtOffset("GMT-08:00")
+                .setItemId(0)
+                .build();
+        Preference preference = new Preference(mActivity);
+        RegionZonePreferenceController controller = new RegionZonePreferenceController(mActivity);
+        controller.setTimeZoneInfo(tzInfo);
+        controller.setClickable(false);
+        controller.updateState(preference);
+        String expectedSummary = "Los Angeles (GMT-08:00)";
+        assertThat(controller.getSummary().toString()).isEqualTo(expectedSummary);
+        assertThat(preference.getSummary().toString()).isEqualTo(expectedSummary);
+        assertThat(preference.isEnabled()).isFalse();
+
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceControllerTest.java
new file mode 100644
index 0000000..2a58770
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneInfoPreferenceControllerTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.datetime.timezone;
+
+import android.support.v7.preference.Preference;
+
+import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.Date;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.spy;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class TimeZoneInfoPreferenceControllerTest {
+
+    @Test
+    public void updateState_matchExpectedFormattedText() {
+        Date now = new Date(0L); // 00:00 1/1/1970
+        Formatter formatter = new Formatter(Locale.US, now);
+
+        TimeZoneInfo timeZoneInfo = formatter.format("America/Los_Angeles");
+        TimeZoneInfoPreferenceController controller =
+                new TimeZoneInfoPreferenceController(RuntimeEnvironment.application, now);
+        controller.setTimeZoneInfo(timeZoneInfo);
+        Preference preference = spy(new Preference(RuntimeEnvironment.application));
+        controller.updateState(preference);
+        assertEquals("Uses Pacific Time (GMT-08:00). "
+                + "Pacific Daylight Time starts on April 26, 1970.",
+                preference.getTitle().toString());
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneSettingsTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneSettingsTest.java
new file mode 100644
index 0000000..21ca30d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneSettingsTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.datetime.timezone;
+
+import com.android.settings.datetime.timezone.model.TimeZoneData;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {
+                SettingsShadowResources.class,
+                SettingsShadowResources.SettingsShadowTheme.class,
+        })
+public class TimeZoneSettingsTest {
+
+    @Test
+    public void findRegionIdForTzId_matchExpectedCountry() {
+        String tzId = "Unknown/Secret_City";
+        TimeZoneData timeZoneData = mock(TimeZoneData.class);
+        when(timeZoneData.lookupCountryCodesForZoneId(tzId))
+                .thenReturn(new HashSet<>(Arrays.asList("US", "GB")));
+
+        TimeZoneSettings settings = new TimeZoneSettings();
+        settings.setTimeZoneData(timeZoneData);
+        assertThat(settings.findRegionIdForTzId(tzId, null, "")).matches("US|GB");
+        assertThat(settings.findRegionIdForTzId(tzId, "GB", "")).isEqualTo("GB");
+        assertThat(settings.findRegionIdForTzId(tzId, null, "GB")).isEqualTo("GB");
+    }
+
+    @Test
+    public void createPreferenceControllers_matchExpectedControllers() {
+        TimeZoneSettings settings = new TimeZoneSettings();
+        List<AbstractPreferenceController> controllers =
+                settings.createPreferenceControllers(RuntimeEnvironment.application);
+        assertThat(controllers).hasSize(4);
+        assertThat(controllers.get(0)).isInstanceOf(RegionPreferenceController.class);
+        assertThat(controllers.get(1)).isInstanceOf(RegionZonePreferenceController.class);
+        assertThat(controllers.get(2)).isInstanceOf(TimeZoneInfoPreferenceController.class);
+        assertThat(controllers.get(3)).isInstanceOf(FixedOffsetPreferenceController.class);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDatabaseManagerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryDatabaseManagerTest.java
index 8b4ff53..6360232 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryDatabaseManagerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryDatabaseManagerTest.java
@@ -42,8 +42,10 @@
 public class BatteryDatabaseManagerTest {
 
     private static String PACKAGE_NAME_NEW = "com.android.app1";
+    private static int UID_NEW = 345;
     private static int TYPE_NEW = 1;
     private static String PACKAGE_NAME_OLD = "com.android.app2";
+    private static int UID_OLD = 543;
     private static int TYPE_OLD = 2;
     private static long NOW = System.currentTimeMillis();
     private static long ONE_DAY_BEFORE = NOW - DateUtils.DAY_IN_MILLIS;
@@ -67,23 +69,23 @@
 
     @Test
     public void testAllFunctions() {
-        mBatteryDatabaseManager.insertAnomaly(PACKAGE_NAME_NEW, TYPE_NEW,
+        mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW,
                 AnomalyDatabaseHelper.State.NEW, NOW);
-        mBatteryDatabaseManager.insertAnomaly(PACKAGE_NAME_OLD, TYPE_OLD,
+        mBatteryDatabaseManager.insertAnomaly(UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD,
                 AnomalyDatabaseHelper.State.NEW, TWO_DAYS_BEFORE);
 
         // In database, it contains two record
         List<AppInfo> totalAppInfos = mBatteryDatabaseManager.queryAllAnomalies(0 /* timeMsAfter */,
                 AnomalyDatabaseHelper.State.NEW);
         assertThat(totalAppInfos).hasSize(2);
-        assertAppInfo(totalAppInfos.get(0), PACKAGE_NAME_NEW, TYPE_NEW);
-        assertAppInfo(totalAppInfos.get(1), PACKAGE_NAME_OLD, TYPE_OLD);
+        assertAppInfo(totalAppInfos.get(0), UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW);
+        assertAppInfo(totalAppInfos.get(1), UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD);
 
         // Only one record shows up if we query by timestamp
         List<AppInfo> appInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
                 AnomalyDatabaseHelper.State.NEW);
         assertThat(appInfos).hasSize(1);
-        assertAppInfo(appInfos.get(0), PACKAGE_NAME_NEW, TYPE_NEW);
+        assertAppInfo(appInfos.get(0), UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW);
 
         mBatteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(ONE_DAY_BEFORE);
 
@@ -91,14 +93,14 @@
         List<AppInfo> appInfos1 = mBatteryDatabaseManager.queryAllAnomalies(0 /* timeMsAfter */,
                 AnomalyDatabaseHelper.State.NEW);
         assertThat(appInfos1).hasSize(1);
-        assertAppInfo(appInfos1.get(0), PACKAGE_NAME_NEW, TYPE_NEW);
+        assertAppInfo(appInfos1.get(0), UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW);
     }
 
     @Test
     public void testUpdateAnomalies_updateSuccessfully() {
-        mBatteryDatabaseManager.insertAnomaly(PACKAGE_NAME_NEW, TYPE_NEW,
+        mBatteryDatabaseManager.insertAnomaly(UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW,
                 AnomalyDatabaseHelper.State.NEW, NOW);
-        mBatteryDatabaseManager.insertAnomaly(PACKAGE_NAME_OLD, TYPE_OLD,
+        mBatteryDatabaseManager.insertAnomaly(UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD,
                 AnomalyDatabaseHelper.State.NEW, NOW);
         final AppInfo appInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME_OLD).build();
         final List<AppInfo> updateAppInfos = new ArrayList<>();
@@ -112,17 +114,18 @@
         List<AppInfo> newAppInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
                 AnomalyDatabaseHelper.State.NEW);
         assertThat(newAppInfos).hasSize(1);
-        assertAppInfo(newAppInfos.get(0), PACKAGE_NAME_NEW, TYPE_NEW);
+        assertAppInfo(newAppInfos.get(0), UID_NEW, PACKAGE_NAME_NEW, TYPE_NEW);
 
         // The state of PACKAGE_NAME_OLD is changed to handled
         List<AppInfo> handledAppInfos = mBatteryDatabaseManager.queryAllAnomalies(ONE_DAY_BEFORE,
                 AnomalyDatabaseHelper.State.HANDLED);
         assertThat(handledAppInfos).hasSize(1);
-        assertAppInfo(handledAppInfos.get(0), PACKAGE_NAME_OLD, TYPE_OLD);
+        assertAppInfo(handledAppInfos.get(0), UID_OLD, PACKAGE_NAME_OLD, TYPE_OLD);
     }
 
-    private void assertAppInfo(final AppInfo appInfo, String packageName, int type) {
+    private void assertAppInfo(final AppInfo appInfo, int uid, String packageName, int type) {
         assertThat(appInfo.packageName).isEqualTo(packageName);
         assertThat(appInfo.anomalyType).isEqualTo(type);
+        assertThat(appInfo.uid).isEqualTo(uid);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AppInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AppInfoTest.java
index 155351a..b140c4c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AppInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AppInfoTest.java
@@ -38,6 +38,7 @@
     private static final String PACKAGE_NAME = "com.android.app";
     private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
     private static final long SCREEN_TIME_MS = DateUtils.HOUR_IN_MILLIS;
+    private static final int UID = 3452;
 
     private AppInfo mAppInfo;
 
@@ -47,6 +48,7 @@
                 .setPackageName(PACKAGE_NAME)
                 .setAnomalyType(ANOMALY_TYPE)
                 .setScreenOnTimeMs(SCREEN_TIME_MS)
+                .setUid(UID)
                 .build();
     }
 
@@ -61,6 +63,7 @@
         assertThat(appInfo.packageName).isEqualTo(PACKAGE_NAME);
         assertThat(appInfo.anomalyType).isEqualTo(ANOMALY_TYPE);
         assertThat(appInfo.screenOnTimeMs).isEqualTo(SCREEN_TIME_MS);
+        assertThat(appInfo.uid).isEqualTo(UID);
     }
 
     @Test
@@ -84,5 +87,6 @@
         assertThat(mAppInfo.packageName).isEqualTo(PACKAGE_NAME);
         assertThat(mAppInfo.anomalyType).isEqualTo(ANOMALY_TYPE);
         assertThat(mAppInfo.screenOnTimeMs).isEqualTo(SCREEN_TIME_MS);
+        assertThat(mAppInfo.uid).isEqualTo(UID);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
index 85c8ffc..753fc48 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
@@ -52,7 +52,7 @@
     }
 
     @Test
-    public void testBuildPreference() {
+    public void buildPreference() {
         final Preference preference = mBatteryTip.buildPreference(mContext);
 
         assertThat(preference.getTitle()).isEqualTo(TITLE);
@@ -61,7 +61,7 @@
     }
 
     @Test
-    public void testParcelable() {
+    public void parcelable() {
         final BatteryTip batteryTip = new TestBatteryTip();
 
         Parcel parcel = Parcel.obtain();
@@ -76,7 +76,7 @@
     }
 
     @Test
-    public void testTipOrder_orderUnique() {
+    public void tipOrder_orderUnique() {
         final List<Integer> orders = new ArrayList<>();
         for (int i = 0, size = BatteryTip.TIP_ORDER.size(); i < size; i++) {
             orders.add(BatteryTip.TIP_ORDER.valueAt(i));
@@ -85,6 +85,11 @@
         assertThat(orders).containsNoDuplicates();
     }
 
+    @Test
+    public void toString_containBatteryTipData() {
+        assertThat(mBatteryTip.toString()).isEqualTo("type=6 state=0");
+    }
+
     /**
      * Used to test the non abstract methods in {@link TestBatteryTip}
      */
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
index db2f37e..af32dc5 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
@@ -73,4 +73,10 @@
         assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
         assertThat(app.screenOnTimeMs).isEqualTo(SCREEN_TIME);
     }
+
+    @Test
+    public void toString_containsAppData() {
+        assertThat(mBatteryTip.toString()).isEqualTo(
+                "type=2 state=0 { packageName=com.android.app,anomalyType=0,screenTime=1800000 }");
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTipTest.java
index 20b896f..3298ea8 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/RestrictAppTipTest.java
@@ -71,7 +71,7 @@
     }
 
     @Test
-    public void testParcelable() {
+    public void parcelable() {
         Parcel parcel = Parcel.obtain();
         mNewBatteryTip.writeToParcel(parcel, mNewBatteryTip.describeContents());
         parcel.setDataPosition(0);
@@ -85,40 +85,46 @@
     }
 
     @Test
-    public void testGetTitle_stateNew_showRestrictTitle() {
+    public void getTitle_stateNew_showRestrictTitle() {
         assertThat(mNewBatteryTip.getTitle(mContext)).isEqualTo("Restrict 1 app");
     }
 
     @Test
-    public void testGetTitle_stateHandled_showHandledTitle() {
+    public void getTitle_stateHandled_showHandledTitle() {
         assertThat(mHandledBatteryTip.getTitle(mContext)).isEqualTo("1 recently restricted");
     }
 
     @Test
-    public void testGetSummary_stateNew_showRestrictSummary() {
+    public void getSummary_stateNew_showRestrictSummary() {
         assertThat(mNewBatteryTip.getSummary(mContext))
             .isEqualTo("app has high battery usage");
     }
 
     @Test
-    public void testGetSummary_stateHandled_showHandledSummary() {
+    public void getSummary_stateHandled_showHandledSummary() {
         assertThat(mHandledBatteryTip.getSummary(mContext))
             .isEqualTo("App changes are in progress");
     }
 
     @Test
-    public void testUpdate_anomalyBecomeInvisible_stateHandled() {
+    public void update_anomalyBecomeInvisible_stateHandled() {
         mNewBatteryTip.updateState(mInvisibleBatteryTip);
 
         assertThat(mNewBatteryTip.getState()).isEqualTo(BatteryTip.StateType.HANDLED);
     }
 
     @Test
-    public void testUpdate_newAnomalyComes_stateNew() {
+    public void update_newAnomalyComes_stateNew() {
         mInvisibleBatteryTip.updateState(mNewBatteryTip);
         assertThat(mInvisibleBatteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
 
         mHandledBatteryTip.updateState(mNewBatteryTip);
         assertThat(mHandledBatteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
     }
+
+    @Test
+    public void toString_containsAppData() {
+        assertThat(mNewBatteryTip.toString()).isEqualTo(
+                "type=1 state=0 { packageName=com.android.app,anomalyType=0,screenTime=0 }");
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMediaPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMediaPreferenceControllerTest.java
index db0a2e9..db828a2 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMediaPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeMediaPreferenceControllerTest.java
@@ -46,10 +46,7 @@
 
 @RunWith(SettingsRobolectricTestRunner.class)
 public class ZenModeMediaPreferenceControllerTest {
-
-    private static final boolean MEDIA_SETTINGS = true;
-
-    private ZenModeMediaSystemOtherPreferenceController mController;
+    private ZenModeMediaPreferenceController mController;
 
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     private Context mContext;
@@ -75,7 +72,7 @@
         mContentResolver = RuntimeEnvironment.application.getContentResolver();
         when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
 
-        mController = new ZenModeMediaSystemOtherPreferenceController(mContext,
+        mController = new ZenModeMediaPreferenceController(mContext,
                 mock(Lifecycle.class));
         ReflectionHelpers.setField(mController, "mBackend", mBackend);
 
@@ -111,13 +108,13 @@
         Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
 
         when(mBackend.isPriorityCategoryEnabled(
-                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER)).
-                thenReturn(MEDIA_SETTINGS);
+                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA)).
+                thenReturn(true);
 
         mController.updateState(mockPref);
 
         verify(mockPref).setEnabled(true);
-        verify(mockPref).setChecked(MEDIA_SETTINGS);
+        verify(mockPref).setChecked(true);
     }
 
     @Test
@@ -126,7 +123,7 @@
         mController.onPreferenceChange(mockPref, allow);
 
         verify(mBackend).saveSoundPolicy(
-                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allow);
+                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA, allow);
     }
 
     @Test
@@ -135,6 +132,6 @@
         mController.onPreferenceChange(mockPref, allow);
 
         verify(mBackend).saveSoundPolicy(
-                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER, allow);
+                NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA, allow);
     }
 }
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index 66b11a6..5c81efc 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -52,7 +52,7 @@
                 NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS
                         | NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS
                         | NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
-                        | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
+                        | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
                 0, 0);
         final String result = mBuilder.getBehaviorSettingSummary(policy,
                 Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
@@ -75,7 +75,7 @@
     public void testGetBehaviorSettingSummary_alarmsAndMedia() {
         NotificationManager.Policy policy = new NotificationManager.Policy(
                         NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
-                        | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
+                        | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
                 0, 0);
         final String result = mBuilder.getBehaviorSettingSummary(policy,
                 Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSystemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSystemPreferenceControllerTest.java
new file mode 100644
index 0000000..46dfc69
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSystemPreferenceControllerTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.notification;
+
+import static android.provider.Settings.Global.ZEN_MODE;
+import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
+import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
+import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
+
+import static junit.framework.Assert.assertEquals;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+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.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModeSystemPreferenceControllerTest {
+    private ZenModeSystemPreferenceController mController;
+
+    @Mock
+    private ZenModeBackend mBackend;
+    @Mock
+    private NotificationManager mNotificationManager;
+    @Mock
+    private SwitchPreference mockPref;
+    @Mock
+    private NotificationManager.Policy mPolicy;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+
+    private Context mContext;
+    private ContentResolver mContentResolver;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        ShadowApplication shadowApplication = ShadowApplication.getInstance();
+        shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+        mContext = shadowApplication.getApplicationContext();
+        mContentResolver = RuntimeEnvironment.application.getContentResolver();
+        when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+        mController = new ZenModeSystemPreferenceController(mContext, mock(Lifecycle.class));
+        ReflectionHelpers.setField(mController, "mBackend", mBackend);
+
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mockPref);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void updateState_TotalSilence() {
+        Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
+
+        final SwitchPreference mockPref = mock(SwitchPreference.class);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setEnabled(false);
+        verify(mockPref).setChecked(false);
+    }
+
+    @Test
+    public void updateState_AlarmsOnly() {
+        Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
+
+        final SwitchPreference mockPref = mock(SwitchPreference.class);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setEnabled(false);
+        verify(mockPref).setChecked(false);
+    }
+
+    @Test
+    public void updateState_Priority() {
+        Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+
+        when(mBackend.isPriorityCategoryEnabled(
+                NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM)).thenReturn(true);
+
+        mController.updateState(mockPref);
+
+        verify(mockPref).setEnabled(true);
+        verify(mockPref).setChecked(true);
+    }
+
+    @Test
+    public void onPreferenceChanged_EnableSystem() {
+        mController.onPreferenceChange(mockPref, true);
+
+        verify(mBackend).saveSoundPolicy(NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM,
+                true);
+    }
+
+    @Test
+    public void onPreferenceChanged_DisableSystem() {
+        mController.onPreferenceChange(mockPref, false);
+
+        verify(mBackend).saveSoundPolicy(NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM,
+                false);
+    }
+}
\ No newline at end of file
diff --git a/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java b/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
index 109c3bc..30206bc 100644
--- a/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
+++ b/tests/uitests/src/com/android/settings/ui/ZonePickerSettingsTest.java
@@ -32,8 +32,6 @@
 import android.support.test.uiautomator.Until;
 import android.system.helpers.SettingsHelper;
 import android.system.helpers.SettingsHelper.SettingsType;
-import android.widget.ListView;
-import android.widget.Spinner;
 
 import org.junit.After;
 import org.junit.Before;
@@ -102,16 +100,16 @@
     // Test 2 time zones with no DST
     @Test
     public void testSelectReykjavik() throws Exception {
-        testSelectTimeZone("Iceland", "Reykjavik", "GMT+00:00", "Atlantic/Reykjavik");
+        testSelectTimeZone("Iceland", "Reykjavik", "GMT+00:00", "Atlantic/Reykjavik", true);
     }
 
     @Test
     public void testSelectPhoenix() throws Exception {
-        testSelectTimeZone("United States", "Phoenix", "GMT-07:00", "America/Phoenix");
+        testSelectTimeZone("United States", "Phoenix", "GMT-07:00", "America/Phoenix", false);
     }
 
     private void testSelectTimeZone(String region, String timezone, String expectedTimeZoneOffset,
-            String expectedTimeZoneId) throws Exception {
+            String expectedTimeZoneId, boolean assumeOneTimeZoneInRegion) throws Exception {
         mHelper.setIntSetting(SettingsType.GLOBAL, Settings.Global.AUTO_TIME_ZONE, 0);
 
         SettingsHelper.launchSettingsPage(
@@ -121,16 +119,21 @@
         assertTrue(selectTimeZone.isEnabled());
         selectTimeZone.click();
 
-        // Select region in the dropdown list
-        selectScrollableItem(selectDropDownInSpinner(By.clazz(Spinner.class)),
-                new UiSelector().textContains(region))
+        wait(By.text("Region")).click();
+        // Speed-up the test by searching with the first 2 characters of the region name
+        wait(By.res("android", "search_src_text")).setText(region.substring(0, 2));
+        // Select region in the list
+        selectItemInList(new UiSelector().textContains(region))
                 .click();
 
-        // Select time zone
-        selectScrollableItem(selectTimeZoneList(),
-                new UiSelector().textContains(timezone))
-                .click();
+        // Only select time zone explicitly if there are more than one time zones in a region
+        if (!assumeOneTimeZoneInRegion) {
+            wait(By.text("Time Zone"));
+            selectItemInList(new UiSelector().textContains(timezone))
+                    .click();
+        }
 
+        mDevice.pressBack();
         // The select button should include the GMT offset in the summary
         BySelector summarySelector = By.res("android:id/summary");
         UiObject2 selectedTimeZone = selectTimeZone.findObject(summarySelector);
@@ -162,21 +165,10 @@
         assertEquals(expectedTimeZoneId, TimeZone.getDefault().getID());
     }
 
-    /**
-     * Perform click on {@link Spinner} and return the pop-up dropdown list.
-     * @return UiScrollable representing the pop-up dropdown after clicking on the spinner
-     */
-    private UiScrollable selectDropDownInSpinner(BySelector spinnerSelector)
-            throws UiObjectNotFoundException {
-        UiObject2 spinner = wait(spinnerSelector);
-        spinner.click();
-
-        UiSelector dropDownSelector = new UiSelector().className(ListView.class);
-        return new UiScrollable(dropDownSelector);
-    }
-
-    private UiScrollable selectTimeZoneList() {
-        return new UiScrollable(new UiSelector().resourceId(SETTINGS_PACKAGE + ":id/tz_list"));
+    private UiObject selectItemInList(UiSelector childSelector) throws UiObjectNotFoundException {
+        UiScrollable recyclerView = new UiScrollable(
+                new UiSelector().resourceId(SETTINGS_PACKAGE + ":id/recycler_view"));
+        return selectScrollableItem(recyclerView, childSelector);
     }
 
     /**