Merge "Increase string character limits to 40" into pi-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e6e6d89..efaa89b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1136,25 +1136,25 @@
 
     <!-- Security Picker --><skip />
 
-    <!-- Title for suggested actions for screen lock [CHAR LIMIT=34] -->
-    <string name="suggested_lock_settings_title">Set screen lock for security</string>
+    <!-- Title for suggested actions for screen lock [CHAR LIMIT=46] -->
+    <string name="suggested_lock_settings_title">Secure your phone</string>
 
-    <!-- Summary for suggested actions for screen lock (tablet) -->
-    <string name="suggested_lock_settings_summary" product="tablet">Prevent others from using your tablet</string>
-    <!-- Summary for suggested actions for screen lock (device) -->
-    <string name="suggested_lock_settings_summary" product="device">Prevent others from using your device</string>
-    <!-- Summary for suggested actions for screen lock (phone) -->
-    <string name="suggested_lock_settings_summary" product="default">Prevent others from using your phone</string>
+    <!-- Summary for suggested actions for screen lock (tablet) [CHAR LIMIT=55] -->
+    <string name="suggested_lock_settings_summary" product="tablet">Set screen lock to protect tablet</string>
+    <!-- Summary for suggested actions for screen lock (device) [CHAR LIMIT=55] -->
+    <string name="suggested_lock_settings_summary" product="device">Set screen lock to protect device</string>
+    <!-- Summary for suggested actions for screen lock (phone) [CHAR LIMIT=55] -->
+    <string name="suggested_lock_settings_summary" product="default">Set screen lock to protect phone</string>
 
-    <!-- Title for suggested actions for settings up a fingerprint lock [CHAR LIMIT=34] -->
+    <!-- Title for suggested actions for settings up a fingerprint lock [CHAR LIMIT=46] -->
     <string name="suggested_fingerprint_lock_settings_title">Unlock with fingerprint</string>
 
-    <!-- Summary for suggested actions for settings up a fingerprint lock (tablet)  -->
-    <string name="suggested_fingerprint_lock_settings_summary" product="tablet">Unlock with your fingerprint</string>
-    <!-- Summary for suggested actions for settings up a fingerprint lock (device)  -->
-    <string name="suggested_fingerprint_lock_settings_summary" product="device">Unlock with your fingerprint</string>
-    <!-- Summary for suggested actions for settings up a fingerprint lock (phone)  -->
-    <string name="suggested_fingerprint_lock_settings_summary" product="default">Unlock with your fingerprint</string>
+    <!-- Summary for suggested actions for settings up a fingerprint lock (tablet) [CHAR LIMIT=55] -->
+    <string name="suggested_fingerprint_lock_settings_summary" product="tablet"></string>
+    <!-- Summary for suggested actions for settings up a fingerprint lock (device) [CHAR LIMIT=55] -->
+    <string name="suggested_fingerprint_lock_settings_summary" product="device"></string>
+    <!-- Summary for suggested actions for settings up a fingerprint lock (phone) [CHAR LIMIT=55] -->
+    <string name="suggested_fingerprint_lock_settings_summary" product="default"></string>
 
     <!--  Title for security picker to choose the unlock method: None/Pattern/PIN/Password [CHAR LIMIT=22] -->
     <string name="lock_settings_picker_title">Choose screen lock</string>
@@ -1676,10 +1676,10 @@
     <string name="bluetooth_max_connected_audio_devices_string">Maximum connected Bluetooth audio devices</string>
     <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
     <string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>
-    <!-- Bluetooth developer settings: Checkbox title for enabling Bluetooth receiving AVDTP delay reports -->
-    <string name="bluetooth_enable_avdtp_delay_reports">Enable Bluetooth AVDTP delay reports</string>
-    <!-- Bluetooth developer settings: Summary of checkbox for enabling Bluetooth receiving AVDTP delay reports -->
-    <string name="bluetooth_enable_avdtp_delay_reports_summary">Allow receiving Bluetooth AVDTP delay reports</string>
+    <!-- Bluetooth developer settings: Checkbox title for disabling Bluetooth receiving AVDTP delay reports -->
+    <string name="bluetooth_disable_avdtp_delay_reports">Disable Bluetooth AVDTP delay reports</string>
+    <!-- Bluetooth developer settings: Summary of checkbox for disabling Bluetooth receiving AVDTP delay reports -->
+    <string name="bluetooth_disable_avdtp_delay_reports_summary">Disallow receiving Bluetooth AVDTP delay reports</string>
 
     <!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
     <string name="wifi_display_settings_title">Cast</string>
