Merge "Simplify password length constraints checking"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 52a18b9..92819d8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -727,6 +727,10 @@
<action android:name="android.settings.ZEN_MODE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
@@ -753,23 +757,6 @@
</activity>
<activity
- android:name="Settings$ZenModeBehaviorSettingsActivity"
- android:label="@string/zen_mode_behavior_settings_title"
- android:icon="@drawable/ic_settings_notifications"
- android:exported="true"
- android:taskAffinity="com.android.settings"
- android:parentActivityName="Settings">
- <intent-filter android:priority="1">
- <action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.notification.ZenModeBehaviorSettings" />
- <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
- android:value="true" />
- </activity>
-
- <activity
android:name="Settings$ZenModeAutomationSettingsActivity"
android:label="@string/zen_mode_automation_settings_title"
android:icon="@drawable/ic_settings_notifications"
@@ -1127,7 +1114,9 @@
</intent-filter>
</activity>
- <activity android:name=".slice.SliceDeepLinkSpringBoard"
+ <activity
+ android:name=".slices.SliceDeepLinkSpringBoard"
+ android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
diff --git a/res/drawable/ic_local_phone_24_lib.xml b/res/drawable/ic_local_phone_24_lib.xml
new file mode 100644
index 0000000..4574802
--- /dev/null
+++ b/res/drawable/ic_local_phone_24_lib.xml
@@ -0,0 +1,28 @@
+<!--
+ Copyright 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+
+ <path
+ android:fillColor="#000000"
+ android:pathData="M16.01,14.48l-2.62,2.62c-2.75-1.49-5.01-3.75-6.5-6.5l2.62-2.62c0.24-0.24,0.34-0.58,0.27-0.9L9.13,3.82 c-0.09-0.47-0.5-0.8-0.98-0.8L4,3.01c-0.56,0-1.03,0.47-1,1.03c0.17,2.91,1.04,5.63,2.43,8.01c1.57,2.69,3.81,4.93,6.5,6.5 c2.38,1.39,5.1,2.26,8.01,2.43c0.56,0.03,1.03-0.44,1.03-1l0-4.15c0-0.48-0.34-0.89-0.8-0.98l-3.26-0.65 C16.58,14.14,16.24,14.24,16.01,14.48z" />
+ <path
+ android:pathData="M0,0h24v24H0V0z" />
+</vector>
diff --git a/res/layout/gesture_preference.xml b/res/layout/gesture_preference.xml
deleted file mode 100644
index ccbc42a..0000000
--- a/res/layout/gesture_preference.xml
+++ /dev/null
@@ -1,104 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeightSmall"
- android:gravity="center_vertical"
- android:background="?android:attr/activatedBackgroundIndicator"
- android:clipToPadding="false"
- android:orientation="vertical">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:paddingTop="24dp"
- android:paddingBottom="16dp"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:background="@android:color/white">
-
- <TextView
- android:id="@android:id/title"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceListItem"
- android:ellipsize="marquee"/>
-
- <Switch
- android:id="@android:id/switch_widget"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="end|center_vertical"/>
-
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/gesture_animation_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/gestures_setting_background_color"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:orientation="horizontal">
-
- <com.android.settings.widget.AspectRatioFrameLayout
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:padding="@dimen/gesture_animation_padding">
-
- <TextureView
- android:id="@+id/gesture_video"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center"/>
-
- <ImageView
- android:id="@+id/gesture_image"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="fitXY"
- android:background="@color/gestures_setting_background_color"/>
-
- <ImageView
- android:id="@+id/gesture_play_button"
- android:layout_width="@dimen/gestures_play_button_size"
- android:layout_height="@dimen/gestures_play_button_size"
- android:src="@drawable/ic_gesture_play_button"
- android:gravity="center"
- android:layout_gravity="center"/>
-
- </com.android.settings.widget.AspectRatioFrameLayout>
-
- <TextView
- android:id="@android:id/summary"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:paddingTop="@dimen/gestures_settings_padding_top_bottom"
- android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:textAppearance="?android:attr/textAppearanceListItemSecondary"
- android:textColor="?android:attr/textColorSecondary"
- android:maxLines="10"
- android:ellipsize="end"/>
-
- </LinearLayout>
-
-</LinearLayout>
diff --git a/res/layout/preference_volume_slider.xml b/res/layout/preference_volume_slider.xml
index 89ecec0..5e5d595 100644
--- a/res/layout/preference_volume_slider.xml
+++ b/res/layout/preference_volume_slider.xml
@@ -45,8 +45,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:layout_marginTop="8dip"
- android:layout_marginBottom="8dip">
+ android:layout_marginTop="16dip"
+ android:layout_marginBottom="16dip">
<LinearLayout
android:layout_width="match_parent"
diff --git a/res/layout/video_preference.xml b/res/layout/video_preference.xml
index 55bc7a5..b71a1b5 100644
--- a/res/layout/video_preference.xml
+++ b/res/layout/video_preference.xml
@@ -28,8 +28,7 @@
<com.android.settings.widget.AspectRatioFrameLayout
android:id="@+id/video_container"
android:layout_width="wrap_content"
- android:layout_height="240dp"
- android:padding="@dimen/gesture_animation_padding">
+ android:layout_height="240dp">
<TextureView
android:id="@+id/video_texture_view"
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index 749a4e9..9569ae4 100755
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -35,7 +35,4 @@
<!-- Display, Screen zoom -->
<dimen name="screen_zoom_preview_height">160dp</dimen>
- <!-- Gestures -->
- <dimen name="gesture_animation_padding">35dp</dimen>
-
</resources>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 61a3c75..29de06b 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -78,6 +78,9 @@
<!-- Whether alarm_volume should be shown or not. -->
<bool name="config_show_alarm_volume">true</bool>
+ <!-- Whether call_volume should be shown or not. -->
+ <bool name="config_show_call_volume">true</bool>
+
<!-- Whether notification_volume should be shown or not. -->
<bool name="config_show_notification_volume">true</bool>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f95de27..e0b8c48 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -288,7 +288,6 @@
<!-- Padding for Gestures settings screen -->
<dimen name="gestures_settings_padding_top_bottom">20dp</dimen>
<dimen name="gestures_play_button_size">36dp</dimen>
- <dimen name="gesture_animation_padding">0dp</dimen>
<dimen name="password_requirement_textsize">14sp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cc2c7f7..252a601 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -388,6 +388,8 @@
<!-- Description for bluetooth device name summary [CHAR LIMIT=none] -->
<string name="bluetooth_device_name_summary">Visible as \u201C<xliff:g id="device_name">^1</xliff:g>\u201D to other devices</string>
+ <!-- Footer description for discoverable mode in bluetooth off state [CHAR LIMIT=none] -->
+ <string name="bluetooth_off_footer">Turn on Bluetooth to connect to other devices.</string>
<!-- Title for paired device group [CHAR LIMIT=none] -->
<string name="bluetooth_paired_device_title">Your devices</string>
@@ -413,14 +415,16 @@
<string name="connected_device_connected_title">Currently connected</string>
<!-- Title for connected device group [CHAR LIMIT=none]-->
<string name="connected_device_saved_title">Saved devices</string>
- <!-- Title for preference to add a device [CHAR LIMIT=none]-->
- <string name="connected_device_add_device_title">Pair new device</string>
+ <!-- Title for preference to add a device [CHAR LIMIT=none] [BACKUP_MESSAGE_ID=7803521577708810621] -->
+ <string name="connected_device_add_device_title">Add device</string>
<!-- Summary for preference to add a device [CHAR LIMIT=none]-->
<string name="connected_device_add_device_summary">Bluetooth will turn on to pair</string>
<!-- Title for other connection preferences [CHAR LIMIT=none]-->
<string name="connected_device_connections_title">Connection preferences</string>
<!-- Title for Bluetooth preference to open paired but no connection list [CHAR LIMIT=none]-->
<string name="connected_device_previously_connected_title">Previously connected devices</string>
+ <!-- Preference screen title for Bluetooth preference to open paired but no connection list [CHAR LIMIT=none]-->
+ <string name="connected_device_previously_connected_screen_title">Previously connected</string>
<!-- Date & time settings screen title -->
<string name="date_and_time">Date & time</string>
@@ -845,9 +849,10 @@
<!-- Security Settings screen Encryption and crendential summary -->
<string name="encryption_and_credential_settings_summary" product="tablet">Device encrypted</string>
<string name="decryption_settings_summary" product="tablet">Device not encrypted</string>
- <!-- Security Settings screen setting option title for the item to take you to the lock screen preference screen [CHAR LIMIT=60] -->
- <string name="lockscreen_settings_title">Lock screen preferences</string>
-
+ <!-- Screen title for a list of settings controlling what to show on user's lockscreen [CHAR LIMIT=60] -->
+ <string name="lockscreen_settings_title">Lock screen display</string>
+ <!-- Category title for the settings that control what lockscreen shows. [CHAR LIMIT=30] -->
+ <string name="lockscreen_settings_what_to_show_category">What to show</string>
<!-- Main Settings screen setting option summary text for the item tot ake you to the security and location screen -->
<string name="security_settings_summary">Set My Location, screen unlock, SIM card lock, credential storage lock</string>
<!-- Main Settings screen setting option summary text for the item to take you to the CDMA security and location screen -->
@@ -2641,6 +2646,7 @@
<string name="ambient_display_screen_summary_always_on">Always on / Increased battery usage</string>
<!-- [CHAR LIMIT=30] Summary of the preference that opens the Ambient display settings screen, when Ambient display is set to show when new notifications come in. -->
<string name="ambient_display_screen_summary_notifications">New notifications</string>
+
<!-- [CHAR LIMIT=30] Category title for the settings that control when Ambient display shows. -->
<string name="ambient_display_category_triggers">When to show</string>
<!-- [CHAR LIMIT=30] Ambient display screen, title for setting to change whether the ambient display feature is triggered for new incoming notifications. -->
@@ -3388,6 +3394,8 @@
<!-- Master Clear -->
<!-- Button title to factory data reset the entire device -->
<string name="master_clear_title">Erase all data (factory reset)</string>
+ <!-- Button title to factory data reset the entire device. The "(factory reset)" part is optional for translation. [CHAR LIMIT=30 BACKUP_MESSAGE_ID=3531267871084279512]-->
+ <string name="master_clear_short_title">Erase all data (factory reset)</string>
<!-- SD card & phone storage settings screen, message on screen after user selects Factory data reset [CHAR LIMIT=NONE] -->
<string name="master_clear_desc" product="tablet">"This will erase all data from your tablet\u2019s <b>internal storage</b>, including:\n\n<li>Your Google account</li>\n<li>System and app data and settings</li>\n<li>Downloaded apps</li>"</string>
<!-- SD card & phone storage settings screen, message on screen after user selects Factory data reset [CHAR LIMIT=NONE] -->
@@ -4629,6 +4637,9 @@
<item quantity="other">Very long delay (<xliff:g id="click_delay_label" example="200">%1$d</xliff:g> ms)</item>
</plurals>
+ <!-- Summary for vibration settings preference when notification vibration and haptic feedback intensity are set. [CHAR LIMIT=32] -->
+ <string name="accessibility_vibration_summary">Ring <xliff:g id="summary_ring" example="Medium">%1$s</xliff:g>, touch <xliff:g id="summary_touch" example="High">%2$s</xliff:g></string>
+
<!-- Summary for vibration settings preference when ring & notification are set to off-->
<string name="accessibility_vibration_summary_off">Ring & notification set to off</string>
@@ -4920,9 +4931,7 @@
<string name="device_cellular_network">Mobile network scanning</string>
<!-- Label for list of apps using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] -->
- <string name="power_usage_list_summary">App usage since full charge (<xliff:g id="relative_time">^1</xliff:g>)</string>
- <!-- Label for device components using battery in power use UI. Note: ^1 should be used in all translations[CHAR_LIMIT=120] -->
- <string name="power_usage_list_summary_device">Device usage since full charge (<xliff:g id="relative_time">^1</xliff:g>)</string>
+ <string name="power_usage_list_summary">Battery usage since full charge</string>
<!-- Temp string used to debug new battery estimates [DO NOT TRANSLATE] -->
<string name="power_usage_enhanced_debug" translatable="false"><xliff:g id="time">%1$s</xliff:g> left (New ML est)</string>
<!-- Temp string used to debug old battery estimates [DO NOT TRANSLATE] -->
@@ -5027,11 +5036,11 @@
<!-- Summary for the battery high usage tip, which presents battery may run out soon [CHAR LIMIT=NONE] -->
<string name="battery_tip_high_usage_summary">Battery may run out soon</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
+ <string name="battery_tip_dialog_message" product="default">Your phone has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps you used since full charge:</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
+ <string name="battery_tip_dialog_message" product="tablet">Your tablet has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps you used since full charge:</string>
<!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
- <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps since last full charge(<xliff:g id="time_period_ago" example="1 hr ago">%2$s</xliff:g>):</string>
+ <string name="battery_tip_dialog_message" product="device">Your device has been used more than usual. Your battery may run out sooner than expected.\n\nTop <xliff:g id="number">%1$d</xliff:g> apps you used since full charge:</string>
<!-- Title for restricted app preference, showing how many app need to be restricted [CHAR LIMIT=NONE] -->
<plurals name="battery_tip_restrict_title">
<item quantity="one">Restrict %1$d app</item>
@@ -7225,24 +7234,23 @@
<!-- Do not disturb: Subtitle for the Visual signals option to toggle on/off visual signals/alerts when the screen is on/when screen is off. [CHAR LIMIT=30] -->
<string name="zen_mode_visual_signals_settings_subtitle">Allow visual signals</string>
- <!-- Do not disturb: restrict notifications title [CHAR LIMIT=60] -->
- <string name="zen_mode_restrict_notifications_screen_title">Restrict notifications</string>
+ <!-- Do not disturb: zen settings screens category title [CHAR LIMIT=100] -->
+ <string name="zen_mode_settings_category">When Do Not Disturb is turned on</string>
+
<!-- Do not disturb: restrict notifications title [CHAR LIMIT=60] -->
<string name="zen_mode_restrict_notifications_title">Notifications</string>
- <!-- Do not disturb: restrict notifications category title [CHAR LIMIT=100] -->
- <string name="zen_mode_restrict_notifications_category">When Do Not Disturb is turned on</string>
<!-- Do not disturb: Mute notifications option [CHAR LIMIT=60] -->
- <string name="zen_mode_restrict_notifications_mute">Mute notifications</string>
+ <string name="zen_mode_restrict_notifications_mute">Show notifications silently</string>
<!-- Do not disturb:Mute notifications summary [CHAR LIMIT=NONE] -->
- <string name="zen_mode_restrict_notifications_mute_summary">Show notifications but mute sounds & vibrations</string>
+ <string name="zen_mode_restrict_notifications_mute_summary">Notifications will be muted</string>
<!-- Do not disturb:Mute notifications footer [CHAR LIMIT=NONE] -->
- <string name="zen_mode_restrict_notifications_mute_footer">When new notifications arrive your phone won\u2019t make a sound or vibration</string>
+ <string name="zen_mode_restrict_notifications_mute_footer">When notifications arrive, your phone won\u2019t make a sound or vibrate.</string>
<!-- Do not disturb: Hide notifications option [CHAR LIMIT=60] -->
- <string name="zen_mode_restrict_notifications_hide">Hide & mute notifications</string>
+ <string name="zen_mode_restrict_notifications_hide">Hide notifications</string>
<!-- Do not disturb: Hide notifications summary [CHAR LIMIT=NONE] -->
- <string name="zen_mode_restrict_notifications_hide_summary">Notifications will not appear at all</string>
+ <string name="zen_mode_restrict_notifications_hide_summary">You won\u2019t see new or existing notifications</string>
<!-- Do not disturb: Hide notifications footer [CHAR LIMIT=NONE] -->
- <string name="zen_mode_restrict_notifications_hide_footer">You won\u2019t see new or existing notifications when Do Not Disturb is on. However, notifications needed for basic phone activity and status will still appear.</string>
+ <string name="zen_mode_restrict_notifications_hide_footer">Your phone won\u2019t show new or existing notifications, and won\u2019t make a sound or vibrate. Notifications won\u2019t appear when you swipe down from the top of your screen.\n\nKeep in mind, critical notifications for phone activity and status will still appear.</string>
<!-- Do not disturb: Custom settings option [CHAR LIMIT=60] -->
<string name="zen_mode_restrict_notifications_custom">Custom</string>
<!-- Do not disturb: restrict notifications page, menu option [CHAR LIMIT=60] -->
@@ -7362,6 +7370,35 @@
<item quantity="other"><xliff:g id="on_count" example="3">%d</xliff:g> rules can turn on automatically</item>
</plurals>
+ <!-- Do not disturb settings, category header [CHAR LIMIT=100]-->
+ <string name="zen_category_behavior">Behavior</string>
+ <!-- Do not disturb settings, category header [CHAR LIMIT=100]-->
+ <string name="zen_category_exceptions">Exceptions</string>
+ <!-- Do not disturb settings, category header [CHAR LIMIT=100]-->
+ <string name="zen_category_schedule">Schedule</string>
+
+ <!-- Do not disturb settings, sound and vibrations title [CHAR LIMIT=100]-->
+ <string name="zen_sound_title">Sound & vibration</string>
+ <!-- Do not disturb settings, sound and vibrations screen footer [CHAR LIMIT=NONE]-->
+ <string name="zen_sound_footer">When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above.</string>
+ <!-- Do not disturb settings, sound and vibrations screen category [CHAR LIMIT=100]-->
+ <string name="zen_sound_category_title">Mute all except</string>
+ <!-- Do not disturb settings, sound and vibrations summary [CHAR LIMIT=100]-->
+ <string name="zen_sound_all_muted">Muted</string>
+ <!-- Do not disturb settings, sound and vibrations summary [CHAR LIMIT=100]-->
+ <string name="zen_sound_none_muted">Not muted</string>
+ <!-- Do not disturb settings, sound and vibrations summary [CHAR LIMIT=100]-->
+ <string name="zen_sound_one_allowed">Muted, but allow <xliff:g id="sound_type" example="alarms">%1$s</xliff:g></string>
+ <!-- Do not disturb settings, sound and vibrations summary [CHAR LIMIT=100]-->
+ <string name="zen_sound_two_allowed">Muted, but allow <xliff:g id="sound_type" example="alarms">%1$s</xliff:g> and <xliff:g id="sound_type" example="media">%2$s</xliff:g></string>
+ <!-- Do not disturb settings, sound and vibrations summary [CHAR LIMIT=100]-->
+ <string name="zen_sound_three_allowed">Muted, but allow <xliff:g id="sound_type" example="alarms">%1$s</xliff:g>, <xliff:g id="sound_type" example="alarms">%2$s</xliff:g>, and <xliff:g id="sound_type" example="media">%3$s</xliff:g></string>
+
+ <!-- Do not disturb settings, messages, events and reminders title [CHAR LIMIT=100]-->
+ <string name="zen_msg_event_reminder_title">Messages, events & reminders</string>
+ <!-- Do not disturb settings, messages, events and reminders footer [CHAR LIMIT=NONE]-->
+ <string name="zen_msg_event_reminder_footer">When Do Not Disturb is on, messages, reminders, and events will muted, except for the items you allow above. You can adjust messages settings to allow your friends, family, or other contacts to reach you.</string>
+
<!-- Do not disturb onboarding dialog, accept new settings [CHAR LIMIT=30]-->
<string name="zen_onboarding_ok">Update</string>
<!-- Do not disturb onboarding dialog, do not accept new settings [CHAR LIMIT=30]-->
@@ -7893,14 +7930,26 @@
<!-- [CHAR LIMIT=20] Zen mode settings: Calls option -->
<string name="zen_mode_calls">Calls</string>
+ <!-- [CHAR LIMIT=20] Zen mode settings: Calls screen footer -->
+ <string name="zen_mode_calls_footer">When Do Not Disturb is on, incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
+
+ <!-- [CHAR LIMIT=50] Zen mode settings: Starred contacts preference title -->
+ <string name="zen_mode_starred_contacts_title">Starred contacts</string>
+
+ <!-- Zen mode settings: Starred contacts summary [CHAR LIMIT=NONE] -->
+ <plurals name="zen_mode_starred_contacts_summary_additional_contacts">
+ <item quantity="one">and 1 other</item>
+ <item quantity="other">and <xliff:g id="num_people" example="3">%d</xliff:g> others</item>
+ </plurals>
+
<!-- [CHAR LIMIT=20] Zen mode settings: Messages option -->
<string name="zen_mode_messages">Messages</string>
<!-- [CHAR LIMIT=50] Zen mode settings: All messages summary -->
- <string name="zen_mode_all_messages">All messages</string>
+ <string name="zen_mode_all_messages">Messages</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Selected messages summary -->
- <string name="zen_mode_selected_messages">Selected messages</string>
+ <string name="zen_mode_selected_messages">Some messages</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: From anyone -->
<string name="zen_mode_from_anyone">From anyone</string>
@@ -7911,6 +7960,15 @@
<!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: From starred contacts only -->
<string name="zen_mode_from_starred">From starred contacts only</string>
+ <!-- Do not disturb settings, calls summary [CHAR LIMIT=100]-->
+ <string name="zen_calls_summary_starred_repeat">From starred contacts and repeat callers</string>
+
+ <!-- Do not disturb settings, calls summary [CHAR LIMIT=100]-->
+ <string name="zen_calls_summary_contacts_repeat">From contacts and repeat callers</string>
+
+ <!-- Do not disturb settings, calls summary [CHAR LIMIT=100]-->
+ <string name="zen_calls_summary_repeat_only">From repeat callers only</string>
+
<!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: None -->
<string name="zen_mode_from_none">None</string>
@@ -7930,14 +7988,23 @@
<string name="zen_mode_events">Events</string>
<!-- [CHAR LIMIT=50] Zen mode settings: All callers summary -->
- <string name="zen_mode_all_callers">All callers</string>
+ <string name="zen_mode_all_callers">anyone</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Selected callers summary -->
- <string name="zen_mode_selected_callers">Selected callers</string>
+ <string name="zen_mode_contacts_callers">contacts</string>
+
+ <!-- [CHAR LIMIT=50] Zen mode settings: Selected callers summary -->
+ <string name="zen_mode_starred_callers">starred contacts</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Repeat callers option -->
<string name="zen_mode_repeat_callers">Repeat callers</string>
+ <!-- [CHAR LIMIT=50] Zen mode settings: calls summary -->
+ <string name="zen_mode_calls_summary_one">From <xliff:g id="caller type" example="contacts">%1$s</xliff:g> only</string>
+
+ <!-- [CHAR LIMIT=50] Zen mode settings: calls summary -->
+ <string name="zen_mode_calls_summary_two">From <xliff:g id="caller type" example="starred contacts">%1$s</xliff:g> and <xliff:g id="callert tpye" example="repeat callers">%2$s</xliff:g></string>
+
<!-- [CHAR LIMIT=200] Zen mode settings: Repeat callers option summary -->
<string name="zen_mode_repeat_callers_summary">If the same person calls a second time within a <xliff:g id="minutes">%d</xliff:g> minute period</string>
@@ -8651,7 +8718,7 @@
<string name="ignore_optimizations_off">Optimize</string>
<!-- Ignore battery optimizations on description [CHAR LIMIT=NONE] -->
- <string name="ignore_optimizations_on_desc">May drain your battery more quickly</string>
+ <string name="ignore_optimizations_on_desc">May drain your battery more quickly. App will no longer be restricted from using background battery.</string>
<!-- Ignore battery optimizations off description [CHAR LIMIT=NONE] -->
<string name="ignore_optimizations_off_desc">Recommended for better battery life</string>
@@ -9806,9 +9873,15 @@
<!-- Help URI, USB Audio [DO NOT TRANSLATE] -->
<string name="help_url_audio_accessory_not_supported" translatable="false"></string>
+ <!-- Help URI, restricted apps page [DO NOT TRANSLATE] -->
+ <string name="help_uri_restricted_apps" translatable="false"></string>
+
<!-- Help URI, battery saver page [DO NOT TRANSLATE] -->
<string name="help_url_battery_saver_settings" translatable="false"></string>
+ <!-- Help URI, smart battery page [DO NOT TRANSLATE] -->
+ <string name="help_uri_smart_battery_settings" translatable="false"></string>
+
<!-- Title label for new device suggestion, which is displayed in Settings homepage [CHAR LIMIT=100] -->
<string name="new_device_suggestion_title">What\'s new and exciting?</string>
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index e3319e9..53e575f 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -20,7 +20,8 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="apps_and_notification_screen"
android:title="@string/app_and_notification_dashboard_title"
- settings:initialExpandedChildrenCount="7">
+ settings:initialExpandedChildrenCount="8">
+ <!-- the initial count should include the dynamic tiles -->
<PreferenceCategory
android:key="recent_apps_category"
diff --git a/res/xml/bluetooth_screen.xml b/res/xml/bluetooth_screen.xml
index ec25520..407feb6 100644
--- a/res/xml/bluetooth_screen.xml
+++ b/res/xml/bluetooth_screen.xml
@@ -15,5 +15,19 @@
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="bluetooth_switchbar_screen"
- android:title="@string/bluetooth_settings_title" />
\ No newline at end of file
+ android:title="@string/bluetooth_settings_title">
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="bluetooth_screen_add_bt_devices"
+ android:title="@string/connected_device_add_device_title"
+ android:icon="@drawable/ic_menu_add"
+ android:summary="@string/connected_device_add_device_summary"
+ android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
+ settings:allowDividerAbove="true"
+ settings:userRestriction="no_config_bluetooth"
+ settings:useAdminDisabledSummary="true"
+ settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 1e9d97e..6d25c58 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -32,7 +32,7 @@
<com.android.settingslib.RestrictedPreference
android:key="add_bt_devices"
- android:title="@string/connected_device_add_device_title"
+ android:title="@string/bluetooth_pairing_pref_title"
android:icon="@drawable/ic_menu_add"
android:summary="@string/connected_device_add_device_summary"
android:fragment="com.android.settings.bluetooth.BluetoothPairingDetail"
diff --git a/res/xml/previously_connected_devices.xml b/res/xml/previously_connected_devices.xml
index b0578a7..8c5509b 100644
--- a/res/xml/previously_connected_devices.xml
+++ b/res/xml/previously_connected_devices.xml
@@ -18,7 +18,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="connected_devices_screen_previously"
- android:title="@string/connected_device_previously_connected_title">
+ android:title="@string/connected_device_previously_connected_screen_title">
<PreferenceCategory
android:key="saved_device_list"
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index 15fbcc8..61f529f 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -38,12 +38,29 @@
android:order="-175"
settings:controller="com.android.settings.sound.MediaOutputPreferenceController"/>
+ <!-- Call volume -->
+ <com.android.settings.notification.VolumeSeekBarPreference
+ android:key="call_volume"
+ android:icon="@drawable/ic_local_phone_24_lib"
+ android:title="@string/call_volume_option_title"
+ android:order="-170"
+ settings:allowDividerAbove="true"
+ settings:controller="com.android.settings.notification.CallVolumePreferenceController"/>
+
+ <!-- Hands free profile output switcher -->
+ <ListPreference
+ android:key="take_call_on_output"
+ android:title="@string/take_call_on_title"
+ android:dialogTitle="@string/take_call_on_title"
+ android:order="-165"
+ settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>
+
<!-- Ring volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="ring_volume"
android:icon="@*android:drawable/ic_audio_ring_notif"
android:title="@string/ring_volume_option_title"
- android:order="-170"
+ android:order="-160"
settings:controller="com.android.settings.notification.RingVolumePreferenceController"
settings:allowDividerAbove="true"/>
@@ -51,15 +68,7 @@
<SwitchPreference
android:key="vibrate_when_ringing"
android:title="@string/vibrate_when_ringing_title"
- android:order="-160"/>
-
- <!-- Hands free profile output switcher -->
- <ListPreference
- android:key="take_call_on_output"
- android:title="@string/take_call_on_title"
- android:dialogTitle="@string/take_call_on_title"
- android:order="-155"
- settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>
+ android:order="-155"/>
<!-- Alarm volume -->
<com.android.settings.notification.VolumeSeekBarPreference
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
deleted file mode 100644
index 8426d91..0000000
--- a/res/xml/zen_mode_behavior_settings.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:key="zen_mode_behavior_settings_page"
- android:title="@string/zen_mode_behavior_settings_title" >
-
- <!-- Alarms -->
- <SwitchPreference
- android:key="zen_mode_alarms"
- android:title="@string/zen_mode_alarms"/>
-
- <!-- Media -->
- <SwitchPreference
- android:key="zen_mode_media"
- android:title="@string/zen_mode_media"/>
-
- <!-- System -->
- <SwitchPreference
- android:key="zen_mode_system"
- android:title="@string/zen_mode_system"/>
-
- <!-- Reminders -->
- <SwitchPreference
- android:key="zen_mode_reminders"
- android:title="@string/zen_mode_reminders"/>
-
- <!-- Events -->
- <SwitchPreference
- android:key="zen_mode_events"
- android:title="@string/zen_mode_events"/>
-
- <!-- Messages -->
- <ListPreference
- android:key="zen_mode_messages"
- android:title="@string/zen_mode_messages"
- android:entries="@array/zen_mode_contacts_entries"
- android:entryValues="@array/zen_mode_contacts_values"/>
-
- <!-- Calls -->
- <ListPreference
- android:key="zen_mode_calls"
- android:title="@string/zen_mode_calls"
- android:entries="@array/zen_mode_contacts_entries"
- android:entryValues="@array/zen_mode_contacts_values"/>
-
- <!-- Repeat callers -->
- <SwitchPreference
- android:key="zen_mode_repeat_callers"
- android:title="@string/zen_mode_repeat_callers" />
-
- <com.android.settingslib.widget.FooterPreference />
-
-</PreferenceScreen>
diff --git a/res/xml/zen_mode_calls_settings.xml b/res/xml/zen_mode_calls_settings.xml
new file mode 100644
index 0000000..dd6fcc5
--- /dev/null
+++ b/res/xml/zen_mode_calls_settings.xml
@@ -0,0 +1,45 @@
+<?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="zen_mode_calls_settings_page"
+ android:title="@string/zen_mode_calls" >
+
+ <PreferenceCategory
+ android:title="@string/zen_mode_settings_category"
+ android:key="zen_mode_settings_category_calls">
+ <!-- Calls -->
+ <ListPreference
+ android:key="zen_mode_calls"
+ android:title="@string/zen_mode_calls"
+ android:entries="@array/zen_mode_contacts_entries"
+ android:entryValues="@array/zen_mode_contacts_values"/>
+
+ <Preference
+ android:key="zen_mode_starred_contacts_callers"
+ android:title="@string/zen_mode_starred_contacts_title"/>
+
+ <!-- Repeat callers -->
+ <SwitchPreference
+ android:key="zen_mode_repeat_callers"
+ android:title="@string/zen_mode_repeat_callers" />
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference/>
+
+</PreferenceScreen>
diff --git a/res/xml/zen_mode_msg_event_reminder_settings.xml b/res/xml/zen_mode_msg_event_reminder_settings.xml
new file mode 100644
index 0000000..d12fc62
--- /dev/null
+++ b/res/xml/zen_mode_msg_event_reminder_settings.xml
@@ -0,0 +1,50 @@
+<?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="zen_mode_msg_event_reminder_settings_page"
+ android:title="@string/zen_msg_event_reminder_title" >
+
+ <PreferenceCategory
+ android:title="@string/zen_mode_settings_category"
+ android:key="zen_mode_settings_category_msg_event_reminder">
+ <!-- Messages -->
+ <ListPreference
+ android:key="zen_mode_messages"
+ android:title="@string/zen_mode_messages"
+ android:entries="@array/zen_mode_contacts_entries"
+ android:entryValues="@array/zen_mode_contacts_values"/>
+
+ <Preference
+ android:key="zen_mode_starred_contacts_messages"
+ android:title="@string/zen_mode_starred_contacts_title"/>
+
+ <!-- Reminders -->
+ <SwitchPreference
+ android:key="zen_mode_reminders"
+ android:title="@string/zen_mode_reminders"/>
+
+ <!-- Events -->
+ <SwitchPreference
+ android:key="zen_mode_events"
+ android:title="@string/zen_mode_events"/>
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference />
+
+</PreferenceScreen>
diff --git a/res/xml/zen_mode_restrict_notifications_settings.xml b/res/xml/zen_mode_restrict_notifications_settings.xml
index d5243f6..e024ab9 100644
--- a/res/xml/zen_mode_restrict_notifications_settings.xml
+++ b/res/xml/zen_mode_restrict_notifications_settings.xml
@@ -18,11 +18,11 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="zen_mode_restrict_settings_page"
- android:title="@string/zen_mode_restrict_notifications_screen_title">
+ android:title="@string/zen_mode_restrict_notifications_title">
<PreferenceCategory
android:key="restrict_category"
- android:title="@string/zen_mode_restrict_notifications_category">
+ android:title="@string/zen_mode_settings_category">
<com.android.settings.notification.ZenCustomRadioButtonPreference
android:key="zen_mute_notifications"
android:title="@string/zen_mode_restrict_notifications_mute"
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 0f93968..240c4c5 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -22,39 +22,50 @@
android:title="@string/zen_mode_settings_title"
settings:keywords="@string/keywords_zen_mode_settings">
- <!-- sound vibration -->
- <com.android.settings.widget.DisabledCheckBoxPreference
- android:key="zen_effect_sound"
- android:title="@string/zen_mode_block_effect_sound"
- android:enabled="false"/>
-
- <!-- What to block (effects) -->
- <Preference
- android:key="zen_mode_block_effects_settings"
- android:title="@string/zen_mode_restrict_notifications_title"
- android:fragment="com.android.settings.notification.ZenModeRestrictNotificationsSettings" />
-
- <!-- Behavior settings (exceptions) -->
- <Preference
- android:key="zen_mode_behavior_settings"
- 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"
- android:title="@string/zen_mode_automation_settings_title"
- android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
-
- <!-- placeholder -->
<PreferenceCategory
- android:key="dashboard_tile_placeholder"
- android:order="5" />
+ android:key="zen_mode_settings_category_behavior"
+ android:title="@string/zen_category_behavior">
+ <!-- sound vibration -->
+ <Preference
+ android:key="zen_sound_vibration_settings"
+ android:title="@string/zen_sound_title"
+ android:fragment="com.android.settings.notification.ZenModeSoundVibrationSettings"/>
+
+ <!-- What to block (effects) -->
+ <Preference
+ android:key="zen_mode_block_effects_settings"
+ android:title="@string/zen_mode_restrict_notifications_title"
+ android:fragment="com.android.settings.notification.ZenModeRestrictNotificationsSettings" />
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:key="zen_mode_settings_category_exceptions"
+ android:title="@string/zen_category_exceptions">
+ <Preference
+ android:key="zen_mode_calls_settings"
+ android:title="@string/zen_mode_calls"
+ android:fragment="com.android.settings.notification.ZenModeCallsSettings" />
+ <Preference
+ android:key="zen_mode_msg_event_reminder_settings"
+ android:title="@string/zen_msg_event_reminder_title"
+ android:fragment="com.android.settings.notification.ZenModeMsgEventReminderSettings" />
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:key="zen_mode_settings_category_schedule"
+ android:title="@string/zen_category_schedule">
+ <!-- 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"
+ android:title="@string/zen_mode_automation_settings_title"
+ android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
+ </PreferenceCategory>
<!-- Turn on DND button -->
<!-- Layout preference doesn't obey allowDividerAbove, so put it in a PreferenceCategory -->
diff --git a/res/xml/zen_mode_sound_vibration_settings.xml b/res/xml/zen_mode_sound_vibration_settings.xml
new file mode 100644
index 0000000..b3b8139
--- /dev/null
+++ b/res/xml/zen_mode_sound_vibration_settings.xml
@@ -0,0 +1,44 @@
+<?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="zen_mode_sound_vibration_settings_page"
+ android:title="@string/zen_sound_title" >
+
+ <PreferenceCategory
+ android:title="@string/zen_mode_settings_category"
+ android:key="zen_mode_settings_category_sound_vibration">
+ <!-- Alarms -->
+ <SwitchPreference
+ android:key="zen_mode_alarms"
+ android:title="@string/zen_mode_alarms"/>
+
+ <!-- Media -->
+ <SwitchPreference
+ android:key="zen_mode_media"
+ android:title="@string/zen_mode_media"/>
+
+ <!-- System -->
+ <SwitchPreference
+ android:key="zen_mode_system"
+ android:title="@string/zen_mode_system"/>
+ </PreferenceCategory>
+
+ <com.android.settingslib.widget.FooterPreference/>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/CredentialStorage.java
index ffbd2ce..c037c9f 100644
--- a/src/com/android/settings/CredentialStorage.java
+++ b/src/com/android/settings/CredentialStorage.java
@@ -127,9 +127,9 @@
protected void onResume() {
super.onResume();
- Intent intent = getIntent();
- String action = intent.getAction();
- UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
+ final Intent intent = getIntent();
+ final String action = intent.getAction();
+ final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
if (!userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
if (ACTION_RESET.equals(action)) {
new ResetDialog();
@@ -208,18 +208,18 @@
* Returns true if the currently set key guard matches our minimum quality requirements.
*/
private boolean checkKeyGuardQuality() {
- int credentialOwner =
+ final int credentialOwner =
UserManager.get(this).getCredentialOwnerProfile(UserHandle.myUserId());
- int quality = new LockPatternUtils(this).getActivePasswordQuality(credentialOwner);
+ final int quality = new LockPatternUtils(this).getActivePasswordQuality(credentialOwner);
return (quality >= MIN_PASSWORD_QUALITY);
}
private boolean isHardwareBackedKey(byte[] keyData) {
try {
- ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(keyData));
- PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
- String algOid = pki.getAlgorithmId().getAlgorithm().getId();
- String algName = new AlgorithmId(new ObjectIdentifier(algOid)).getName();
+ final ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(keyData));
+ final PrivateKeyInfo pki = PrivateKeyInfo.getInstance(bIn.readObject());
+ final String algOid = pki.getAlgorithmId().getAlgorithm().getId();
+ final String algName = new AlgorithmId(new ObjectIdentifier(algOid)).getName();
return KeyChain.isBoundKeyAlgorithm(algName);
} catch (IOException e) {
@@ -236,14 +236,13 @@
return;
}
- Bundle bundle = mInstallBundle;
+ final Bundle bundle = mInstallBundle;
mInstallBundle = null;
final int uid = bundle.getInt(Credentials.EXTRA_INSTALL_AS_UID, KeyStore.UID_SELF);
if (uid != KeyStore.UID_SELF && !UserHandle.isSameUser(uid, Process.myUid())) {
- int dstUserId = UserHandle.getUserId(uid);
- int myUserId = UserHandle.myUserId();
+ final int dstUserId = UserHandle.getUserId(uid);
// Restrict install target to the wifi uid.
if (uid != Process.WIFI_UID) {
@@ -252,7 +251,7 @@
return;
}
- Intent installIntent = new Intent(ACTION_INSTALL)
+ final Intent installIntent = new Intent(ACTION_INSTALL)
.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
.putExtras(bundle);
startActivityAsUser(installIntent, new UserHandle(dstUserId));
@@ -260,8 +259,8 @@
}
if (bundle.containsKey(Credentials.EXTRA_USER_PRIVATE_KEY_NAME)) {
- String key = bundle.getString(Credentials.EXTRA_USER_PRIVATE_KEY_NAME);
- byte[] value = bundle.getByteArray(Credentials.EXTRA_USER_PRIVATE_KEY_DATA);
+ final String key = bundle.getString(Credentials.EXTRA_USER_PRIVATE_KEY_NAME);
+ final byte[] value = bundle.getByteArray(Credentials.EXTRA_USER_PRIVATE_KEY_DATA);
int flags = KeyStore.FLAG_ENCRYPTED;
if (uid == Process.WIFI_UID && isHardwareBackedKey(value)) {
@@ -287,11 +286,11 @@
}
}
- int flags = KeyStore.FLAG_NONE;
+ final int flags = KeyStore.FLAG_NONE;
if (bundle.containsKey(Credentials.EXTRA_USER_CERTIFICATE_NAME)) {
- String certName = bundle.getString(Credentials.EXTRA_USER_CERTIFICATE_NAME);
- byte[] certData = bundle.getByteArray(Credentials.EXTRA_USER_CERTIFICATE_DATA);
+ final String certName = bundle.getString(Credentials.EXTRA_USER_CERTIFICATE_NAME);
+ final byte[] certData = bundle.getByteArray(Credentials.EXTRA_USER_CERTIFICATE_DATA);
if (!mKeyStore.put(certName, certData, uid, flags)) {
Log.e(TAG, "Failed to install " + certName + " as uid " + uid);
@@ -300,8 +299,8 @@
}
if (bundle.containsKey(Credentials.EXTRA_CA_CERTIFICATES_NAME)) {
- String caListName = bundle.getString(Credentials.EXTRA_CA_CERTIFICATES_NAME);
- byte[] caListData = bundle.getByteArray(Credentials.EXTRA_CA_CERTIFICATES_DATA);
+ final String caListName = bundle.getString(Credentials.EXTRA_CA_CERTIFICATES_NAME);
+ final byte[] caListData = bundle.getByteArray(Credentials.EXTRA_CA_CERTIFICATES_DATA);
if (!mKeyStore.put(caListName, caListData, uid, flags)) {
Log.e(TAG, "Failed to install " + caListName + " as uid " + uid);
@@ -310,7 +309,7 @@
}
// Send the broadcast.
- Intent broadcast = new Intent(KeyChain.ACTION_KEYCHAIN_CHANGED);
+ final Intent broadcast = new Intent(KeyChain.ACTION_KEYCHAIN_CHANGED);
sendBroadcast(broadcast);
setResult(RESULT_OK);
@@ -324,7 +323,7 @@
private boolean mResetConfirmed;
private ResetDialog() {
- AlertDialog dialog = new AlertDialog.Builder(CredentialStorage.this)
+ final AlertDialog dialog = new AlertDialog.Builder(CredentialStorage.this)
.setTitle(android.R.string.dialog_alert_title)
.setMessage(R.string.credentials_reset_hint)
.setPositiveButton(android.R.string.ok, this)
@@ -364,7 +363,7 @@
new LockPatternUtils(CredentialStorage.this).resetKeyStore(UserHandle.myUserId());
try {
- KeyChainConnection keyChainConnection = KeyChain.bind(CredentialStorage.this);
+ final KeyChainConnection keyChainConnection = KeyChain.bind(CredentialStorage.this);
try {
return keyChainConnection.getService().reset();
} catch (RemoteException e) {
@@ -393,7 +392,7 @@
}
private void clearLegacyVpnIfEstablished() {
- boolean isDone = VpnUtils.disconnectLegacyVpn(getApplicationContext());
+ final boolean isDone = VpnUtils.disconnectLegacyVpn(getApplicationContext());
if (isDone) {
Toast.makeText(CredentialStorage.this, R.string.vpn_disconnected,
Toast.LENGTH_SHORT).show();
@@ -407,7 +406,7 @@
private class MarkKeyAsUserSelectable extends AsyncTask<Void, Void, Boolean> {
final String mAlias;
- public MarkKeyAsUserSelectable(String alias) {
+ MarkKeyAsUserSelectable(String alias) {
mAlias = alias;
}
@@ -440,7 +439,7 @@
final int launchedFromUserId;
try {
- int launchedFromUid = android.app.ActivityManager.getService()
+ final int launchedFromUid = android.app.ActivityManager.getService()
.getLaunchedFromUid(getActivityToken());
if (launchedFromUid == -1) {
Log.e(TAG, ACTION_INSTALL + " must be started with startActivityForResult");
@@ -456,8 +455,8 @@
return false;
}
- UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
- UserInfo parentInfo = userManager.getProfileParent(launchedFromUserId);
+ final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
+ final UserInfo parentInfo = userManager.getProfileParent(launchedFromUserId);
if (parentInfo == null || parentInfo.id != UserHandle.myUserId()) {
// Caller is not running in a profile of this user
return false;
@@ -469,7 +468,7 @@
* Confirm existing key guard, returning password via onActivityResult.
*/
private boolean confirmKeyGuard(int requestCode) {
- Resources res = getResources();
+ final Resources res = getResources();
boolean launched = new ChooseLockSettingsHelper(this)
.launchConfirmationActivity(requestCode,
res.getText(R.string.credentials_title), true);
@@ -485,7 +484,7 @@
*/
if (requestCode == CONFIRM_KEY_GUARD_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
- String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
+ final String password = data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
if (!TextUtils.isEmpty(password)) {
// success
mKeyStore.unlock(password);
@@ -520,9 +519,10 @@
private final TextView mError;
private UnlockDialog() {
- View view = View.inflate(CredentialStorage.this, R.layout.credentials_dialog, null);
+ final View view = View.inflate(
+ CredentialStorage.this, R.layout.credentials_dialog, null);
- CharSequence text;
+ final CharSequence text;
if (mRetriesRemaining == -1) {
text = getResources().getText(R.string.credentials_unlock_hint);
} else if (mRetriesRemaining > 3) {
@@ -539,7 +539,7 @@
mOldPassword.addTextChangedListener(this);
mError = (TextView) view.findViewById(R.id.error);
- AlertDialog dialog = new AlertDialog.Builder(CredentialStorage.this)
+ final AlertDialog dialog = new AlertDialog.Builder(CredentialStorage.this)
.setView(view)
.setTitle(R.string.credentials_unlock)
.setPositiveButton(android.R.string.ok, this)
@@ -575,7 +575,7 @@
mUnlockConfirmed = false;
mError.setVisibility(View.VISIBLE);
mKeyStore.unlock(mOldPassword.getText().toString());
- int error = mKeyStore.getLastError();
+ final int error = mKeyStore.getLastError();
if (error == KeyStore.NO_ERROR) {
mRetriesRemaining = -1;
Toast.makeText(CredentialStorage.this,
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index a1f836b..ba3c4d9 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -102,7 +102,7 @@
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getActivity().setTitle(R.string.master_clear_title);
+ getActivity().setTitle(R.string.master_clear_short_title);
}
/**
@@ -114,7 +114,7 @@
private boolean runKeyguardConfirmation(int request) {
Resources res = getActivity().getResources();
return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
- request, res.getText(R.string.master_clear_title));
+ request, res.getText(R.string.master_clear_short_title));
}
@VisibleForTesting
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index de1732c..cd92a95 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -33,6 +33,7 @@
import android.os.Vibrator;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
+import androidx.annotation.VisibleForTesting;
import androidx.preference.SwitchPreference;
import androidx.core.content.ContextCompat;
import androidx.preference.ListPreference;
@@ -749,12 +750,34 @@
pref.setSummary(entries[index]);
}
- private void updateVibrationSummary(Preference pref) {
- Vibrator vibrator = getContext().getSystemService(Vibrator.class);
- final int intensity = Settings.System.getInt(getContext().getContentResolver(),
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ void updateVibrationSummary(Preference pref) {
+ final Context context = getContext();
+ final Vibrator vibrator = context.getSystemService(Vibrator.class);
+
+ final int ringIntensity = Settings.System.getInt(context.getContentResolver(),
Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
vibrator.getDefaultNotificationVibrationIntensity());
- mVibrationPreferenceScreen.setSummary(getVibrationSummary(getContext(), intensity));
+ CharSequence ringIntensityString =
+ VibrationIntensityPreferenceController.getIntensityString(context, ringIntensity);
+
+ final int touchIntensity = Settings.System.getInt(context.getContentResolver(),
+ Settings.System.HAPTIC_FEEDBACK_INTENSITY,
+ vibrator.getDefaultHapticFeedbackIntensity());
+ CharSequence touchIntensityString =
+ VibrationIntensityPreferenceController.getIntensityString(context, touchIntensity);
+
+ if (mVibrationPreferenceScreen == null) {
+ mVibrationPreferenceScreen = findPreference(VIBRATION_PREFERENCE_SCREEN);
+ }
+
+ if (ringIntensity == touchIntensity) {
+ mVibrationPreferenceScreen.setSummary(ringIntensityString);
+ } else {
+ mVibrationPreferenceScreen.setSummary(
+ getString(R.string.accessibility_vibration_summary,
+ ringIntensityString, touchIntensityString));
+ }
}
private String getVibrationSummary(Context context, @VibrationIntensity int intensity) {
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index f2e357f..1d66812 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -23,7 +23,6 @@
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
-import androidx.preference.Preference;
import android.text.TextUtils;
import android.view.accessibility.AccessibilityManager;
@@ -32,11 +31,15 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.search.actionbar.SearchMenuController;
+import com.android.settings.support.actionbar.HelpResourceProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
+import androidx.preference.Preference;
+
@SearchIndexable
public final class MagnificationPreferenceFragment extends DashboardFragment {
@@ -90,6 +93,10 @@
// If invoked from SUW, redirect to fragment instrumented for Vision Settings metrics
preference.setFragment(
ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
+ Bundle args = preference.getExtras();
+ // Copy from AccessibilitySettingsForSetupWizardActivity, hide search and help menu
+ args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0);
+ args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
}
return super.onPreferenceTreeClick(preference);
}
diff --git a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
index 34516b4..e99e32f 100644
--- a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
@@ -77,16 +77,19 @@
public CharSequence getSummary() {
final int intensity = Settings.System.getInt(mContext.getContentResolver(),
mSettingKey, getDefaultIntensity());
+ return getIntensityString(mContext, intensity);
+ }
+ public static CharSequence getIntensityString(Context context, int intensity) {
switch (intensity) {
case Vibrator.VIBRATION_INTENSITY_OFF:
- return mContext.getText(R.string.accessibility_vibration_intensity_off);
+ return context.getText(R.string.accessibility_vibration_intensity_off);
case Vibrator.VIBRATION_INTENSITY_LOW:
- return mContext.getText(R.string.accessibility_vibration_intensity_low);
+ return context.getText(R.string.accessibility_vibration_intensity_low);
case Vibrator.VIBRATION_INTENSITY_MEDIUM:
- return mContext.getText(R.string.accessibility_vibration_intensity_medium);
+ return context.getText(R.string.accessibility_vibration_intensity_medium);
case Vibrator.VIBRATION_INTENSITY_HIGH:
- return mContext.getText(R.string.accessibility_vibration_intensity_high);
+ return context.getText(R.string.accessibility_vibration_intensity_high);
default:
return "";
}
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index eb74b2e..68ed42a 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -549,7 +549,7 @@
startAppInfoFragment(AppStorageSettings.class, R.string.storage_settings);
break;
case LIST_TYPE_HIGH_POWER:
- HighPowerDetail.show(this, mCurrentPkgName, INSTALLED_APP_DETAILS);
+ HighPowerDetail.show(this, mCurrentUid, mCurrentPkgName, INSTALLED_APP_DETAILS);
break;
case LIST_TYPE_OVERLAY:
startAppInfoFragment(DrawOverlayDetails.class, R.string.overlay_settings);
diff --git a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java
index ee9d15f..9a287f1 100644
--- a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java
@@ -16,11 +16,12 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothProfile;
-import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.media.AudioManager;
-import androidx.annotation.VisibleForTesting;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -29,7 +30,8 @@
/**
* Controller to maintain available media Bluetooth devices
*/
-public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
+public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
+ implements Preference.OnPreferenceClickListener {
private static final String TAG = "AvailableMediaBluetoothDeviceUpdater";
private static final boolean DBG = false;
@@ -57,18 +59,20 @@
}
@Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
+ int bluetoothProfile) {
if (DBG) {
- Log.d(TAG,"onConnectionStateChanged() device : " +
- cachedDevice.getName() + ", state : " + state);
+ Log.d(TAG, "onProfileConnectionStateChanged() device: " +
+ cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
+ + bluetoothProfile);
}
- if (state == BluetoothAdapter.STATE_CONNECTED) {
+ if (state == BluetoothProfile.STATE_CONNECTED) {
if (isFilterMatched(cachedDevice)) {
addPreference(cachedDevice);
} else {
removePreference(cachedDevice);
}
- } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+ } else if (state == BluetoothProfile.STATE_DISCONNECTED) {
removePreference(cachedDevice);
}
}
@@ -114,5 +118,12 @@
}
return isFilterMatched;
}
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
+ .getBluetoothDevice();
+ return device.setActive();
+ }
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
index 2ebaafc..f7fadf2 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -59,24 +59,12 @@
protected DashboardFragment mFragment;
private final boolean mShowDeviceWithoutNames;
- private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null;
@VisibleForTesting
final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
launchDeviceDetails(pref);
};
- private class PreferenceClickListener implements
- Preference.OnPreferenceClickListener {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- final CachedBluetoothDevice device =
- ((BluetoothDevicePreference) preference).getBluetoothDevice();
- Log.i(TAG, "OnPreferenceClickListener: device=" + device);
- return device.setActive();
- }
- }
-
public BluetoothDeviceUpdater(Context context, DashboardFragment fragment,
DevicePreferenceCallback devicePreferenceCallback) {
this(fragment, devicePreferenceCallback, Utils.getLocalBtManager(context));
@@ -91,7 +79,6 @@
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
mPreferenceMap = new HashMap<>();
mLocalManager = localManager;
- mDevicePreferenceClickListener = new PreferenceClickListener();
}
/**
@@ -162,6 +149,11 @@
}
@Override
+ public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
+ int bluetoothProfile) {
+ }
+
+ @Override
public void onServiceConnected() {
// When bluetooth service connected update the UI
forceUpdate();
@@ -207,7 +199,10 @@
new BluetoothDevicePreference(mPrefContext, cachedDevice,
mShowDeviceWithoutNames);
btPreference.setOnGearClickListener(mDeviceProfilesListener);
- btPreference.setOnPreferenceClickListener(mDevicePreferenceClickListener);
+ if (this instanceof Preference.OnPreferenceClickListener) {
+ btPreference.setOnPreferenceClickListener(
+ (Preference.OnPreferenceClickListener)this);
+ }
mPreferenceMap.put(device, btPreference);
mDevicePreferenceCallback.onDeviceAdded(btPreference);
}
diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
index 7559b30..0ac3e6d 100644
--- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java
@@ -15,7 +15,6 @@
*/
package com.android.settings.bluetooth;
-import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
@@ -64,19 +63,20 @@
}
@Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
+ int bluetoothProfile) {
if (DBG) {
- Log.d(TAG,"onConnectionStateChanged() device : " +
- cachedDevice.getName() + ", state : " + state);
+ Log.d(TAG, "onProfileConnectionStateChanged() device: " +
+ cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
+ + bluetoothProfile);
}
-
- if (state == BluetoothAdapter.STATE_CONNECTED) {
+ if (state == BluetoothProfile.STATE_CONNECTED) {
if (isFilterMatched(cachedDevice)) {
addPreference(cachedDevice);
} else {
removePreference(cachedDevice);
}
- } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+ } else if (state == BluetoothProfile.STATE_DISCONNECTED) {
removePreference(cachedDevice);
}
}
diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
index 9836d29..b5cdaa6 100644
--- a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java
@@ -15,20 +15,24 @@
*/
package com.android.settings.bluetooth;
-import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
import android.content.Context;
import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import android.util.Log;
/**
* Maintain and update saved bluetooth devices(bonded but not connected)
*/
-public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
+public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
+ implements Preference.OnPreferenceClickListener {
+ private static final String TAG = "SavedBluetoothDeviceUpdater";
public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
DevicePreferenceCallback devicePreferenceCallback) {
@@ -43,10 +47,11 @@
}
@Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
- if (state == BluetoothAdapter.STATE_CONNECTED) {
+ public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
+ int bluetoothProfile) {
+ if (state == BluetoothProfile.STATE_CONNECTED) {
removePreference(cachedDevice);
- } else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
+ } else if (state == BluetoothProfile.STATE_DISCONNECTED) {
addPreference(cachedDevice);
}
}
@@ -56,4 +61,12 @@
final BluetoothDevice device = cachedDevice.getDevice();
return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected();
}
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
+ .getBluetoothDevice();
+ device.connect(true);
+ return true;
+ }
}
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 8304392..88ba329 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -30,7 +30,6 @@
import java.util.List;
import androidx.preference.Preference;
-import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
/**
@@ -49,22 +48,27 @@
* {@link #isSupported()}.
*/
@Retention(RetentionPolicy.SOURCE)
- @IntDef({AVAILABLE, UNSUPPORTED_ON_DEVICE, DISABLED_FOR_USER, DISABLED_DEPENDENT_SETTING,
- CONDITIONALLY_UNAVAILABLE})
+ @IntDef({AVAILABLE, AVAILABLE_UNSEARCHABLE, UNSUPPORTED_ON_DEVICE, DISABLED_FOR_USER,
+ DISABLED_DEPENDENT_SETTING, CONDITIONALLY_UNAVAILABLE})
public @interface AvailabilityStatus {
}
/**
- * The setting is available.
+ * The setting is available, and searchable to all search clients.
*/
public static final int AVAILABLE = 0;
/**
+ * The setting is available, but is not searchable to any search client.
+ */
+ public static final int AVAILABLE_UNSEARCHABLE = 1;
+
+ /**
* A generic catch for settings which are currently unavailable, but may become available in
* the future. You should use {@link #DISABLED_FOR_USER} or {@link #DISABLED_DEPENDENT_SETTING}
* if they describe the condition more accurately.
*/
- public static final int CONDITIONALLY_UNAVAILABLE = 1;
+ public static final int CONDITIONALLY_UNAVAILABLE = 2;
/**
* The setting is not, and will not supported by this device.
@@ -72,7 +76,7 @@
* There is no guarantee that the setting page exists, and any links to the Setting should take
* you to the home page of Settings.
*/
- public static final int UNSUPPORTED_ON_DEVICE = 2;
+ public static final int UNSUPPORTED_ON_DEVICE = 3;
/**
@@ -81,7 +85,7 @@
* Links to the Setting should take you to the page of the Setting, even if it cannot be
* changed.
*/
- public static final int DISABLED_FOR_USER = 3;
+ public static final int DISABLED_FOR_USER = 4;
/**
* The setting has a dependency in the Settings App which is currently blocking access.
@@ -98,7 +102,7 @@
* Links to the Setting should take you to the page of the Setting, even if it cannot be
* changed.
*/
- public static final int DISABLED_DEPENDENT_SETTING = 4;
+ public static final int DISABLED_DEPENDENT_SETTING = 5;
protected final String mPreferenceKey;
@@ -183,6 +187,7 @@
public final boolean isAvailable() {
final int availabilityStatus = getAvailabilityStatus();
return (availabilityStatus == AVAILABLE
+ || availabilityStatus == AVAILABLE_UNSEARCHABLE
|| availabilityStatus == DISABLED_DEPENDENT_SETTING);
}
@@ -226,16 +231,15 @@
* Called by SearchIndexProvider#getNonIndexableKeys
*/
public void updateNonIndexableKeys(List<String> keys) {
- if (this instanceof AbstractPreferenceController) {
- if (!isAvailable()) {
- final String key = getPreferenceKey();
- if (TextUtils.isEmpty(key)) {
- Log.w(TAG,
- "Skipping updateNonIndexableKeys due to empty key " + this.toString());
- return;
- }
- keys.add(key);
+ final boolean shouldSuppressFromSearch = !isAvailable()
+ || getAvailabilityStatus() == AVAILABLE_UNSEARCHABLE;
+ if (shouldSuppressFromSearch) {
+ final String key = getPreferenceKey();
+ if (TextUtils.isEmpty(key)) {
+ Log.w(TAG, "Skipping updateNonIndexableKeys due to empty key " + toString());
+ return;
}
+ keys.add(key);
}
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index ced158e..aab3512 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -106,9 +106,10 @@
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
-import com.android.settings.notification.ZenModeBehaviorSettings;
+import com.android.settings.notification.ZenModeMsgEventReminderSettings;
import com.android.settings.notification.ZenModeBlockedEffectsSettings;
import com.android.settings.notification.ZenModeEventRuleSettings;
+import com.android.settings.notification.ZenModeRestrictNotificationsSettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.password.ChooseLockPassword;
@@ -220,7 +221,6 @@
ApnSettings.class.getName(),
ApnEditor.class.getName(),
WifiCallingSettings.class.getName(),
- ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
ZenModeBlockedEffectsSettings.class.getName(),
diff --git a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
index 7b7fb5b..cd478fc 100644
--- a/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
+++ b/src/com/android/settings/dashboard/DashboardFragmentRegistry.java
@@ -27,7 +27,9 @@
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
import com.android.settings.deviceinfo.StorageDashboardFragment;
+import com.android.settings.display.NightDisplaySettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.gestures.GestureSettings;
import com.android.settings.language.LanguageAndInputSettings;
import com.android.settings.network.NetworkDashboardFragment;
import com.android.settings.notification.ConfigureNotificationSettings;
@@ -95,6 +97,10 @@
CategoryKey.CATEGORY_SECURITY_LOCKSCREEN);
PARENT_TO_CATEGORY_KEY_MAP.put(ZenModeSettings.class.getName(),
CategoryKey.CATEGORY_DO_NOT_DISTURB);
+ PARENT_TO_CATEGORY_KEY_MAP.put(GestureSettings.class.getName(),
+ CategoryKey.CATEGORY_GESTURES);
+ PARENT_TO_CATEGORY_KEY_MAP.put(NightDisplaySettings.class.getName(),
+ CategoryKey.CATEGORY_NIGHT_DISPLAY);
CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());
diff --git a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
index e2633a8..83b0984 100644
--- a/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java
@@ -193,14 +193,7 @@
}
mBatteryStatsHelper = statsHelper;
- final long lastFullChargeTime = mBatteryUtils.calculateLastFullChargeTime(
- mBatteryStatsHelper, System.currentTimeMillis());
- final CharSequence timeSequence = StringUtil.formatRelativeTime(mContext,
- lastFullChargeTime,
- false);
- final int resId = showAllApps ? R.string.power_usage_list_summary_device
- : R.string.power_usage_list_summary;
- mAppListGroup.setTitle(TextUtils.expandTemplate(mContext.getText(resId), timeSequence));
+ mAppListGroup.setTitle(R.string.power_usage_list_summary);
final PowerProfile powerProfile = statsHelper.getPowerProfile();
final BatteryStats stats = statsHelper.getStats();
diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
index c051604..bd64dd3 100644
--- a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
+++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java
@@ -21,9 +21,15 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.PowerManager;
+
+import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
import com.android.settings.Utils;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
/**
* Use this broadcastReceiver to listen to the battery change, and it will invoke
@@ -43,7 +49,19 @@
* Battery saver(e.g. off->on)
*/
public interface OnBatteryChangedListener {
- void onBatteryChanged();
+ void onBatteryChanged(@BatteryUpdateType int type);
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({BatteryUpdateType.MANUAL,
+ BatteryUpdateType.BATTERY_LEVEL,
+ BatteryUpdateType.BATTERY_SAVER,
+ BatteryUpdateType.BATTERY_STATUS})
+ public @interface BatteryUpdateType {
+ int MANUAL = 0;
+ int BATTERY_LEVEL = 1;
+ int BATTERY_SAVER = 2;
+ int BATTERY_STATUS = 3;
}
@VisibleForTesting
@@ -85,14 +103,17 @@
final String batteryLevel = Utils.getBatteryPercentage(intent);
final String batteryStatus = Utils.getBatteryStatus(
mContext.getResources(), intent);
- if (forceUpdate || !batteryLevel.equals(mBatteryLevel) || !batteryStatus.equals(
- mBatteryStatus)) {
- mBatteryLevel = batteryLevel;
- mBatteryStatus = batteryStatus;
- mBatteryListener.onBatteryChanged();
+ if (forceUpdate) {
+ mBatteryListener.onBatteryChanged(BatteryUpdateType.MANUAL);
+ } else if(!batteryLevel.equals(mBatteryLevel)) {
+ mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
+ } else if (!batteryStatus.equals(mBatteryStatus)) {
+ mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_STATUS);
}
+ mBatteryLevel = batteryLevel;
+ mBatteryStatus = batteryStatus;
} else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(intent.getAction())) {
- mBatteryListener.onBatteryChanged();
+ mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
}
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index e25e44e..ed40b7c 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -521,7 +521,7 @@
return true;
}
- return isSystemUid(uid) || powerWhitelistBackend.isSysWhitelistedExceptIdle(packageNames)
+ return isSystemUid(uid) || powerWhitelistBackend.isWhitelisted(packageNames)
|| (isSystemApp(mPackageManager, packageNames) && !hasLauncherEntry(packageNames));
}
diff --git a/src/com/android/settings/fuelgauge/HighPowerDetail.java b/src/com/android/settings/fuelgauge/HighPowerDetail.java
index 9cafbcb..4f70700 100644
--- a/src/com/android/settings/fuelgauge/HighPowerDetail.java
+++ b/src/com/android/settings/fuelgauge/HighPowerDetail.java
@@ -17,6 +17,7 @@
package com.android.settings.fuelgauge;
import android.app.AlertDialog;
+import android.app.AppOpsManager;
import android.app.Dialog;
import android.app.Fragment;
import android.content.Context;
@@ -43,12 +44,18 @@
private static final String ARG_DEFAULT_ON = "default_on";
- private final PowerWhitelistBackend mBackend = PowerWhitelistBackend.getInstance();
-
- private String mPackageName;
+ @VisibleForTesting
+ PowerWhitelistBackend mBackend;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
+ @VisibleForTesting
+ String mPackageName;
+ @VisibleForTesting
+ int mPackageUid;
private CharSequence mLabel;
private boolean mDefaultOn;
- private boolean mIsEnabled;
+ @VisibleForTesting
+ boolean mIsEnabled;
private Checkable mOptionOn;
private Checkable mOptionOff;
@@ -60,8 +67,11 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mBatteryUtils = BatteryUtils.getInstance(getContext());
+ mBackend = PowerWhitelistBackend.getInstance();
mPackageName = getArguments().getString(AppInfoBase.ARG_PACKAGE_NAME);
+ mPackageUid = getArguments().getInt(AppInfoBase.ARG_PACKAGE_UID);
PackageManager pm = getContext().getPackageManager();
try {
mLabel = pm.getApplicationInfo(mPackageName, 0).loadLabel(pm);
@@ -129,6 +139,8 @@
if (newValue != oldValue) {
logSpecialPermissionChange(newValue, mPackageName, getContext());
if (newValue) {
+ mBatteryUtils.setForceAppStandby(mPackageUid, mPackageName,
+ AppOpsManager.MODE_ALLOWED);
mBackend.addApp(mPackageName);
} else {
mBackend.removeApp(mPackageName);
@@ -165,10 +177,11 @@
: R.string.high_power_off);
}
- public static void show(Fragment caller, String packageName, int requestCode) {
+ public static void show(Fragment caller, int uid, String packageName, int requestCode) {
HighPowerDetail fragment = new HighPowerDetail();
Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, packageName);
+ args.putInt(AppInfoBase.ARG_PACKAGE_UID, uid);
fragment.setArguments(args);
fragment.setTargetFragment(caller, requestCode);
fragment.show(caller.getFragmentManager(), HighPowerDetail.class.getSimpleName());
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index a318e16..74098ff 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -13,6 +13,8 @@
*/
package com.android.settings.fuelgauge;
+import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
+
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -33,6 +35,7 @@
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.utils.StringUtil;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -108,7 +111,7 @@
mMetricsFeatureProvider.action(getContext(),
MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE,
mShowAllApps);
- restartBatteryStatsLoader();
+ restartBatteryStatsLoader(BatteryUpdateType.MANUAL);
return true;
default:
return super.onOptionsItemSelected(item);
@@ -140,7 +143,7 @@
}
@Override
- protected void refreshUi() {
+ protected void refreshUi(@BatteryUpdateType int refreshType) {
final Context context = getContext();
if (context == null) {
return;
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index f924e46..aa02919 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.fuelgauge;
+import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.*;
+
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
@@ -26,18 +28,17 @@
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settingslib.utils.AsyncLoader;
/**
* Common base class for things that need to show the battery usage graph.
*/
-public abstract class PowerUsageBase extends DashboardFragment
- implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
+public abstract class PowerUsageBase extends DashboardFragment {
// +1 to allow ordering for PowerUsageSummary.
@VisibleForTesting
static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
private static final String TAG = "PowerUsageBase";
+ private static final String KEY_REFRESH_TYPE = "refresh_type";
protected BatteryStatsHelper mStatsHelper;
protected UserManager mUm;
@@ -57,8 +58,8 @@
setHasOptionsMenu(true);
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
- mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
- restartBatteryStatsLoader();
+ mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
+ restartBatteryStatsLoader(type);
});
}
@@ -81,11 +82,14 @@
mBatteryBroadcastReceiver.unRegister();
}
- protected void restartBatteryStatsLoader() {
- getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
+ protected void restartBatteryStatsLoader(int refreshType) {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(KEY_REFRESH_TYPE, refreshType);
+
+ getLoaderManager().restartLoader(0, bundle, new PowerLoaderCallback());
}
- protected abstract void refreshUi();
+ protected abstract void refreshUi(@BatteryUpdateType int refreshType);
protected void updatePreference(BatteryHistoryPreference historyPref) {
final long startTime = System.currentTimeMillis();
@@ -93,21 +97,30 @@
BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
}
- @Override
- public Loader<BatteryStatsHelper> onCreateLoader(int id,
- Bundle args) {
- return new BatteryStatsHelperLoader(getContext());
- }
+ /**
+ * {@link android.app.LoaderManager.LoaderCallbacks} for {@link PowerUsageBase} to load
+ * the {@link BatteryStatsHelper}
+ */
+ public class PowerLoaderCallback implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
+ private int mRefreshType;
- @Override
- public void onLoadFinished(Loader<BatteryStatsHelper> loader,
- BatteryStatsHelper statsHelper) {
- mStatsHelper = statsHelper;
- refreshUi();
- }
+ @Override
+ public Loader<BatteryStatsHelper> onCreateLoader(int id,
+ Bundle args) {
+ mRefreshType = args.getInt(KEY_REFRESH_TYPE);
+ return new BatteryStatsHelperLoader(getContext());
+ }
- @Override
- public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
+ @Override
+ public void onLoadFinished(Loader<BatteryStatsHelper> loader,
+ BatteryStatsHelper statsHelper) {
+ mStatsHelper = statsHelper;
+ refreshUi(mRefreshType);
+ }
+ @Override
+ public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
+
+ }
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index af69cee..82cd16a 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -16,6 +16,8 @@
package com.android.settings.fuelgauge;
+import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
+
import android.app.Activity;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
@@ -279,7 +281,7 @@
} else {
mStatsType = BatteryStats.STATS_SINCE_CHARGED;
}
- refreshUi();
+ refreshUi(BatteryUpdateType.MANUAL);
return true;
case MENU_ADVANCED_BATTERY:
new SubSettingLauncher(getContext())
@@ -293,14 +295,15 @@
}
}
- protected void refreshUi() {
+ protected void refreshUi(@BatteryUpdateType int refreshType) {
final Context context = getContext();
if (context == null) {
return;
}
- // Only skip BatteryTipLoader for the first time when device is rotated
- if (mNeedUpdateBatteryTip) {
+ // Skip BatteryTipLoader if device is rotated or only battery level change
+ if (mNeedUpdateBatteryTip
+ && refreshType != BatteryUpdateType.BATTERY_LEVEL) {
restartBatteryTipLoader();
} else {
mNeedUpdateBatteryTip = true;
@@ -399,8 +402,9 @@
}
@Override
- protected void restartBatteryStatsLoader() {
- restartBatteryStatsLoader(true /* clearHeader */);
+ protected void restartBatteryStatsLoader(@BatteryUpdateType int refreshType) {
+ super.restartBatteryStatsLoader(refreshType);
+ mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
}
@Override
@@ -409,13 +413,6 @@
mBatteryTipPreferenceController.saveInstanceState(outState);
}
- void restartBatteryStatsLoader(boolean clearHeader) {
- super.restartBatteryStatsLoader();
- if (clearHeader) {
- mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
- }
- }
-
@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
restartBatteryTipLoader();
@@ -430,7 +427,7 @@
mContext = context;
mLoader = loader;
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
- mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
+ mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
@Override
public void onBatteryInfoLoaded(BatteryInfo info) {
diff --git a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
index ba1db34..18cb476 100644
--- a/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
+++ b/src/com/android/settings/fuelgauge/RestrictedAppDetails.java
@@ -120,6 +120,11 @@
return MetricsProto.MetricsEvent.FUELGAUGE_RESTRICTED_APP_DETAILS;
}
+ @Override
+ public int getHelpResource() {
+ return R.string.help_uri_restricted_apps;
+ }
+
@VisibleForTesting
void refreshUi() {
mRestrictedAppListGroup.removeAll();
diff --git a/src/com/android/settings/fuelgauge/SmartBatterySettings.java b/src/com/android/settings/fuelgauge/SmartBatterySettings.java
index ff00d06..7076001 100644
--- a/src/com/android/settings/fuelgauge/SmartBatterySettings.java
+++ b/src/com/android/settings/fuelgauge/SmartBatterySettings.java
@@ -62,6 +62,11 @@
}
@Override
+ public int getHelpResource() {
+ return R.string.help_uri_smart_battery_settings;
+ }
+
+ @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, (SettingsActivity) getActivity(), this);
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
index 1cc1fe8..8c553cb 100644
--- a/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
+++ b/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobService.java
@@ -73,7 +73,8 @@
private final Object mLock = new Object();
@GuardedBy("mLock")
- private boolean mIsJobCanceled = false;
+ @VisibleForTesting
+ boolean mIsJobCanceled = false;
public static void scheduleAnomalyDetection(Context context, Intent intent) {
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
@@ -91,6 +92,9 @@
@Override
public boolean onStartJob(JobParameters params) {
+ synchronized (mLock) {
+ mIsJobCanceled = false;
+ }
ThreadUtils.postOnBackgroundThread(() -> {
final Context context = AnomalyDetectionJobService.this;
final BatteryDatabaseManager batteryDatabaseManager =
@@ -98,18 +102,15 @@
final BatteryTipPolicy policy = new BatteryTipPolicy(this);
final BatteryUtils batteryUtils = BatteryUtils.getInstance(this);
final ContentResolver contentResolver = getContentResolver();
- final BatteryStatsHelper batteryStatsHelper = new BatteryStatsHelper(this,
- true /* collectBatteryBroadcast */);
final UserManager userManager = getSystemService(UserManager.class);
final PowerWhitelistBackend powerWhitelistBackend = PowerWhitelistBackend.getInstance();
final PowerUsageFeatureProvider powerUsageFeatureProvider = FeatureFactory
.getFactory(this).getPowerUsageFeatureProvider(this);
final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory
.getFactory(this).getMetricsFeatureProvider();
- batteryUtils.initBatteryStatsHelper(batteryStatsHelper, null /* bundle */, userManager);
for (JobWorkItem item = dequeueWork(params); item != null; item = dequeueWork(params)) {
- saveAnomalyToDatabase(context, batteryStatsHelper, userManager,
+ saveAnomalyToDatabase(context, userManager,
batteryDatabaseManager, batteryUtils, policy, powerWhitelistBackend,
contentResolver, powerUsageFeatureProvider, metricsFeatureProvider,
item.getIntent().getExtras());
@@ -130,8 +131,7 @@
}
@VisibleForTesting
- void saveAnomalyToDatabase(Context context, BatteryStatsHelper batteryStatsHelper,
- UserManager userManager,
+ void saveAnomalyToDatabase(Context context, UserManager userManager,
BatteryDatabaseManager databaseManager, BatteryUtils batteryUtils,
BatteryTipPolicy policy, PowerWhitelistBackend powerWhitelistBackend,
ContentResolver contentResolver, PowerUsageFeatureProvider powerUsageFeatureProvider,
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
index ef903a8..5cd5277 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -94,10 +94,7 @@
return new AlertDialog.Builder(context)
.setMessage(getString(R.string.battery_tip_dialog_message,
- highUsageTip.getHighUsageAppList().size(),
- StringUtil.formatRelativeTime(context,
- highUsageTip.getLastFullChargeTimeMs(),
- false /* withSeconds */)))
+ highUsageTip.getHighUsageAppList().size()))
.setView(view)
.setPositiveButton(android.R.string.ok, null)
.create();
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
index fa970ed..42e723d 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicy.java
@@ -230,7 +230,7 @@
appRestrictionEnabled = mParser.getBoolean(KEY_APP_RESTRICTION_ENABLED, true);
reducedBatteryEnabled = mParser.getBoolean(KEY_REDUCED_BATTERY_ENABLED, false);
reducedBatteryPercent = mParser.getInt(KEY_REDUCED_BATTERY_PERCENT, 50);
- lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, false);
+ lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, true);
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 3);
dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
index 24c763c..da2d81f 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java
@@ -94,6 +94,7 @@
case BatteryTip.TipType.SMART_BATTERY_MANAGER:
return new SmartBatteryAction(settingsActivity, fragment);
case BatteryTip.TipType.BATTERY_SAVER:
+ case BatteryTip.TipType.LOW_BATTERY:
if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
return new OpenBatterySaverAction(settingsActivity);
} else {
diff --git a/src/com/android/settings/notification/CallVolumePreferenceController.java b/src/com/android/settings/notification/CallVolumePreferenceController.java
new file mode 100644
index 0000000..c0e1633
--- /dev/null
+++ b/src/com/android/settings/notification/CallVolumePreferenceController.java
@@ -0,0 +1,55 @@
+/*
+ * 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.content.Context;
+import android.media.AudioManager;
+
+import com.android.settings.R;
+
+
+public class CallVolumePreferenceController extends VolumeSeekBarPreferenceController {
+
+ private AudioManager mAudioManager;
+
+ public CallVolumePreferenceController(Context context, String key) {
+ super(context, key);
+ mAudioManager = context.getSystemService(AudioManager.class);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_call_volume)
+ && !mHelper.isSingleVolume() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public int getAudioStream() {
+ if (mAudioManager.isBluetoothScoOn()) {
+ return AudioManager.STREAM_BLUETOOTH_SCO;
+ }
+ return AudioManager.STREAM_VOICE_CALL;
+ }
+
+ @Override
+ public int getMuteIcon() {
+ // User will not be allowed to fully mute the call volume, use original
+ // icon for mute icon.
+ return R.drawable.ic_local_phone_24_lib;
+ }
+
+}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 228ced1..33818e0 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -153,6 +153,7 @@
volumeControllers.add(use(MediaVolumePreferenceController.class));
volumeControllers.add(use(RingVolumePreferenceController.class));
volumeControllers.add(use(NotificationVolumePreferenceController.class));
+ volumeControllers.add(use(CallVolumePreferenceController.class));
for (VolumeSeekBarPreferenceController controller : volumeControllers) {
controller.setCallback(mVolumeCallback);
diff --git a/src/com/android/settings/notification/VolumeSeekBarPreference.java b/src/com/android/settings/notification/VolumeSeekBarPreference.java
index 28d60f7..ee02b62 100644
--- a/src/com/android/settings/notification/VolumeSeekBarPreference.java
+++ b/src/com/android/settings/notification/VolumeSeekBarPreference.java
@@ -83,7 +83,9 @@
public void setStream(int stream) {
mStream = stream;
setMax(mAudioManager.getStreamMaxVolume(mStream));
- setMin(mAudioManager.getStreamMinVolume(mStream));
+ // Use getStreamMinVolumeInt for non-public stream type
+ // eg: AudioManager.STREAM_BLUETOOTH_SCO
+ setMin(mAudioManager.getStreamMinVolumeInt(mStream));
setProgress(mAudioManager.getStreamVolume(mStream));
}
@@ -108,10 +110,6 @@
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
- if (mStream == 0) {
- Log.w(TAG, "No stream found, not binding volumizer");
- return;
- }
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index ece2a9e..cb8a048 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -16,6 +16,9 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
+
import android.app.ActivityManager;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
@@ -146,19 +149,24 @@
protected void savePolicy(int priorityCategories, int priorityCallSenders,
int priorityMessageSenders, int suppressedVisualEffects) {
mPolicy = new NotificationManager.Policy(priorityCategories, priorityCallSenders,
- priorityMessageSenders,
- suppressedVisualEffects);
+ priorityMessageSenders, suppressedVisualEffects);
mNotificationManager.setNotificationPolicy(mPolicy);
}
- protected int getNewSuppressedEffects(boolean suppress, int effectType) {
+ private int getNewSuppressedEffects(boolean suppress, int effectType) {
int effects = mPolicy.suppressedVisualEffects;
+
if (suppress) {
effects |= effectType;
} else {
effects &= ~effectType;
}
- return effects;
+
+ return clearDeprecatedEffects(effects);
+ }
+
+ private int clearDeprecatedEffects(int effects) {
+ return effects & ~(SUPPRESSED_EFFECT_SCREEN_ON | SUPPRESSED_EFFECT_SCREEN_OFF);
}
protected boolean isEffectAllowed(int effect) {
diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
similarity index 83%
rename from src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
rename to src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
index 908ec04..4ab1437 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
@@ -22,13 +22,13 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeBehaviorPreferenceController extends
+public class ZenModeBehaviorCallsPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
- protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorCallsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@@ -47,7 +47,6 @@
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
- getZenMode()));
+ preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
}
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
index a36c266..1a6a3b4 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
@@ -16,8 +16,8 @@
package com.android.settings.notification;
-import android.content.Context;
import android.content.ComponentName;
+import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
@@ -30,14 +30,17 @@
public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "footer_preference";
+ private final int mTitleRes;
- public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle,
+ int titleRes) {
super(context, KEY, lifecycle);
+ mTitleRes = titleRes;
}
@Override
public boolean isAvailable() {
- return isDeprecatedZenMode(getZenMode());
+ return true;
}
@Override
@@ -48,45 +51,45 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
-
- boolean isAvailable = isAvailable();
- preference.setVisible(isAvailable);
- if (isAvailable) {
- preference.setTitle(getFooterText());
- }
-
+ preference.setTitle(getFooterText());
}
protected String getFooterText() {
- ZenModeConfig config = getZenModeConfig();
+ if (isDeprecatedZenMode(getZenMode())) {
+ ZenModeConfig config = getZenModeConfig();
- // DND turned on by manual rule with deprecated zen mode
- if (config.manualRule != null &&
- isDeprecatedZenMode(config.manualRule.zenMode)) {
- final Uri id = config.manualRule.conditionId;
- if (config.manualRule.enabler != null) {
- // app triggered manual rule
- String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler);
- if (!appOwner.isEmpty()) {
- return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
- }
- } else {
- return mContext.getString(R.string.zen_mode_qs_set_behavior);
- }
- }
-
- // DND turned on by an automatic rule with deprecated zen mode
- for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
- if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(automaticRule.zenMode)) {
- ComponentName component = automaticRule.component;
- if (component != null) {
- return mContext.getString(R.string.zen_mode_app_set_behavior,
- component.getPackageName());
+ // DND turned on by manual rule with deprecated zen mode
+ if (config.manualRule != null &&
+ isDeprecatedZenMode(config.manualRule.zenMode)) {
+ final Uri id = config.manualRule.conditionId;
+ if (config.manualRule.enabler != null) {
+ // app triggered manual rule
+ String appOwner = mZenModeConfigWrapper.getOwnerCaption(
+ config.manualRule.enabler);
+ if (!appOwner.isEmpty()) {
+ return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
+ }
+ } else {
+ return mContext.getString(R.string.zen_mode_qs_set_behavior);
}
}
- }
- return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
+ // DND turned on by an automatic rule with deprecated zen mode
+ for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
+ if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(
+ automaticRule.zenMode)) {
+ ComponentName component = automaticRule.component;
+ if (component != null) {
+ return mContext.getString(R.string.zen_mode_app_set_behavior,
+ component.getPackageName());
+ }
+ }
+ }
+
+ return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
+ } else {
+ return mContext.getString(mTitleRes);
+ }
}
private boolean isDeprecatedZenMode(int zenMode) {
diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
similarity index 82%
copy from src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
copy to src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
index 908ec04..d11baee 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
@@ -22,13 +22,14 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeBehaviorPreferenceController extends
+public class ZenModeBehaviorMsgEventReminderPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
- protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorMsgEventReminderPreferenceController(Context context,
+ Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@@ -47,7 +48,6 @@
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
- getZenMode()));
+ preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy()));
}
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java
similarity index 77%
copy from src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
copy to src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java
index 908ec04..3d25063 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.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.
@@ -22,13 +22,13 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeBehaviorPreferenceController extends
+public class ZenModeBehaviorSoundPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
- protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@@ -47,7 +47,6 @@
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
- getZenMode()));
+ preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy()));
}
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeCallsSettings.java
similarity index 77%
copy from src/com/android/settings/notification/ZenModeBehaviorSettings.java
copy to src/com/android/settings/notification/ZenModeCallsSettings.java
index 5a084e88..d771ef2 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeCallsSettings.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.
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
+
import android.content.Context;
import android.provider.SearchIndexableResource;
@@ -31,7 +33,7 @@
import java.util.List;
@SearchIndexable
-public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
+public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -41,23 +43,20 @@
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new ZenModeAlarmsPreferenceController(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));
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
+ PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers"));
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
context.getResources().getInteger(com.android.internal.R.integer
.config_zen_repeat_callers_threshold)));
- controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(
+ context, lifecycle, R.string.zen_mode_calls_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_behavior_settings;
+ return R.xml.zen_mode_calls_settings;
}
@Override
@@ -68,7 +67,7 @@
/**
* For Search.
*/
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -77,7 +76,7 @@
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.zen_mode_behavior_settings;
+ sir.xmlResId = R.xml.zen_mode_calls_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
similarity index 78%
rename from src/com/android/settings/notification/ZenModeBehaviorSettings.java
rename to src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
index 5a084e88..e3a721f 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.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.
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+
import android.content.Context;
import android.provider.SearchIndexableResource;
@@ -31,7 +33,7 @@
import java.util.List;
@SearchIndexable
-public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
+public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -41,23 +43,19 @@
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new ZenModeAlarmsPreferenceController(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));
- controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
- context.getResources().getInteger(com.android.internal.R.integer
- .config_zen_repeat_callers_threshold)));
- controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
+ PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages"));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
+ R.string.zen_msg_event_reminder_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_behavior_settings;
+ return R.xml.zen_mode_msg_event_reminder_settings;
}
@Override
@@ -77,7 +75,7 @@
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.zen_mode_behavior_settings;
+ sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/notification/ZenModeRestrictNotificationsSettings.java b/src/com/android/settings/notification/ZenModeRestrictNotificationsSettings.java
index 966e932..a2a0ba7 100644
--- a/src/com/android/settings/notification/ZenModeRestrictNotificationsSettings.java
+++ b/src/com/android/settings/notification/ZenModeRestrictNotificationsSettings.java
@@ -70,7 +70,6 @@
custom.displayPreference(getPreferenceScreen());
if (mShowMenuSelected) {
- custom.select();
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, true);
} else {
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, false);
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index ddbfcb6..3fb5a4b 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -16,6 +16,15 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM;
+
import android.app.AutomaticZenRule;
import android.app.FragmentManager;
import android.app.NotificationManager;
@@ -42,19 +51,13 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.Predicate;
@SearchIndexable
public class ZenModeSettings extends ZenModeSettingsBase {
- private static final String KEY_SOUND = "zen_effect_sound";
-
@Override
public void onResume() {
super.onResume();
- CheckBoxPreference soundPreference =
- (CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SOUND);
- if (soundPreference != null) {
- soundPreference.setChecked(true);
- }
}
@Override
@@ -80,7 +83,9 @@
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, FragmentManager fragmentManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
fragmentManager));
@@ -100,19 +105,63 @@
// these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
private static final int[] ALL_PRIORITY_CATEGORIES = {
- Policy.PRIORITY_CATEGORY_ALARMS,
- Policy.PRIORITY_CATEGORY_MEDIA,
- Policy.PRIORITY_CATEGORY_SYSTEM,
- Policy.PRIORITY_CATEGORY_REMINDERS,
- Policy.PRIORITY_CATEGORY_EVENTS,
- Policy.PRIORITY_CATEGORY_MESSAGES,
- Policy.PRIORITY_CATEGORY_CALLS,
- Policy.PRIORITY_CATEGORY_REPEAT_CALLERS,
+ PRIORITY_CATEGORY_ALARMS,
+ PRIORITY_CATEGORY_MEDIA,
+ PRIORITY_CATEGORY_SYSTEM,
+ PRIORITY_CATEGORY_MESSAGES,
+ PRIORITY_CATEGORY_EVENTS,
+ PRIORITY_CATEGORY_REMINDERS,
+ PRIORITY_CATEGORY_CALLS,
+ PRIORITY_CATEGORY_REPEAT_CALLERS,
};
- String getBehaviorSettingSummary(Policy policy, int zenMode) {
- List<String> enabledCategories = getEnabledCategories(policy);
+ String getSoundSettingSummary(Policy policy) {
+ List<String> enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_ALARMS == category
+ || PRIORITY_CATEGORY_MEDIA == category
+ || PRIORITY_CATEGORY_SYSTEM == category);
+ int numCategories = enabledCategories.size();
+ if (numCategories == 0) {
+ return mContext.getString(R.string.zen_sound_all_muted);
+ } else if (numCategories == 1) {
+ return mContext.getString(R.string.zen_sound_one_allowed,
+ enabledCategories.get(0).toLowerCase());
+ } else if (numCategories == 2) {
+ return mContext.getString(R.string.zen_sound_two_allowed,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase());
+ } else if (numCategories == 3) {
+ return mContext.getString(R.string.zen_sound_three_allowed,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase(),
+ enabledCategories.get(2).toLowerCase());
+ } else {
+ return mContext.getString(R.string.zen_sound_none_muted);
+ }
+ }
+ String getCallsSettingSummary(Policy policy) {
+ List<String> enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_CALLS == category
+ || PRIORITY_CATEGORY_REPEAT_CALLERS == category);
+ int numCategories = enabledCategories.size();
+ if (numCategories == 0) {
+ return mContext.getString(R.string.zen_mode_no_exceptions);
+ } else if (numCategories == 1) {
+ return mContext.getString(R.string.zen_mode_calls_summary_one,
+ enabledCategories.get(0).toLowerCase());
+ } else {
+ return mContext.getString(R.string.zen_mode_calls_summary_two,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase());
+ }
+ }
+
+ String getMsgEventReminderSettingSummary(Policy policy) {
+ List<String> enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_EVENTS == category
+ || PRIORITY_CATEGORY_REMINDERS == category
+ || PRIORITY_CATEGORY_MESSAGES == category);
int numCategories = enabledCategories.size();
if (numCategories == 0) {
return mContext.getString(R.string.zen_mode_no_exceptions);
@@ -201,22 +250,19 @@
return count;
}
- private List<String> getEnabledCategories(Policy policy) {
+ private List<String> getEnabledCategories(Policy policy,
+ Predicate<Integer> filteredCategories) {
List<String> enabledCategories = new ArrayList<>();
for (int category : ALL_PRIORITY_CATEGORIES) {
- if (isCategoryEnabled(policy, category)) {
- if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
+ if (filteredCategories.test(category) && isCategoryEnabled(policy, category)) {
+ if (category == PRIORITY_CATEGORY_ALARMS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
- } else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
+ } else if (category == PRIORITY_CATEGORY_MEDIA) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_media));
- } else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
+ } else if (category == 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) {
- enabledCategories.add(mContext.getString(R.string.zen_mode_events));
} else if (category == Policy.PRIORITY_CATEGORY_MESSAGES) {
if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
@@ -225,13 +271,20 @@
enabledCategories.add(mContext.getString(
R.string.zen_mode_selected_messages));
}
+ } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_events));
+ } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
} else if (category == Policy.PRIORITY_CATEGORY_CALLS) {
if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_all_callers));
+ } else if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_CONTACTS){
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_contacts_callers));
} else {
enabledCategories.add(mContext.getString(
- R.string.zen_mode_selected_callers));
+ R.string.zen_mode_starred_callers));
}
} else if (category == Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) {
if (!enabledCategories.contains(mContext.getString(
@@ -248,10 +301,6 @@
private boolean isCategoryEnabled(Policy policy, int categoryType) {
return (policy.priorityCategories & categoryType) != 0;
}
-
- private boolean isEffectSuppressed(Policy policy, int effect) {
- return (policy.suppressedVisualEffects & effect) != 0;
- }
}
/**
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
similarity index 76%
copy from src/com/android/settings/notification/ZenModeBehaviorSettings.java
copy to src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
index 5a084e88..b72460c 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.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.
@@ -31,7 +31,7 @@
import java.util.List;
@SearchIndexable
-public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
+public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -44,20 +44,14 @@
controllers.add(new ZenModeAlarmsPreferenceController(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));
- controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
- context.getResources().getInteger(com.android.internal.R.integer
- .config_zen_repeat_callers_threshold)));
- controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
+ R.string.zen_sound_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_behavior_settings;
+ return R.xml.zen_mode_sound_vibration_settings;
}
@Override
@@ -68,7 +62,7 @@
/**
* For Search.
*/
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -77,7 +71,7 @@
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.zen_mode_behavior_settings;
+ sir.xmlResId = R.xml.zen_mode_sound_vibration_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java
new file mode 100644
index 0000000..0996534
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java
@@ -0,0 +1,153 @@
+/*
+ * 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.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.icu.text.ListFormatter;
+import android.provider.Contacts;
+import android.provider.ContactsContract;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ZenModeStarredContactsPreferenceController extends
+ AbstractZenModePreferenceController implements Preference.OnPreferenceClickListener {
+
+ protected static String KEY;
+ private Preference mPreference;
+ private final int mPriorityCategory;
+ private final PackageManager mPackageManager;
+
+ @VisibleForTesting
+ Intent mStarredContactsIntent;
+ @VisibleForTesting
+ Intent mFallbackIntent;
+
+ public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int
+ priorityCategory, String key) {
+ super(context, key, lifecycle);
+ KEY = key;
+
+ mPriorityCategory = priorityCategory;
+ mPackageManager = mContext.getPackageManager();
+
+ mStarredContactsIntent = new Intent(Contacts.Intents.UI.LIST_STARRED_ACTION);
+
+ mFallbackIntent = new Intent(Intent.ACTION_MAIN);
+ mFallbackIntent.addCategory(Intent.CATEGORY_APP_CONTACTS);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(KEY);
+ mPreference.setOnPreferenceClickListener(this);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (mPriorityCategory == PRIORITY_CATEGORY_CALLS) {
+ return mBackend.isPriorityCategoryEnabled(PRIORITY_CATEGORY_CALLS)
+ && mBackend.getPriorityCallSenders() == PRIORITY_SENDERS_STARRED
+ && isIntentValid();
+ } else if (mPriorityCategory == PRIORITY_CATEGORY_MESSAGES) {
+ return mBackend.isPriorityCategoryEnabled(PRIORITY_CATEGORY_MESSAGES)
+ && mBackend.getPriorityMessageSenders() == PRIORITY_SENDERS_STARRED
+ && isIntentValid();
+ } else {
+ // invalid category
+ return false;
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ List<String> starredContacts = getStarredContacts();
+ int numStarredContacts = starredContacts.size();
+
+ List<String> displayContacts = new ArrayList<>();
+
+ if (numStarredContacts == 0) {
+ displayContacts.add(mContext.getString(R.string.zen_mode_from_none));
+ } else {
+ for (int i = 0; i < 2 && i < numStarredContacts; i++) {
+ displayContacts.add(starredContacts.get(i));
+ }
+
+ if (numStarredContacts == 3) {
+ displayContacts.add(starredContacts.get(2));
+ } else if (numStarredContacts > 2) {
+ displayContacts.add(mContext.getResources().getQuantityString(
+ R.plurals.zen_mode_starred_contacts_summary_additional_contacts,
+ numStarredContacts - 2, numStarredContacts - 2));
+ }
+ }
+
+ mPreference.setSummary(ListFormatter.getInstance().format(displayContacts));
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (mStarredContactsIntent.resolveActivity(mPackageManager) != null) {
+ mContext.startActivity(mStarredContactsIntent);
+ } else {
+ mContext.startActivity(mFallbackIntent);
+ }
+ return true;
+ }
+
+ private List<String> getStarredContacts() {
+ List<String> starredContacts = new ArrayList<>();
+
+ Cursor cursor = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
+ new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
+ ContactsContract.Data.STARRED + "=1", null,
+ ContactsContract.Data.TIMES_CONTACTED);
+
+ if (cursor.moveToFirst()) {
+ do {
+ starredContacts.add(cursor.getString(0));
+ } while (cursor.moveToNext());
+ }
+ return starredContacts;
+ }
+
+ private boolean isIntentValid() {
+ return mStarredContactsIntent.resolveActivity(mPackageManager) != null
+ || mFallbackIntent.resolveActivity(mPackageManager) != null;
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceController.java b/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceController.java
index 550fda4..5baf0fa 100644
--- a/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceController.java
@@ -18,6 +18,7 @@
import android.app.NotificationManager.Policy;
import android.content.Context;
+
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -57,15 +58,12 @@
pref.setChecked(areCustomOptionsSelected());
pref.setOnGearClickListener(p -> {
- new SubSettingLauncher(mContext)
- .setDestination(ZenModeBlockedEffectsSettings.class.getName())
- .setTitleRes(R.string.zen_mode_what_to_block_title)
- .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
- .launch();
+ launchCustomSettings();
+
});
pref.setOnRadioButtonClickListener(p -> {
- select();
+ launchCustomSettings();
});
}
@@ -84,9 +82,14 @@
protected void select() {
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM, true);
- mBackend.savePolicy(mBackend.mPolicy.priorityCategories,
- mBackend.mPolicy.priorityCallSenders,
- mBackend.mPolicy.priorityMessageSenders,
- INTERRUPTIVE_EFFECTS);
+ }
+
+ private void launchCustomSettings() {
+ select();
+ new SubSettingLauncher(mContext)
+ .setDestination(ZenModeBlockedEffectsSettings.class.getName())
+ .setTitleRes(R.string.zen_mode_what_to_block_title)
+ .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
+ .launch();
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
index 37978df..a171844 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
@@ -47,17 +47,19 @@
List<String> keywords);
default void updateIndex(Context context, boolean force) {
- if (!isIndexingEnabled()) return;
+ if (!isIndexingEnabled()) {
+ return;
+ }
if (!force && Objects.equals(
- Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) {
+ Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) {
// No need to update.
return;
}
- ComponentName jobComponent = new ComponentName(context.getPackageName(),
+ final ComponentName jobComponent = new ComponentName(context.getPackageName(),
DeviceIndexUpdateJobService.class.getName());
- int jobId = context.getResources().getInteger(R.integer.device_index_update);
+ final int jobId = context.getResources().getInteger(R.integer.device_index_update);
// Schedule a job so that we know it'll be able to complete, but try to run as
// soon as possible.
context.getSystemService(JobScheduler.class).schedule(
@@ -70,11 +72,10 @@
Settings.Secure.putString(context.getContentResolver(), INDEX_VERSION, VERSION);
}
- static String createDeepLink(String s) {
+ static Uri createDeepLink(String s) {
return new Uri.Builder().scheme(SETTINGS)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendQueryParameter(INTENT, s)
- .build()
- .toString();
+ .build();
}
}
diff --git a/src/com/android/settings/search/DeviceIndexUpdateJobService.java b/src/com/android/settings/search/DeviceIndexUpdateJobService.java
index 573dcdf..12a9cf0 100644
--- a/src/com/android/settings/search/DeviceIndexUpdateJobService.java
+++ b/src/com/android/settings/search/DeviceIndexUpdateJobService.java
@@ -17,7 +17,6 @@
import static android.app.slice.Slice.HINT_LARGE;
import static android.app.slice.Slice.HINT_TITLE;
import static android.app.slice.SliceItem.FORMAT_TEXT;
-
import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepLink;
import android.app.job.JobParameters;
@@ -73,16 +72,20 @@
@VisibleForTesting
protected void updateIndex(JobParameters params) {
- if (DEBUG) Log.d(TAG, "Starting index");
- DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(
- this).getDeviceIndexFeatureProvider();
- SliceManager manager = getSliceManager();
- Uri baseUri = new Builder()
+ if (DEBUG) {
+ Log.d(TAG, "Starting index");
+ }
+ final DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(this)
+ .getDeviceIndexFeatureProvider();
+ final SliceManager manager = getSliceManager();
+ final Uri baseUri = new Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.build();
- Collection<Uri> slices = manager.getSliceDescendants(baseUri);
- if (DEBUG) Log.d(TAG, "Indexing " + slices.size() + " slices");
+ final Collection<Uri> slices = manager.getSliceDescendants(baseUri);
+ if (DEBUG) {
+ Log.d(TAG, "Indexing " + slices.size() + " slices");
+ }
for (Uri slice : slices) {
if (!mRunningJob) {
@@ -93,16 +96,20 @@
SliceMetadata metaData = getMetadata(loadedSlice);
CharSequence title = findTitle(loadedSlice, metaData);
if (title != null) {
- if (DEBUG) Log.d(TAG, "Indexing: " + slice + " " + title + " " + loadedSlice);
- indexProvider.index(this, title, slice, Uri.parse(createDeepLink(
+ if (DEBUG) {
+ Log.d(TAG, "Indexing: " + slice + " " + title + " " + loadedSlice);
+ }
+ indexProvider.index(this, title, slice, createDeepLink(
new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE)
.setPackage(getPackageName())
.putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE, slice.toString())
- .toUri(Intent.URI_ANDROID_APP_SCHEME))),
+ .toUri(Intent.URI_ANDROID_APP_SCHEME)),
metaData.getSliceKeywords());
}
}
- if (DEBUG) Log.d(TAG, "Done indexing");
+ if (DEBUG) {
+ Log.d(TAG, "Done indexing");
+ }
jobFinished(params, false);
}
diff --git a/src/com/android/settings/security/LockdownButtonPreferenceController.java b/src/com/android/settings/security/LockdownButtonPreferenceController.java
index dd6e0d0..5b29868 100644
--- a/src/com/android/settings/security/LockdownButtonPreferenceController.java
+++ b/src/com/android/settings/security/LockdownButtonPreferenceController.java
@@ -21,7 +21,6 @@
import android.provider.Settings;
import com.android.internal.widget.LockPatternUtils;
-import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.TogglePreferenceController;
public class LockdownButtonPreferenceController extends TogglePreferenceController {
@@ -36,9 +35,9 @@
@Override
public int getAvailabilityStatus() {
if (mLockPatternUtils.isSecure(UserHandle.myUserId())) {
- return BasePreferenceController.AVAILABLE;
+ return AVAILABLE;
} else {
- return BasePreferenceController.DISABLED_FOR_USER;
+ return DISABLED_FOR_USER;
}
}
diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java
index c9ed2c2..1cabb92 100644
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -18,7 +18,6 @@
import android.content.Context;
import android.provider.SearchIndexableResource;
-import androidx.annotation.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -34,6 +33,8 @@
import java.util.Arrays;
import java.util.List;
+import androidx.annotation.VisibleForTesting;
+
/**
* Settings screen for lock screen preference
*/
diff --git a/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java
index ffb26bc..117946a 100644
--- a/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java
+++ b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java
@@ -16,13 +16,13 @@
package com.android.settings.security;
+
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
+import android.util.Log;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.Utils;
@@ -32,10 +32,17 @@
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
public class VisiblePatternProfilePreferenceController extends TogglePreferenceController
implements LifecycleObserver, OnResume {
private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
+ private static final String TAG = "VisPtnProfPrefCtrl";
private final LockPatternUtils mLockPatternUtils;
private final UserManager mUm;
@@ -45,7 +52,7 @@
private Preference mPreference;
public VisiblePatternProfilePreferenceController(Context context) {
- this(context, null /* lifecycle */);
+ this(context, null /* lifecycle */);
}
// TODO (b/73074893) Replace this constructor without Lifecycle using setter method instead.
@@ -63,12 +70,25 @@
@Override
public int getAvailabilityStatus() {
- if (mLockPatternUtils.isSecure(mProfileChallengeUserId)
- && mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
- == PASSWORD_QUALITY_SOMETHING) {
- return AVAILABLE;
+ final FutureTask<Integer> futureTask = new FutureTask<>(
+ // Put the API call in a future to avoid StrictMode violation.
+ () -> {
+ final boolean isSecure = mLockPatternUtils.isSecure(mProfileChallengeUserId);
+ final boolean hasPassword = mLockPatternUtils
+ .getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
+ == PASSWORD_QUALITY_SOMETHING;
+ if (isSecure && hasPassword) {
+ return AVAILABLE;
+ }
+ return DISABLED_FOR_USER;
+ });
+ try {
+ futureTask.run();
+ return futureTask.get();
+ } catch (InterruptedException | ExecutionException e) {
+ Log.w(TAG, "Error getting lock pattern state.");
+ return DISABLED_FOR_USER;
}
- return DISABLED_FOR_USER;
}
@Override
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 71a3828..edeb2b5 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -26,11 +26,8 @@
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiManager;
-import android.os.StrictMode;
import android.provider.Settings;
-import androidx.annotation.VisibleForTesting;
import android.provider.SettingsSlicesContract;
-import androidx.core.graphics.drawable.IconCompat;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -46,6 +43,8 @@
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
+import androidx.annotation.VisibleForTesting;
+import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
import androidx.slice.SliceProvider;
import androidx.slice.builders.ListBuilder;
@@ -155,11 +154,6 @@
@Override
public Slice onBindSlice(Uri sliceUri) {
- // TODO: Remove this when all slices are not breaking strict mode
- StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
- .permitAll()
- .build());
-
String path = sliceUri.getPath();
// If adding a new Slice, do not directly match Slice URIs.
// Use {@link SlicesDatabaseAccessor}.
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index d9473d8..265564e 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -161,7 +161,6 @@
*/
@Override
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
- updateState(mPreference);
}
@Override
@@ -175,6 +174,12 @@
}
@Override
+ public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
+ int bluetoothProfile) {
+ updateState(mPreference);
+ }
+
+ @Override
public void onBluetoothStateChanged(int bluetoothState) {
}
diff --git a/src/com/android/settings/system/SystemUpdatePreferenceController.java b/src/com/android/settings/system/SystemUpdatePreferenceController.java
index bd8ffa7..54ab924 100644
--- a/src/com/android/settings/system/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/system/SystemUpdatePreferenceController.java
@@ -35,6 +35,9 @@
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
public class SystemUpdatePreferenceController extends BasePreferenceController {
private static final String TAG = "SysUpdatePrefContr";
@@ -84,9 +87,19 @@
@Override
public CharSequence getSummary() {
- final Bundle updateInfo = mUpdateManager.retrieveSystemUpdateInfo();
CharSequence summary = mContext.getString(R.string.android_version_summary,
Build.VERSION.RELEASE);
+ final FutureTask<Bundle> bundleFutureTask = new FutureTask<>(
+ // Put the API call in a future to avoid StrictMode violation.
+ () -> mUpdateManager.retrieveSystemUpdateInfo());
+ final Bundle updateInfo;
+ try {
+ bundleFutureTask.run();
+ updateInfo = bundleFutureTask.get();
+ } catch (InterruptedException | ExecutionException e) {
+ Log.w(TAG, "Error getting system update info.");
+ return summary;
+ }
switch (updateInfo.getInt(SystemUpdateManager.KEY_STATUS)) {
case SystemUpdateManager.STATUS_WAITING_DOWNLOAD:
case SystemUpdateManager.STATUS_IN_PROGRESS:
diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java
index 193861b..018119b 100644
--- a/src/com/android/settings/wifi/WifiEnabler.java
+++ b/src/com/android/settings/wifi/WifiEnabler.java
@@ -160,15 +160,14 @@
setSwitchBarChecked(false);
mSwitchWidget.setEnabled(true);
}
- if (mayDisableTethering(!mSwitchWidget.isChecked())) {
- if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
- UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
- mSwitchWidget.setEnabled(false);
- } else {
- final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
- UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
- mSwitchWidget.setDisabledByAdmin(admin);
- }
+
+ if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
+ UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
+ mSwitchWidget.setEnabled(false);
+ } else {
+ final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
+ UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
+ mSwitchWidget.setDisabledByAdmin(admin);
}
}
@@ -203,15 +202,11 @@
// Show toast message if Wi-Fi is not allowed in airplane mode
if (isChecked && !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_WIFI)) {
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
- // Reset switch to off. No infinite check/listenenr loop.
+ // Reset switch to off. No infinite check/listener loop.
mSwitchWidget.setChecked(false);
return false;
}
- // Disable tethering if enabling Wifi
- if (mayDisableTethering(isChecked)) {
- mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);
- }
if (isChecked) {
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_ON);
} else {
@@ -226,10 +221,4 @@
}
return true;
}
-
- private boolean mayDisableTethering(boolean isChecked) {
- final int wifiApState = mWifiManager.getWifiApState();
- return isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
- (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED));
- }
}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
index 4f3bec0..554cc0e 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
@@ -106,7 +106,7 @@
void startTether() {
mSwitchBar.setEnabled(false);
- mConnectivityManager.startTethering(TETHERING_WIFI, false /* showProvisioningUi */,
+ mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index f257f54..a4907da 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -18,7 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
+import android.os.Vibrator;
+import android.provider.Settings;
+import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -26,6 +34,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
@@ -45,4 +55,31 @@
assertThat(keys).containsAllIn(niks);
}
-}
\ No newline at end of file
+
+ @Test
+ public void testUpdateVibrationSummary_shouldUpdateSummary() {
+ MockitoAnnotations.initMocks(this);
+ final Context mContext = RuntimeEnvironment.application;
+ final AccessibilitySettings mSettings = spy(new AccessibilitySettings());
+
+ final Preference mVibrationPreferenceScreen = new Preference(mContext);
+ doReturn(mVibrationPreferenceScreen).when(mSettings).findPreference(anyString());
+
+ doReturn(mContext).when(mSettings).getContext();
+
+ mVibrationPreferenceScreen.setKey("vibration_preference_screen");
+
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
+ Vibrator.VIBRATION_INTENSITY_OFF);
+
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.HAPTIC_FEEDBACK_INTENSITY,
+ Vibrator.VIBRATION_INTENSITY_OFF);
+
+ mSettings.updateVibrationSummary(mVibrationPreferenceScreen);
+ assertThat(mVibrationPreferenceScreen.getSummary()).isEqualTo(
+ VibrationIntensityPreferenceController.getIntensityString(mContext,
+ Vibrator.VIBRATION_INTENSITY_OFF));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
index fbc698c..ced8fc4 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java
@@ -15,11 +15,11 @@
*/
package com.android.settings.bluetooth;
-import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
-
import android.media.AudioManager;
+
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -73,6 +73,7 @@
private AvailableMediaBluetoothDeviceUpdater mBluetoothDeviceUpdater;
private Collection<CachedBluetoothDevice> cachedDevices;
private ShadowAudioManager mShadowAudioManager;
+ private BluetoothDevicePreference mPreference;
@Before
public void setUp() {
@@ -93,6 +94,7 @@
mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mDashboardFragment,
mDevicePreferenceCallback, mLocalManager));
mBluetoothDeviceUpdater.setPrefContext(mContext);
+ mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
}
@@ -150,62 +152,70 @@
}
@Test
- public void onConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
+ public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
+ public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
+
@Test
- public void onConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
+ public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
+ public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_deviceDisconnected_removePreference() {
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_DISCONNECTED);
+ public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
+
+ @Test
+ public void onClick_Preference_setActive() {
+ mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
+
+ verify(mCachedBluetoothDevice).setActive();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
index fc99744..7449948 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java
@@ -156,6 +156,11 @@
}
@Override
+ public int getProfileId() {
+ return 0;
+ }
+
+ @Override
public int getOrdinal() {
return 0;
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
index 56e638a..483df01 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java
@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -23,11 +24,11 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
-
import android.media.AudioManager;
+
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -75,6 +76,7 @@
private Collection<CachedBluetoothDevice> cachedDevices;
private ShadowAudioManager mShadowAudioManager;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -151,60 +153,61 @@
}
@Test
- public void onConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
+ public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
+ public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
+
@Test
- public void onConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
+ public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
+ public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
when(mBluetoothDeviceUpdater.
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_CONNECTED);
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
@Test
- public void onConnectionStateChanged_deviceDisconnected_removePreference() {
- mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
- BluetoothAdapter.STATE_DISCONNECTED);
+ public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
index e0ba829..547727b 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java
@@ -22,7 +22,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
@@ -57,7 +57,8 @@
private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
private Context mContext;
- private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+ private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
+ private BluetoothDevicePreference mPreference;
@Before
public void setUp() {
@@ -71,12 +72,13 @@
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
mDevicePreferenceCallback, mLocalManager));
mBluetoothDeviceUpdater.setPrefContext(mContext);
+ mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
}
@Test
- public void testUpdate_filterMatch_addPreference() {
+ public void update_filterMatch_addPreference() {
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
doReturn(false).when(mBluetoothDevice).isConnected();
@@ -86,7 +88,7 @@
}
@Test
- public void testUpdate_filterNotMatch_removePreference() {
+ public void update_filterNotMatch_removePreference() {
doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
doReturn(true).when(mBluetoothDevice).isConnected();
@@ -96,18 +98,25 @@
}
@Test
- public void testOnConnectionStateChanged_deviceConnected_removePreference() {
- mBluetoothDeviceUpdater
- .onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_CONNECTED);
+ public void onProfileConnectionStateChanged_deviceConnected_removePreference() {
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
}
@Test
- public void testOnConnectionStateChanged_deviceDisconnected_addPreference() {
- mBluetoothDeviceUpdater
- .onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_DISCONNECTED);
+ public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() {
+ mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
+ BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
}
+
+ @Test
+ public void onClick_Preference_setConnect() {
+ mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
+
+ verify(mCachedBluetoothDevice).connect(true);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
index 611c1b5..d5e8e15 100644
--- a/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/core/BasePreferenceControllerTest.java
@@ -16,12 +16,12 @@
package com.android.settings.core;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,8 +36,10 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
+import java.util.ArrayList;
+import java.util.List;
+
import androidx.preference.Preference;
-import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -73,6 +75,13 @@
}
@Test
+ public void isAvailable_availableStatusUnSearchable_returnsTrue() {
+ mPreferenceController.setAvailability(AVAILABLE_UNSEARCHABLE);
+
+ assertThat(mPreferenceController.isAvailable()).isTrue();
+ }
+
+ @Test
public void isAvailable_availableStatusUnsupportedOnDevice_returnsFalse() {
mPreferenceController.setAvailability(UNSUPPORTED_ON_DEVICE);
@@ -159,6 +168,36 @@
assertThat(preference.isEnabled()).isFalse();
}
+ @Test
+ public void updateNonIndexableKeys_controllerUnavailable_shouldAddKey() {
+ final List<String> keys = new ArrayList<>();
+ mPreferenceController.setAvailability(UNSUPPORTED_ON_DEVICE);
+
+ mPreferenceController.updateNonIndexableKeys(keys);
+
+ assertThat(keys).containsExactly(mPreferenceController.getPreferenceKey());
+ }
+
+ @Test
+ public void updateNonIndexableKeys_controllerUnsearchable_shouldAddKey() {
+ final List<String> keys = new ArrayList<>();
+ mPreferenceController.setAvailability(AVAILABLE_UNSEARCHABLE);
+
+ mPreferenceController.updateNonIndexableKeys(keys);
+
+ assertThat(keys).containsExactly(mPreferenceController.getPreferenceKey());
+ }
+
+ @Test
+ public void updateNonIndexableKeys_controllerAvailable_shouldNotAddKey() {
+ final List<String> keys = new ArrayList<>();
+ mPreferenceController.setAvailability(AVAILABLE);
+
+ mPreferenceController.updateNonIndexableKeys(keys);
+
+ assertThat(keys).isEmpty();
+ }
+
private class FakeBasePreferenceController extends BasePreferenceController {
public int mAvailable;
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java b/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java
index 8df4a31..6942fd8 100644
--- a/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/display/NightDisplaySettingsTest.java
@@ -22,6 +22,7 @@
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.drawer.CategoryKey;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
@@ -45,4 +46,10 @@
assertThat(indexedXml).contains(R.xml.night_display_settings);
}
+
+ @Test
+ public void getCategoryKey_isCategoryNightDisplay() {
+ NightDisplaySettings settings = new NightDisplaySettings();
+ assertThat(settings.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_NIGHT_DISPLAY);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
index 3fdbe83..4583dd1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java
@@ -15,8 +15,11 @@
*/
package com.android.settings.fuelgauge;
+import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -70,14 +73,14 @@
}
@Test
- public void testOnReceive_batteryDataChanged_dataUpdated() {
+ public void testOnReceive_batteryLevelChanged_dataUpdated() {
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
assertThat(mBatteryBroadcastReceiver.mBatteryLevel)
.isEqualTo(Utils.getBatteryPercentage(mChargingIntent));
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
.isEqualTo(Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
- verify(mBatteryListener).onBatteryChanged();
+ verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
}
@Test
@@ -85,7 +88,7 @@
mBatteryBroadcastReceiver.onReceive(mContext,
new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
- verify(mBatteryListener).onBatteryChanged();
+ verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_SAVER);
}
@Test
@@ -100,7 +103,7 @@
assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(batteryLevel);
assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(batteryStatus);
- verify(mBatteryListener, never()).onBatteryChanged();
+ verify(mBatteryListener, never()).onBatteryChanged(anyInt());
}
@Test
@@ -115,6 +118,6 @@
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
.isEqualTo(Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
// 2 times because register will force update the battery
- verify(mBatteryListener, times(2)).onBatteryChanged();
+ verify(mBatteryListener, times(2)).onBatteryChanged(BatteryUpdateType.MANUAL);
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index 5c2a1c7..4fd3a82 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -612,6 +612,14 @@
}
@Test
+ public void testShouldHideAnomaly_AppInDozeList_returnTrue() {
+ doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
+ doReturn(true).when(mPowerWhitelistBackend).isWhitelisted(new String[]{HIGH_SDK_PACKAGE});
+
+ assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID)).isTrue();
+ }
+
+ @Test
public void testShouldHideAnomaly_normalApp_returnFalse() {
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
index 8029c55..1817325 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/HighPowerDetailTest.java
@@ -18,27 +18,49 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import android.app.AppOpsManager;
import android.content.Context;
+import android.content.DialogInterface;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
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;
@RunWith(SettingsRobolectricTestRunner.class)
public class HighPowerDetailTest {
+ private static final int TEST_UID = 12000;
+ private static final String TEST_PACKAGE = "com.test.package";
private FakeFeatureFactory mFeatureFactory;
+ private HighPowerDetail mFragment;
+
+ @Mock
+ private PowerWhitelistBackend mPowerWhitelistBackend;
+ @Mock
+ private BatteryUtils mBatteryUtils;
@Before
public void setUp() {
mFeatureFactory = FakeFeatureFactory.setupForTest();
+
+ MockitoAnnotations.initMocks(this);
+ mFragment = spy(new HighPowerDetail());
+ mFragment.mBackend = mPowerWhitelistBackend;
+ mFragment.mBatteryUtils = mBatteryUtils;
+ mFragment.mPackageUid = TEST_UID;
+ mFragment.mPackageName = TEST_PACKAGE;
}
@Test
@@ -53,4 +75,13 @@
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_BATTERY_ALLOW), eq("app"));
}
+
+ @Test
+ public void onClick_appAddedToDozeWhitelist_getsUnrestricted() {
+ mFragment.mIsEnabled = true;
+ when(mPowerWhitelistBackend.isWhitelisted(TEST_PACKAGE)).thenReturn(false);
+ mFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
+ verify(mBatteryUtils).setForceAppStandby(TEST_UID, TEST_PACKAGE,
+ AppOpsManager.MODE_ALLOWED);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
index 8a7e7a0..ffa49d4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAdvancedTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
@@ -86,7 +87,7 @@
@Test
public void testOptionsMenu_menuAppToggle_metricEventInvoked() {
mFragment.mShowAllApps = false;
- doNothing().when(mFragment).restartBatteryStatsLoader();
+ doNothing().when(mFragment).restartBatteryStatsLoader(anyInt());
mFragment.onOptionsItemSelected(mToggleAppsMenu);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
index d9f572d..eb683c0 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
@@ -74,7 +74,7 @@
}
@Override
- protected void refreshUi() {
+ protected void refreshUi(int refreshType) {
// Do nothing
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index b48f00e..07341a1 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -149,7 +149,7 @@
mFragment.initFeatureProvider();
mBatteryMeterView = new BatteryMeterView(mRealContext);
mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
- doNothing().when(mFragment).restartBatteryStatsLoader();
+ doNothing().when(mFragment).restartBatteryStatsLoader(anyInt());
doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager();
doReturn(MENU_ADVANCED_BATTERY).when(mAdvancedPageMenu).getItemId();
@@ -317,15 +317,6 @@
}
@Test
- public void restartBatteryStatsLoader_notClearHeader_quickUpdateNotInvoked() {
- mFragment.mBatteryHeaderPreferenceController = mBatteryHeaderPreferenceController;
-
- mFragment.restartBatteryStatsLoader(false /* clearHeader */);
-
- verify(mBatteryHeaderPreferenceController, never()).quickUpdateHeaderPreference();
- }
-
- @Test
public void optionsMenu_advancedPageEnabled() {
when(mFeatureFactory.powerUsageFeatureProvider.isPowerAccountingToggleEnabled())
.thenReturn(true);
@@ -360,7 +351,18 @@
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(false);
mFragment.updateBatteryTipFlag(new Bundle());
- mFragment.refreshUi();
+ mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
+
+ verify(mFragment, never()).restartBatteryTipLoader();
+ }
+
+ @Test
+ public void refreshUi_batteryLevelChanged_doNotUpdateBatteryTip() {
+ mFragment.mBatteryTipPreferenceController = mock(BatteryTipPreferenceController.class);
+ when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(true);
+ mFragment.updateBatteryTipFlag(new Bundle());
+
+ mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.BATTERY_LEVEL);
verify(mFragment, never()).restartBatteryTipLoader();
}
@@ -371,7 +373,7 @@
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(true);
mFragment.updateBatteryTipFlag(new Bundle());
- mFragment.refreshUi();
+ mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
verify(mFragment).restartBatteryTipLoader();
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
index f159e79..8df1f21 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/AnomalyDetectionJobServiceTest.java
@@ -46,8 +46,6 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.os.Parcel;
-import android.os.Parcelable;
import android.os.Process;
import android.os.StatsDimensionsValue;
import android.os.UserManager;
@@ -57,11 +55,11 @@
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.R;
import com.android.settings.fuelgauge.BatteryUtils;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
+import com.android.settings.testutils.shadow.ShadowPowerWhitelistBackend;
import org.junit.Before;
import org.junit.Test;
@@ -80,7 +78,7 @@
import java.util.concurrent.TimeUnit;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(shadows = ShadowConnectivityManager.class)
+@Config(shadows = {ShadowConnectivityManager.class, ShadowPowerWhitelistBackend.class})
public class AnomalyDetectionJobServiceTest {
private static final int UID = 12345;
private static final String SYSTEM_PACKAGE = "com.android.system";
@@ -91,8 +89,6 @@
private static final int ANOMALY_TYPE = 6;
private static final long VERSION_CODE = 15;
@Mock
- private BatteryStatsHelper mBatteryStatsHelper;
- @Mock
private UserManager mUserManager;
@Mock
private BatteryDatabaseManager mBatteryDatabaseManager;
@@ -148,9 +144,9 @@
@Test
public void saveAnomalyToDatabase_systemWhitelisted_doNotSave() {
doReturn(UID).when(mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
- doReturn(true).when(mPowerWhitelistBackend).isSysWhitelistedExceptIdle(any(String[].class));
+ doReturn(true).when(mPowerWhitelistBackend).isWhitelisted(any(String[].class));
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider,
@@ -171,7 +167,7 @@
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
doReturn(true).when(mBatteryUtils).shouldHideAnomaly(any(), anyInt());
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider,
@@ -191,7 +187,7 @@
doReturn(Process.SYSTEM_UID).when(
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
@@ -206,7 +202,7 @@
doReturn(AnomalyDetectionJobService.UID_NULL).when(
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
@@ -226,7 +222,7 @@
doReturn(Process.FIRST_APPLICATION_UID).when(
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
@@ -251,7 +247,7 @@
doReturn(Process.FIRST_APPLICATION_UID).when(
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
- mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext, mBatteryStatsHelper,
+ mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
mPowerWhitelistBackend, mContext.getContentResolver(),
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
@@ -316,4 +312,12 @@
// Should not crash even job is stopped
mAnomalyDetectionJobService.completeWork(mJobParameters, mJobWorkItem);
}
+
+ @Test
+ public void restartWorkAfterBeenStopped_jobStarted() {
+ mAnomalyDetectionJobService.onStopJob(mJobParameters);
+ mAnomalyDetectionJobService.onStartJob(mJobParameters);
+
+ assertThat(mAnomalyDetectionJobService.mIsJobCanceled).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
index 7a41921..a02bdc2 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragmentTest.java
@@ -113,7 +113,7 @@
ShadowAlertDialog shadowDialog = shadowOf(dialog);
assertThat(shadowDialog.getMessage()).isEqualTo(
- mContext.getString(R.string.battery_tip_dialog_message, 1, "60 minutes ago"));
+ mContext.getString(R.string.battery_tip_dialog_message, 1));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicyTest.java
index 350326a..547e0eb 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPolicyTest.java
@@ -101,7 +101,7 @@
assertThat(batteryTipPolicy.appRestrictionEnabled).isTrue();
assertThat(batteryTipPolicy.reducedBatteryEnabled).isFalse();
assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(50);
- assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
+ assertThat(batteryTipPolicy.lowBatteryEnabled).isTrue();
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(3);
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
index 7a25555..459c4e2 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java
@@ -29,6 +29,7 @@
import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
+import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -51,6 +52,7 @@
private InstrumentedPreferenceFragment mFragment;
private RestrictAppTip mRestrictAppTip;
private EarlyWarningTip mEarlyWarningTip;
+ private LowBatteryTip mLowBatteryTip;
@Before
public void setUp() {
@@ -59,7 +61,11 @@
FakeFeatureFactory.setupForTest();
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
mRestrictAppTip = spy(new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>()));
- mEarlyWarningTip = spy(new EarlyWarningTip(BatteryTip.StateType.NEW, true));
+ mEarlyWarningTip = spy(
+ new EarlyWarningTip(BatteryTip.StateType.NEW, true /* powerSaveModeOn */));
+ mLowBatteryTip = spy(
+ new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */,
+ "" /* summary */));
}
@Test
@@ -93,4 +99,20 @@
assertThat(BatteryTipUtils.getActionForBatteryTip(mEarlyWarningTip, mSettingsActivity,
mFragment)).isInstanceOf(OpenBatterySaverAction.class);
}
+
+ @Test
+ public void testGetActionForBatteryTip_typeLowBatteryStateNew_returnActionBatterySaver() {
+ when(mLowBatteryTip.getState()).thenReturn(BatteryTip.StateType.NEW);
+
+ assertThat(BatteryTipUtils.getActionForBatteryTip(mLowBatteryTip, mSettingsActivity,
+ mFragment)).isInstanceOf(BatterySaverAction.class);
+ }
+
+ @Test
+ public void testGetActionForBatteryTip_typeLowBatteryStateHandled_returnActionOpen() {
+ when(mLowBatteryTip.getState()).thenReturn(BatteryTip.StateType.HANDLED);
+
+ assertThat(BatteryTipUtils.getActionForBatteryTip(mLowBatteryTip, mSettingsActivity,
+ mFragment)).isInstanceOf(OpenBatterySaverAction.class);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/gestures/GestureSettingsTest.java b/tests/robotests/src/com/android/settings/gestures/GestureSettingsTest.java
new file mode 100644
index 0000000..29d2c19
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/GestureSettingsTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.gestures;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.drawer.CategoryKey;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class GestureSettingsTest {
+
+ @Test
+ public void getCategoryKey_isCategoryGestures() {
+ GestureSettings settings = new GestureSettings();
+ assertThat(settings.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_GESTURES);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/CallVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/CallVolumePreferenceControllerTest.java
new file mode 100644
index 0000000..bed45e5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/CallVolumePreferenceControllerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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 com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.media.AudioManager;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowAudioManager;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {ShadowAudioManager.class})
+public class CallVolumePreferenceControllerTest {
+ private static final String TEST_KEY = "Test_Key";
+
+ @Mock
+ private AudioHelper mHelper;
+
+ private Context mContext;
+ private CallVolumePreferenceController mController;
+ private ShadowAudioManager mShadowAudioManager;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new CallVolumePreferenceController(mContext, TEST_KEY);
+ mController.setAudioHelper(mHelper);
+ mShadowAudioManager = ShadowAudioManager.getShadow();
+ }
+
+ @Test
+ public void getAvailabilityStatus_singleVolume_shouldReturnDisable() {
+ when(mHelper.isSingleVolume()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_notSingleVolume_shouldReturnAvailable() {
+ when(mHelper.isSingleVolume()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getMuteIcon_shouldEqualToOriginalIcon() {
+ assertThat(mController.getMuteIcon()).isEqualTo(R.drawable.ic_local_phone_24_lib);
+ }
+
+ @Test
+ public void getAudioStream_onBluetoothScoOff_shouldEqualToStreamVoiceCall() {
+ mShadowAudioManager.setBluetoothScoOn(false);
+
+ assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_VOICE_CALL);
+ }
+
+ @Test
+ public void getAudioStream_onBluetoothScoOn_shouldEqualToStreamBtSco() {
+ mShadowAudioManager.setBluetoothScoOn(true);
+
+ assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_BLUETOOTH_SCO);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
index c32f96a..5955aa8 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
@@ -50,17 +50,20 @@
}
@Test
- public void setStream_shouldSetMaxAndProgress() {
+ public void setStream_shouldSetMinMaxAndProgress() {
final int stream = 5;
final int max = 17;
+ final int min = 1;
final int progress = 4;
when(mAudioManager.getStreamMaxVolume(stream)).thenReturn(max);
+ when(mAudioManager.getStreamMinVolumeInt(stream)).thenReturn(min);
when(mAudioManager.getStreamVolume(stream)).thenReturn(progress);
doCallRealMethod().when(mPreference).setStream(anyInt());
mPreference.setStream(stream);
verify(mPreference).setMax(max);
+ verify(mPreference).setMin(min);
verify(mPreference).setProgress(progress);
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
new file mode 100644
index 0000000..b3a4b90
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+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.Context;
+import androidx.preference.Preference;
+
+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.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorCallsPreferenceControllerTest {
+
+ private ZenModeBehaviorCallsPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorCallsPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
index 760efb2..0bf8214 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
@@ -41,6 +41,7 @@
import androidx.preference.PreferenceScreen;
import android.util.ArrayMap;
+import com.android.settings.R;
import com.android.settings.notification.AbstractZenModePreferenceController.ZenModeConfigWrapper;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -77,6 +78,7 @@
private Context mContext;
private ContentResolver mContentResolver;
+ private int mTitleResId = R.string.zen_sound_title;
@Before
public void setup() {
@@ -88,8 +90,8 @@
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getZenModeConfig()).thenReturn(mZenModeConfig);
- mController =
- new ZenModeBehaviorFooterPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeBehaviorFooterPreferenceController(
+ mContext, mock(Lifecycle.class), mTitleResId);
ReflectionHelpers.setField(mController, "mZenModeConfigWrapper", mConfigWrapper);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
@@ -112,13 +114,13 @@
@Test
public void priorityOnly_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- assertFalse(mController.isAvailable());
+ assertTrue(mController.isAvailable());
}
@Test
- public void zenModeOff_footerIsNotAvailable() {
+ public void zenModeOff_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
- assertFalse(mController.isAvailable());
+ assertTrue(mController.isAvailable());
}
@Test
@@ -126,7 +128,7 @@
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
mController.updateState(mockPref);
- verify(mockPref, never()).setTitle(any(String.class));
+ verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test
@@ -134,7 +136,7 @@
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
mController.updateState(mockPref);
- verify(mockPref, never()).setTitle(any(String.class));
+ verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
new file mode 100644
index 0000000..e30fc71
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+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.Context;
+import androidx.preference.Preference;
+
+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.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorMsgEventReminderPreferenceControllerTest {
+
+ private ZenModeBehaviorMsgEventReminderPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorMsgEventReminderPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java
new file mode 100644
index 0000000..d3fab8f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+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.Context;
+import androidx.preference.Preference;
+
+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.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorSoundPreferenceControllerTest {
+
+ private ZenModeBehaviorSoundPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorSoundPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index b26989d..5b2782f 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -20,9 +20,9 @@
import static junit.framework.Assert.assertEquals;
import android.app.NotificationManager;
+import android.app.NotificationManager.Policy;
import android.content.Context;
import android.provider.SearchIndexableResource;
-import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -47,54 +47,140 @@
}
@Test
- public void testGetBehaviorSettingSummary_noSoundsCanBypass() {
- NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0);
- final String result = mBuilder.getBehaviorSettingSummary(policy,
- Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- String totalSilence = mContext.getString(R.string.zen_mode_no_exceptions);
- assertEquals(totalSilence, result);
- }
-
- @Test
- public void testGetBehaviorSettingSummary_alarmsAndMedia() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
- | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
- 0, 0);
- final String result = mBuilder.getBehaviorSettingSummary(policy,
- Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- String alarmsAndMedia = mContext.getString(R.string.join_two_items,
- mContext.getString(R.string.zen_mode_alarms),
- mContext.getString(R.string.zen_mode_media).toLowerCase());
- assertEquals(alarmsAndMedia, result);
- }
-
- @Test
public void testBlockedEffectsSummary_none() {
- NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0, 0);
+ Policy policy = new Policy(0, 0, 0, 0);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_some() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- 0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
+ Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_all() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- 0, 0, 0, 511);
+ Policy policy = new Policy(0, 0, 0, 511);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
+ public void testGetMsgEventReminderSettingSummary_none() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("None");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_single() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_EVENTS, 0 , 0 , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Events");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgs() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
+ Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
+
+ policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
+ Policy.PRIORITY_SENDERS_STARRED , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_msgs() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, 0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Messages");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgsAndOther() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Some messages and reminders");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_EVENTS
+ | Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Some messages, events, and reminders");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_noMsgsAndOther() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_EVENTS | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0,0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Events and reminders");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_none() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_contacts() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
+ Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts only");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_repeatCallers() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers only");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_starredRepeatCallers() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
+ Policy.PRIORITY_SENDERS_STARRED, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy))
+ .isEqualTo("From starred contacts and repeat callers");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOff() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOn() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
+ | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy))
+ .isEqualTo("Muted, but allow alarms, media, and touch sounds");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOffButOne() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOffButTwo() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
+ | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy))
+ .isEqualTo("Muted, but allow media and touch sounds");
+ }
+
+ @Test
public void searchProvider_shouldIndexDefaultXml() {
final List<SearchIndexableResource> sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER
.getXmlResourcesToIndex(mContext, true /* enabled */);
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java
new file mode 100644
index 0000000..9a2bccd
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import androidx.preference.Preference;
+import androidx.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.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModeStarredContactsPreferenceControllerTest {
+
+ private ZenModeStarredContactsPreferenceController mCallsController;
+ private ZenModeStarredContactsPreferenceController mMessagesController;
+
+ @Mock
+ private ZenModeBackend mBackend;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private Preference mockPref;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ @Mock
+ private Intent testIntent;
+ @Mock
+ private ComponentName mComponentName;
+ private Context mContext;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = shadowApplication.getApplicationContext();
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+ when(testIntent.resolveActivity(any())).thenReturn(mComponentName);
+
+ mCallsController = new ZenModeStarredContactsPreferenceController(
+ mContext, mock(Lifecycle.class), PRIORITY_CATEGORY_CALLS,
+ "zen_mode_starred_contacts_callers");
+ ReflectionHelpers.setField(mCallsController, "mBackend", mBackend);
+ ReflectionHelpers.setField(mCallsController, "mStarredContactsIntent", testIntent);
+ when(mPreferenceScreen.findPreference(mCallsController.getPreferenceKey()))
+ .thenReturn(mockPref);
+ mCallsController.displayPreference(mPreferenceScreen);
+
+ mMessagesController = new ZenModeStarredContactsPreferenceController(
+ mContext, mock(Lifecycle.class), PRIORITY_CATEGORY_MESSAGES,
+ "zen_mode_starred_contacts_messages");
+ ReflectionHelpers.setField(mMessagesController, "mBackend", mBackend);
+ ReflectionHelpers.setField(mMessagesController, "mStarredContactsIntent", testIntent);
+ when(mPreferenceScreen.findPreference(mMessagesController.getPreferenceKey()))
+ .thenReturn(mockPref);
+ mMessagesController.displayPreference(mPreferenceScreen);
+ }
+
+ @Test
+ public void isAvailable_noCallers() {
+ when(mBackend.isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenReturn(false);
+ assertThat(mCallsController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_anyCallers() {
+ when(mBackend.isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenReturn(true);
+ when(mBackend.getPriorityCallSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+
+
+ assertThat(mCallsController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_starredCallers() {
+ when(mBackend.isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenReturn(true);
+ when(mBackend.getPriorityCallSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+
+ assertThat(mCallsController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_noMessages() {
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)).thenReturn(false);
+ assertThat(mMessagesController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_anyMessages() {
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)).thenReturn(true);
+ when(mBackend.getPriorityMessageSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+
+ assertThat(mMessagesController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_starredMessageContacts() {
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)).thenReturn(true);
+ when(mBackend.getPriorityMessageSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+
+ assertThat(mMessagesController.isAvailable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceControllerTest.java
index 5de7697..f3d92d1 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceControllerTest.java
@@ -150,18 +150,4 @@
verify(mockPref).setOnGearClickListener(any());
verify(mockPref).setOnRadioButtonClickListener(any());
}
-
- @Test
- public void select() {
- int interruptiveSuppressed = SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
- | SUPPRESSED_EFFECT_AMBIENT
- | SUPPRESSED_EFFECT_LIGHTS
- | SUPPRESSED_EFFECT_PEEK;
- mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
- mController.select();
- verify(mBackend).savePolicy(anyInt(), anyInt(), anyInt(), eq(interruptiveSuppressed));
- verify(mFeatureFactory.metricsFeatureProvider).action(eq(mContext),
- eq(ACTION_ZEN_CUSTOM),
- eq(true));
- }
}
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index 0fda33e..a0bd33a 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -18,20 +18,17 @@
package com.android.settings.slices;
import static android.content.ContentResolver.SCHEME_CONTENT;
-
import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.slice.SliceManager;
-import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
+import android.os.StrictMode;
import android.provider.SettingsSlicesContract;
import com.android.settings.testutils.DatabaseTestUtils;
@@ -44,29 +41,30 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
-import androidx.slice.Slice;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import androidx.slice.Slice;
+
/**
* TODO Investigate using ShadowContentResolver.registerProviderInternal(String, ContentProvider)
*/
@RunWith(SettingsRobolectricTestRunner.class)
public class SettingsSliceProviderTest {
- private final String KEY = "KEY";
- private final String INTENT_PATH = SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY;
- private final String ACTION_PATH = SettingsSlicesContract.PATH_SETTING_ACTION + "/" + KEY;
- private final String TITLE = "title";
- private final String SUMMARY = "summary";
- private final String SCREEN_TITLE = "screen title";
- private final String FRAGMENT_NAME = "fragment name";
- private final int ICON = 1234; // I declare a thumb war
- private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
- private final String PREF_CONTROLLER = FakeToggleController.class.getName();
+ private static final String KEY = "KEY";
+ private static final String INTENT_PATH =
+ SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY;
+ private static final String TITLE = "title";
+ private static final String SUMMARY = "summary";
+ private static final String SCREEN_TITLE = "screen title";
+ private static final String FRAGMENT_NAME = "fragment name";
+ private static final int ICON = 1234; // I declare a thumb war
+ private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
+ private static final String PREF_CONTROLLER = FakeToggleController.class.getName();
+
private Context mContext;
private SettingsSliceProvider mProvider;
private SQLiteDatabase mDb;
@@ -152,6 +150,18 @@
}
@Test
+ public void onBindSlice_shouldNotOverrideStrictMode() {
+ final StrictMode.ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
+ SliceData data = getDummyData();
+ mProvider.mSliceWeakDataCache.put(data.getUri(), data);
+ mProvider.onBindSlice(data.getUri());
+
+ final StrictMode.ThreadPolicy newThreadPolicy = StrictMode.getThreadPolicy();
+
+ assertThat(newThreadPolicy.toString()).isEqualTo(oldThreadPolicy.toString());
+ }
+
+ @Test
public void testLoadSlice_cachedEntryRemovedOnUnpin() {
SliceData data = getDummyData();
mProvider.mSliceDataCache.put(data.getUri(), data);
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
index 88a0fb6..3c37145 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowAudioManager.java
@@ -42,7 +42,8 @@
public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManager {
private int mRingerMode;
private int mDeviceCodes;
- private boolean mMusicActiveRemotely = false;
+ private boolean mMusicActiveRemotely;
+ private boolean mBluetoothScoOn;
private ArrayList<AudioDeviceCallback> mDeviceCallbacks = new ArrayList();
@Implementation
@@ -104,4 +105,11 @@
public void reset() {
mDeviceCallbacks.clear();
}
+
+ public void setBluetoothScoOn(boolean bluetoothScoOn) {
+ mBluetoothScoOn = bluetoothScoOn;
+ }
+
+ @Implementation
+ public boolean isBluetoothScoOn() { return mBluetoothScoOn; }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPowerWhitelistBackend.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPowerWhitelistBackend.java
new file mode 100644
index 0000000..4500b23
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowPowerWhitelistBackend.java
@@ -0,0 +1,28 @@
+/*
+ * 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.testutils.shadow;
+
+import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
+
+import org.robolectric.annotation.Implements;
+
+@Implements(PowerWhitelistBackend.class)
+public class ShadowPowerWhitelistBackend {
+ public void __constructor__() {
+ // Do nothing
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictedLockUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictedLockUtils.java
index 30e6401..c6197e7 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictedLockUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictedLockUtils.java
@@ -89,6 +89,18 @@
return (sKeyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
}
+ @Implementation
+ public static boolean hasBaseUserRestriction(Context context,
+ String userRestriction, int userId) {
+ return sIsRestricted;
+ }
+
+ @Implementation
+ public static EnforcedAdmin checkIfRestrictionEnforced(Context context,
+ String userRestriction, int userId) {
+ return sIsRestricted ? new EnforcedAdmin() : null;
+ }
+
public static boolean hasAdminSupportDetailsIntentLaunched() {
return sAdminSupportDetailsIntentLaunched;
}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
index 66cbd30..75c9bb1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiEnablerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.wifi;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -25,6 +27,7 @@
import android.net.wifi.WifiManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
import com.android.settings.widget.SwitchWidgetController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -33,8 +36,10 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = ShadowRestrictedLockUtils.class)
public class WifiEnablerTest {
@Mock
@@ -59,8 +64,6 @@
when(mWifiManager.setWifiEnabled(true)).thenReturn(true);
when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_ENABLED);
- mEnabler.onSwitchToggled(true);
-
- verify(mConnectivityManager).stopTethering(ConnectivityManager.TETHERING_WIFI);
+ assertThat(mEnabler.onSwitchToggled(true)).isTrue();
}
}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
index ecf7206..57ecfd0 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
@@ -36,6 +36,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -48,6 +49,7 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = ShadowRestrictedLockUtils.class)
public class WifiMasterSwitchPreferenceControllerTest {
@Mock
diff --git a/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java b/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
index f42dbd1..5655213 100644
--- a/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/display/ThemePreferenceControllerTest.java
@@ -69,9 +69,9 @@
@Test
public void testUpdateState() throws Exception {
OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android",
- "", "", OverlayInfo.STATE_ENABLED, 0);
+ "", "", OverlayInfo.STATE_ENABLED, 0, 0, true);
OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android",
- "", "", 0, 0);
+ "", "", 0, 0, 0, true);
when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
ApplicationInfo info = mock(ApplicationInfo.class);
if ("com.android.Theme1".equals(inv.getArguments()[0])) {
@@ -105,9 +105,9 @@
@Test
public void testUpdateState_withStaticOverlay() throws Exception {
OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android",
- "", "", OverlayInfo.STATE_ENABLED, 0);
+ "", "", OverlayInfo.STATE_ENABLED, 0, 0, true);
OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android",
- "", "", OverlayInfo.STATE_ENABLED, 0);
+ "", "", OverlayInfo.STATE_ENABLED, 0, 0, true);
when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
ApplicationInfo info = mock(ApplicationInfo.class);
if ("com.android.Theme1".equals(inv.getArguments()[0])) {
@@ -145,7 +145,7 @@
when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(
new PackageInfo());
when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt()))
- .thenReturn(list(new OverlayInfo("", "", "", "", 0, 0)));
+ .thenReturn(list(new OverlayInfo("", "", "", "", 0, 0, 0, false)));
assertThat(mPreferenceController.isAvailable()).isFalse();
}
@@ -154,8 +154,8 @@
when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(
new PackageInfo());
when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt()))
- .thenReturn(list(new OverlayInfo("", "", "", "", 0, 0),
- new OverlayInfo("", "", "", "", 0, 0)));
+ .thenReturn(list(new OverlayInfo("", "", "", "", 0, 0, 0, true),
+ new OverlayInfo("", "", "", "", 0, 0, 0, true)));
assertThat(mPreferenceController.isAvailable()).isTrue();
}
diff --git a/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java b/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java
new file mode 100644
index 0000000..e7c5d6e
--- /dev/null
+++ b/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.slices;
+
+import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepLink;
+
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class SliceDeepLinkSpringBoardTest {
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getTargetContext();
+ }
+
+ @Test
+ public void launcheDeepLinkIntent_shouldNotCrash() {
+ final Uri springBoardIntentUri = createDeepLink(
+ new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE)
+ .setPackage(mContext.getPackageName())
+ .putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE,
+ "content://com.android.settings.slices/action/test_slice")
+ .toUri(Intent.URI_ANDROID_APP_SCHEME));
+
+ final Intent deepLinkIntent = new Intent(Intent.ACTION_VIEW)
+ .setData(springBoardIntentUri)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ mContext.startActivity(deepLinkIntent);
+ }
+}