@@ -2251,10 +2251,10 @@
 
     <!-- Wireless networks, item title to go into the WFC settings [CHAR LIMIT=30] -->
     <string name="wifi_calling_settings_title">Wi-Fi calling</string>
-    <!-- Title of suggestion to turn on wifi calling [CHAR LIMIT=30] -->
-    <string name="wifi_calling_suggestion_title">Extend call coverage with Wi\u2011Fi</string>
-    <!-- Summary of suggestion to turn on wifi calling [CHAR LIMIT=60] -->
-    <string name="wifi_calling_suggestion_summary">Turn on Wi\u2011Fi calling</string>
+    <!-- Title of suggestion to turn on wifi calling [CHAR LIMIT=46] -->
+    <string name="wifi_calling_suggestion_title">Extend calls with Wi\u2011Fi</string>
+    <!-- Summary of suggestion to turn on wifi calling [CHAR LIMIT=55] -->
+    <string name="wifi_calling_suggestion_summary">Turn on Wi\u2011Fi calling to extend coverage</string>
     <!-- Title of WFC preference item [CHAR LIMIT=30] -->
     <string name="wifi_calling_mode_title">Calling preference</string>
     <!-- Title of WFC preference selection dialog [CHAR LIMIT=30] -->
@@ -2532,9 +2532,9 @@
     <string name="wallpaper_settings_summary_default">Default</string>
     <!-- Wallpaper settings summary when wallpaper has been updated [CHAR LIMIT=NONE] -->
     <string name="wallpaper_settings_summary_custom">Custom</string>
-    <!-- Wallpaper suggestion title [CHAR LIMIT=30] -->
+    <!-- Wallpaper suggestion title [CHAR LIMIT=46] -->
     <string name="wallpaper_suggestion_title">Change wallpaper</string>
-    <!-- Wallpaper suggestion title [CHAR LIMIT=60] -->
+    <!-- Wallpaper suggestion summary [CHAR LIMIT=55] -->
     <string name="wallpaper_suggestion_summary">Personalize your screen</string>
     <!-- Wallpaper settings fragment title [CHAR LIMIT=30] -->
     <string name="wallpaper_settings_fragment_title">Choose wallpaper from</string>
@@ -6917,6 +6917,9 @@
     <!-- Do not disturb: Title for the page describing what can bypass DND. [CHAR LIMIT=30] -->
     <string name="zen_mode_behavior_settings_title">Exceptions</string>
 
+    <!-- Do not disturb: Title for the dnd duration setting (user can specify how long dnd will last when toggling dnd on from qs or settings) [CHAR LIMIT=30] -->
+    <string name="zen_mode_duration_settings_title">Duration</string>
+
     <!-- Do not disturb: Instructions indicating what types of sounds can bypass DND. [CHAR LIMIT=52] -->
     <string name="zen_mode_behavior_allow_title">Allow sounds and vibrations from</string>
 
@@ -6941,10 +6944,10 @@
     <!--  Do not disturb: Title for a specific zen mode automatic rule in settings. [CHAR LIMIT=30] -->
     <string name="zen_mode_automatic_rule_settings_page_title">Automatic rule</string>
 
-    <!--  Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=34] -->
+    <!--  Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=46] -->
     <string name="zen_mode_automation_suggestion_title">Silence phone at certain times</string>
 
-    <!--  Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=NONE] -->
+    <!--  Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=55] -->
     <string name="zen_mode_automation_suggestion_summary">Set Do Not Disturb rules</string>
 
     <!--  Do not disturb: Switch toggle to toggle whether to use an automatic dnd rule or not [CHAR LIMIT=40] -->
@@ -7038,6 +7041,21 @@
     <!-- Sound settings screen, summary format of do not disturb when on with no extra information. [CHAR LIMIT=NONE] -->
     <string name="zen_mode_sound_summary_on">On</string>
 
+    <!--  Do not disturb: Summary for zen mode duration setting indicating user will be prompted to set dnd duration whenever dnd is manually toggled on [CHAR LIMIT=NONE]-->
+    <string name="zen_mode_duration_summary_always_prompt">Ask every time (unless turned on automatically)</string>
+
+    <!--  Do not disturb: Summary for zen mode duration setting indicating how long dnd will last when dnd is manually toggled on [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_duration_summary_forever">Until you turn off (unless turned on automatically)</string>
+
+    <!--  Do not disturb: Summary for zen mode duration setting indicating how long dnd will last when dnd is manually toggled on [CHAR LIMIT=NONE] -->
+    <plurals name="zen_mode_duration_summary_time_hours">
+        <item quantity="one">1 hour (unless turned on automatically)</item>
+        <item quantity="other"><xliff:g id="num_hours" example="3">%d</xliff:g> hours (unless turned on automatically)</item>
+    </plurals>
+
+    <!--  Do not disturb: Summary for zen mode duration setting indicating how long dnd will last when toggled on -->
+    <string name="zen_mode_duration_summary_time_minutes"><xliff:g id="num_minutes" example="5">%d</xliff:g> minutes (unless turned on automatically)</string>
+
     <!-- Summary for the Sound Do not Disturb option when at least one automatic rules is enabled. [CHAR LIMIT=NONE]-->
     <plurals name="zen_mode_sound_summary_summary_off_info">
         <item quantity="one">1 rule can turn on automatically</item>
@@ -8557,10 +8575,10 @@
     <!-- Summary of condition that work mode is off [CHAR LIMIT=NONE] -->
     <string name="condition_work_summary">Apps, background sync, and other features related to your work profile are turned off.</string>
 
-    <!--  Night display: Title for the night display option Suggestion (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
+    <!--  Night display: Title for the night display option Suggestion (renamed "Night Light" with title caps). [CHAR LIMIT=46] -->
     <string name="night_display_suggestion_title">Set Night Light schedule</string>
 
-    <!--  Night display: Summary for the night display option Suggestion (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
+    <!--  Night display: Summary for the night display option Suggestion (renamed "Night Light" with title caps). [CHAR LIMIT=55] -->
     <string name="night_display_suggestion_summary">Automatically tint screen every night</string>
 
     <!-- Title of condition that night display is on (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
@@ -8768,10 +8786,10 @@
     <!-- Summary of the preference controlling whether the device encryption *password* must be entered before being able to start the device. [CHAR LIMIT=NONE]-->
     <string name="lockpattern_settings_require_password_before_startup_summary">Require password to start up your device. While off, this device can\'t receive calls, messages, notifications, or alarms.</string>
 
-    <!-- Title for suggestion adding more fingerprints [CHAR LIMIT=30] -->
+    <!-- Title for suggestion adding more fingerprints [CHAR LIMIT=46] -->
     <string name="suggestion_additional_fingerprints">Add another fingerprint</string>
 
-    <!-- Summary for suggestion adding more fingerprints [CHAR LIMIT=60] -->
+    <!-- Summary for suggestion adding more fingerprints [CHAR LIMIT=55] -->
     <string name="suggestion_additional_fingerprints_summary">Unlock with a different finger</string>
 
     <!-- Summary of battery saver when on [CHAR LIMIT=NONE] -->
@@ -9452,4 +9470,13 @@
     <!-- Summary for media output settings when the media stream is being captured by something else. -->
     <string name="media_output_summary_unavailable">Unavailable</string>
 
+    <!--  Title for battery Suggestion. (tablet) [CHAR LIMIT=46] -->
+    <string name="battery_suggestion_title" product="tablet" >Improve tablet\'s battery life</string>
+    <!--  Title for battery Suggestion. (device) [CHAR LIMIT=46] -->
+    <string name="battery_suggestion_title" product="device" >Improve device\'s battery life</string>
+    <!--  Title for battery Suggestion. (phone) [CHAR LIMIT=46] -->
+    <string name="battery_suggestion_title" product="default" >Improve phone\'s battery life</string>
+    <!--  Summary for battery Suggestion. [CHAR LIMIT=55] -->
+    <string name="battery_suggestion_summary"></string>
+
 </resources>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 571f38e..282a5121 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -264,9 +264,9 @@
             android:summary="@string/bluetooth_disable_inband_ringing_summary" />
 
         <SwitchPreference
-            android:key="bluetooth_enable_avdtp_delay_reports"
-            android:title="@string/bluetooth_enable_avdtp_delay_reports"
-            android:summary="@string/bluetooth_enable_avdtp_delay_reports_summary"/>
+            android:key="bluetooth_disable_avdtp_delay_reports"
+            android:title="@string/bluetooth_disable_avdtp_delay_reports"
+            android:summary="@string/bluetooth_disable_avdtp_delay_reports_summary"/>
 
         <ListPreference
             android:key="bluetooth_select_avrcp_version"
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 1f863c2..65fb7ab 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -31,6 +31,11 @@
             android:title="@string/zen_mode_behavior_settings_title"
             android:fragment="com.android.settings.notification.ZenModeBehaviorSettings" />
 
+    <!-- DND duration settings -->
+    <Preference
+        android:key="zen_mode_duration_settings"
+        android:title="@string/zen_mode_duration_settings_title" />
+
     <!-- Automatic rules -->
     <Preference
         android:key="zen_mode_automation_settings"
diff --git a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
index f20a110..032e2d2 100644
--- a/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
+++ b/src/com/android/settings/datetime/timezone/BaseTimeZonePicker.java
@@ -25,7 +25,9 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 import android.widget.SearchView;
+import android.widget.TextView;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
@@ -130,6 +132,19 @@
                 mSearchView.setActivated(true);
                 mSearchView.setQuery("", true /* submit */);
             }
+
+            // Set zero margin and padding to align with the text horizontally in the preference
+            final TextView searchViewView = (TextView) mSearchView.findViewById(
+                    com.android.internal.R.id.search_src_text);
+            searchViewView.setPadding(0, searchViewView.getPaddingTop(), 0,
+                    searchViewView.getPaddingBottom());
+            final View editFrame = mSearchView.findViewById(
+                    com.android.internal.R.id.search_edit_frame);
+            final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) editFrame
+                    .getLayoutParams();
+            params.setMarginStart(0);
+            params.setMarginEnd(0);
+            editFrame.setLayoutParams(params);
         }
     }
 
diff --git a/src/com/android/settings/development/BluetoothDelayReportsPreferenceController.java b/src/com/android/settings/development/BluetoothDelayReportsPreferenceController.java
index 0858555..6c7a7dd 100644
--- a/src/com/android/settings/development/BluetoothDelayReportsPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothDelayReportsPreferenceController.java
@@ -28,11 +28,11 @@
 public class BluetoothDelayReportsPreferenceController extends DeveloperOptionsPreferenceController
         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
 
-    private static final String BLUETOOTH_ENABLE_AVDTP_DELAY_REPORT_KEY =
-            "bluetooth_enable_avdtp_delay_reports";
+    private static final String BLUETOOTH_DISABLE_AVDTP_DELAY_REPORT_KEY =
+            "bluetooth_disable_avdtp_delay_reports";
     @VisibleForTesting
-    static final String BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY =
-            "persist.bluetooth.enabledelayreports";
+    static final String BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY =
+            "persist.bluetooth.disabledelayreports";
 
     public BluetoothDelayReportsPreferenceController(Context context) {
         super(context);
@@ -40,22 +40,22 @@
 
     @Override
     public String getPreferenceKey() {
-        return BLUETOOTH_ENABLE_AVDTP_DELAY_REPORT_KEY;
+        return BLUETOOTH_DISABLE_AVDTP_DELAY_REPORT_KEY;
     }
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        final boolean isEnabled = (Boolean) newValue;
-        SystemProperties.set(BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY,
-                isEnabled ? "true" : "false");
+        final boolean isDisabled = (Boolean) newValue;
+        SystemProperties.set(BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY,
+                isDisabled ? "true" : "false");
         return true;
     }
 
     @Override
     public void updateState(Preference preference) {
-        final boolean isEnabled = SystemProperties.getBoolean(
-                BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
-        ((SwitchPreference) mPreference).setChecked(isEnabled);
+        final boolean isDisabled = SystemProperties.getBoolean(
+                BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
+        ((SwitchPreference) mPreference).setChecked(isDisabled);
     }
 
     @Override
@@ -63,7 +63,7 @@
         super.onDeveloperOptionsSwitchDisabled();
         // the default setting for this preference is the disabled state
         ((SwitchPreference) mPreference).setChecked(false);
-        SystemProperties.set(BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY, "false");
+        SystemProperties.set(BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY, "false");
     }
 
 }
diff --git a/src/com/android/settings/notification/AbstractZenModePreferenceController.java b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
index 9180791..c60299e 100644
--- a/src/com/android/settings/notification/AbstractZenModePreferenceController.java
+++ b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
@@ -112,10 +112,17 @@
                 mBackend.mZenMode);
     }
 
+    protected int getZenDuration() {
+        return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_DURATION,
+                0);
+    }
+
     class SettingObserver extends ContentObserver {
         private final Uri ZEN_MODE_URI = Settings.Global.getUriFor(Settings.Global.ZEN_MODE);
         private final Uri ZEN_MODE_CONFIG_ETAG_URI = Settings.Global.getUriFor(
                 Settings.Global.ZEN_MODE_CONFIG_ETAG);
+        private final Uri ZEN_MODE_DURATION_URI = Settings.Global.getUriFor(
+                Settings.Global.ZEN_DURATION);
 
         private final Preference mPreference;
 
@@ -127,6 +134,7 @@
         public void register(ContentResolver cr) {
             cr.registerContentObserver(ZEN_MODE_URI, false, this, UserHandle.USER_ALL);
             cr.registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this, UserHandle.USER_ALL);
+            cr.registerContentObserver(ZEN_MODE_DURATION_URI, false, this, UserHandle.USER_ALL);
         }
 
         public void unregister(ContentResolver cr) {
@@ -136,11 +144,8 @@
         @Override
         public void onChange(boolean selfChange, Uri uri) {
             super.onChange(selfChange, uri);
-            if (ZEN_MODE_URI.equals(uri)) {
-                updateState(mPreference);
-            }
-
-            if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) {
+            if (ZEN_MODE_URI.equals(uri) || ZEN_MODE_CONFIG_ETAG_URI.equals(uri)
+                    || ZEN_MODE_DURATION_URI.equals(uri)) {
                 updateState(mPreference);
             }
         }
diff --git a/src/com/android/settings/notification/SettingsZenDurationDialog.java b/src/com/android/settings/notification/SettingsZenDurationDialog.java
new file mode 100644
index 0000000..23bf1a9
--- /dev/null
+++ b/src/com/android/settings/notification/SettingsZenDurationDialog.java
@@ -0,0 +1,37 @@
+/*
+ * 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 android.app.Dialog;
+import android.os.Bundle;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class SettingsZenDurationDialog extends InstrumentedDialogFragment {
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        return new com.android.settingslib.notification.ZenDurationDialog(
+                getContext()).createDialog();
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_DURATION_DIALOG;
+    }
+}
diff --git a/src/com/android/settings/notification/ZenModeAutomationPreferenceController.java b/src/com/android/settings/notification/ZenModeAutomationPreferenceController.java
index aa46d4e..792a272 100644
--- a/src/com/android/settings/notification/ZenModeAutomationPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeAutomationPreferenceController.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.android.settings.notification;
 
 import android.content.Context;
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index 8817417..3c6a026 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -16,9 +16,11 @@
 
 package com.android.settings.notification;
 
+import android.app.ActivityManager;
 import android.app.AutomaticZenRule;
 import android.app.NotificationManager;
 import android.content.Context;
+import android.net.Uri;
 import android.provider.Settings;
 import android.service.notification.ZenModeConfig;
 import android.support.annotation.VisibleForTesting;
@@ -79,7 +81,15 @@
 
     protected void setZenMode(int zenMode) {
         NotificationManager.from(mContext).setZenMode(zenMode, null, TAG);
-        mZenMode = zenMode;
+        mZenMode = getZenMode();
+    }
+
+    protected void setZenModeForDuration(int minutes) {
+        Uri conditionId = ZenModeConfig.toTimeCondition(mContext, minutes,
+                ActivityManager.getCurrentUser(), true).id;
+        mNotificationManager.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS,
+                conditionId, TAG);
+        mZenMode = getZenMode();
     }
 
     protected int getZenMode() {
diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
index 0e1f066..cf6218c 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.android.settings.notification;
 
 import android.content.Context;
diff --git a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
index d9c9691..12008a1 100644
--- a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
@@ -61,8 +61,7 @@
         if (null == mZenButtonOn) {
             mZenButtonOn = (Button) ((LayoutPreference) preference)
                     .findViewById(R.id.zen_mode_settings_turn_on_button);
-            mZenButtonOn.setOnClickListener(v ->
-                    new SettingsEnableZenModeDialog().show(mFragment, TAG));
+            updateZenButtonOnClickListener();
         }
 
         if (null == mZenButtonOff) {
@@ -89,7 +88,34 @@
             case Settings.Global.ZEN_MODE_OFF:
             default:
                 mZenButtonOff.setVisibility(View.GONE);
+                updateZenButtonOnClickListener();
                 mZenButtonOn.setVisibility(View.VISIBLE);
         }
     }
+
+    private void updateZenButtonOnClickListener() {
+        int zenDuration = getZenDuration();
+        switch (zenDuration) {
+            case Settings.Global.ZEN_DURATION_PROMPT:
+                mZenButtonOn.setOnClickListener(v -> {
+                    mMetricsFeatureProvider.action(mContext,
+                            MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false);
+                    new SettingsEnableZenModeDialog().show(mFragment, TAG);
+                });
+                break;
+            case Settings.Global.ZEN_DURATION_FOREVER:
+                mZenButtonOn.setOnClickListener(v -> {
+                    mMetricsFeatureProvider.action(mContext,
+                            MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false);
+                    mBackend.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+                });
+                break;
+            default:
+                mZenButtonOn.setOnClickListener(v -> {
+                    mMetricsFeatureProvider.action(mContext,
+                            MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false);
+                    mBackend.setZenModeForDuration(zenDuration);
+                });
+        }
+    }
 }
\ No newline at end of file
diff --git a/src/com/android/settings/notification/ZenModeDurationPreferenceController.java b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java
new file mode 100644
index 0000000..0cd0eb3
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java
@@ -0,0 +1,86 @@
+/*
+ * 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 android.app.FragmentManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
+        implements PreferenceControllerMixin, Preference.OnPreferenceClickListener {
+
+    private static final String TAG = "ZenModeDurationDialog";
+    protected static final String KEY = "zen_mode_duration_settings";
+    private FragmentManager mFragment;
+
+    public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
+            fragment) {
+        super(context, KEY, lifecycle);
+        mFragment = fragment;
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        screen.findPreference(KEY).setOnPreferenceClickListener(this);
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+
+        String summary = "";
+        int zenDuration = getZenDuration();
+        if (zenDuration < 0) {
+            summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt);
+        } else if (zenDuration == 0) {
+            summary = mContext.getString(R.string.zen_mode_duration_summary_forever);
+        } else {
+            if (zenDuration >= 60) {
+                int hours = zenDuration / 60;
+                summary = mContext.getResources().getQuantityString(
+                        R.plurals.zen_mode_duration_summary_time_hours, hours, hours);
+            } else {
+                summary = mContext.getResources().getString(
+                        R.string.zen_mode_duration_summary_time_minutes, zenDuration);
+            }
+        }
+
+        preference.setSummary(summary);
+    }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        new SettingsZenDurationDialog().show(mFragment, TAG);
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 557d624..b143b42 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -65,6 +65,8 @@
         List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
         controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
+        controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
+                fragmentManager));
         controllers.add(new ZenModeAutomationPreferenceController(context));
         controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
         controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
@@ -250,6 +252,7 @@
                 @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     List<String> keys = super.getNonIndexableKeys(context);
+                    keys.add(ZenModeDurationPreferenceController.KEY);
                     keys.add(ZenModeButtonPreferenceController.KEY);
                     return keys;
                 }
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothDelayReportsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothDelayReportsPreferenceControllerTest.java
index d529fc1..bdaad0a 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothDelayReportsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothDelayReportsPreferenceControllerTest.java
@@ -16,7 +16,9 @@
 
 package com.android.settings.development;
 
-import static com.android.settings.development.BluetoothDelayReportsPreferenceController.BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY;
+import static com.android.settings.development.BluetoothDelayReportsPreferenceController
+        .BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY;
+
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -57,11 +59,11 @@
     }
 
     @Test
-    public void onPreferenceChanged_settingEnabled_turnOnDelayReports() {
+    public void onPreferenceChanged_settingDisabled_turnOnDelayReports() {
         mController.onPreferenceChange(mPreference, true /* new value */);
 
         final boolean mode = SystemProperties.getBoolean(
-                BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
+                BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
 
         assertThat(mode).isTrue();
     }
@@ -71,14 +73,14 @@
         mController.onPreferenceChange(mPreference, false /* new value */);
 
         final boolean mode = SystemProperties.getBoolean(
-                BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
+                BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
 
         assertThat(mode).isFalse();
     }
 
     @Test
-    public void updateState_settingEnabled_preferenceShouldBeChecked() {
-        SystemProperties.set(BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY,
+    public void updateState_settingDisabled_preferenceShouldBeChecked() {
+        SystemProperties.set(BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY,
                 Boolean.toString(true));
         mController.updateState(mPreference);
 
@@ -87,7 +89,7 @@
 
     @Test
     public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
-        SystemProperties.set(BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY,
+        SystemProperties.set(BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY,
                 Boolean.toString(false));
         mController.updateState(mPreference);
 
@@ -99,10 +101,10 @@
         mController.onDeveloperOptionsDisabled();
 
         final boolean mode = SystemProperties.getBoolean(
-                BLUETOOTH_ENABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
+                BLUETOOTH_DISABLE_AVDTP_DELAY_REPORTS_PROPERTY, false /* default */);
 
         assertThat(mode).isFalse();
         assertThat(mPreference.isEnabled()).isFalse();
         assertThat(mPreference.isChecked()).isFalse();
     }
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java
new file mode 100644
index 0000000..9a94e6c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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 org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.FragmentManager;
+import android.app.NotificationManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModeDurationPreferenceControllerTest {
+    private ZenModeDurationPreferenceController mController;
+
+    @Mock
+    private ZenModeBackend mBackend;
+    @Mock
+    private NotificationManager mNotificationManager;
+    @Mock
+    private Preference mockPref;
+    @Mock
+    private NotificationManager.Policy mPolicy;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+    private ContentResolver mContentResolver;
+    private Context mContext;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        ShadowApplication shadowApplication = ShadowApplication.getInstance();
+        shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+        mContext = shadowApplication.getApplicationContext();
+        mContentResolver = RuntimeEnvironment.application.getContentResolver();
+        mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class),
+                mock(FragmentManager.class));
+        when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+        ReflectionHelpers.setField(mController, "mBackend", mBackend);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mockPref);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void updateState_DurationForever() {
+        Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION,
+                Settings.Global.ZEN_DURATION_FOREVER);
+        final Preference mockPref = mock(Preference.class);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setSummary(mContext.getString(R.string.zen_mode_duration_summary_forever));
+    }
+
+    @Test
+    public void updateState_DurationPrompt() {
+        Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION,
+                Settings.Global.ZEN_DURATION_PROMPT);
+        final Preference mockPref = mock(Preference.class);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setSummary(mContext.getString(
+                R.string.zen_mode_duration_summary_always_prompt));
+    }
+
+    @Test
+    public void updateState_DurationCustom() {
+        int zenDuration = 45;
+        Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION,
+                zenDuration);
+        final Preference mockPref = mock(Preference.class);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setSummary(mContext.getResources().getString(
+                R.string.zen_mode_duration_summary_time_minutes, zenDuration));
+    }
+}
\ No newline at end of file