Snap for 4778411 from 34b1805053 to qt-release

Change-Id: I597ed1f2aa43d330c3e57430799ad6cc93deefb4
This commit is contained in:
android-build-team Robot
2018-05-12 09:32:31 +00:00
77 changed files with 2029 additions and 625 deletions

View File

@@ -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" />
@@ -752,23 +756,6 @@
</intent-filter>
</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"

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"

View File

@@ -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"

View File

@@ -35,7 +35,4 @@
<!-- Display, Screen zoom -->
<dimen name="screen_zoom_preview_height">160dp</dimen>
<!-- Gestures -->
<dimen name="gesture_animation_padding">35dp</dimen>
</resources>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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,8 +415,8 @@
<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]-->
@@ -847,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 -->
@@ -2643,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. -->
@@ -4633,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 &amp; notification set to off</string>
@@ -7227,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 &amp; 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 &amp; 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] -->
@@ -7364,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 &amp; 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 &amp; 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]-->
@@ -7895,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>
@@ -7913,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>
@@ -7932,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>
@@ -8653,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>
@@ -9808,6 +9873,9 @@
<!-- 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>

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"

View File

@@ -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 -->

View File

@@ -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>

View File

@@ -127,9 +127,9 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
* 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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
}
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 @@ public final class CredentialStorage extends Activity {
}
}
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 @@ public final class CredentialStorage extends Activity {
}
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 @@ public final class CredentialStorage extends Activity {
}
// 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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
}
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 @@ public final class CredentialStorage extends Activity {
private class MarkKeyAsUserSelectable extends AsyncTask<Void, Void, Boolean> {
final String mAlias;
public MarkKeyAsUserSelectable(String alias) {
MarkKeyAsUserSelectable(String alias) {
mAlias = alias;
}
@@ -440,7 +439,7 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
* 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 @@ public final class CredentialStorage extends Activity {
*/
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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
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 @@ public final class CredentialStorage extends Activity {
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,

View File

@@ -33,6 +33,7 @@ import android.os.UserHandle;
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 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
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) {

View File

@@ -77,16 +77,19 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
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 "";
}

View File

@@ -549,7 +549,7 @@ public class ManageApplications extends InstrumentedFragment
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);

View File

@@ -16,11 +16,11 @@
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 com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -57,18 +57,20 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
}
@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);
}
}

View File

@@ -161,6 +161,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
public void onAudioModeChanged() {
}
@Override
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) {
}
@Override
public void onServiceConnected() {
// When bluetooth service connected update the UI

View File

@@ -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 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
}
@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);
}
}

View File

@@ -15,8 +15,8 @@
*/
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;
@@ -43,10 +43,11 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
}
@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);
}
}

View File

@@ -187,6 +187,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
public final boolean isAvailable() {
final int availabilityStatus = getAvailabilityStatus();
return (availabilityStatus == AVAILABLE
|| availabilityStatus == AVAILABLE_UNSEARCHABLE
|| availabilityStatus == DISABLED_DEPENDENT_SETTING);
}
@@ -230,16 +231,15 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
* 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);
}
}

View File

@@ -106,9 +106,10 @@ import com.android.settings.notification.NotificationStation;
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 @@ public class SettingsGateway {
ApnSettings.class.getName(),
ApnEditor.class.getName(),
WifiCallingSettings.class.getName(),
ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
ZenModeBlockedEffectsSettings.class.getName(),

View File

@@ -100,7 +100,7 @@ public class DashboardFragmentRegistry {
PARENT_TO_CATEGORY_KEY_MAP.put(GestureSettings.class.getName(),
CategoryKey.CATEGORY_GESTURES);
PARENT_TO_CATEGORY_KEY_MAP.put(NightDisplaySettings.class.getName(),
CategoryKey.CATEGORY_NIGHT_LIGHT);
CategoryKey.CATEGORY_NIGHT_DISPLAY);
CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());

View File

@@ -21,9 +21,15 @@ import android.content.Context;
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 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
* 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 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
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);
}
}
}

View File

@@ -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 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
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 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
@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 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
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 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
: 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());

View File

@@ -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.core.AbstractPreferenceController;
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 @@ public class PowerUsageAdvanced extends PowerUsageBase {
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 @@ public class PowerUsageAdvanced extends PowerUsageBase {
}
@Override
protected void refreshUi() {
protected void refreshUi(@BatteryUpdateType int refreshType) {
final Context context = getContext();
if (context == null) {
return;

View File

@@ -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 android.view.Menu;
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 @@ public abstract class PowerUsageBase extends DashboardFragment
setHasOptionsMenu(true);
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
restartBatteryStatsLoader();
mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
restartBatteryStatsLoader(type);
});
}
@@ -81,11 +82,14 @@ public abstract class PowerUsageBase extends DashboardFragment
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 @@ public abstract class PowerUsageBase extends DashboardFragment
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) {
}
}
}

View File

@@ -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 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
} else {
mStatsType = BatteryStats.STATS_SINCE_CHARGED;
}
refreshUi();
refreshUi(BatteryUpdateType.MANUAL);
return true;
case MENU_ADVANCED_BATTERY:
new SubSettingLauncher(getContext())
@@ -293,14 +295,15 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
}
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 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
@Override
protected void restartBatteryStatsLoader() {
restartBatteryStatsLoader(true /* clearHeader */);
protected void restartBatteryStatsLoader(@BatteryUpdateType int refreshType) {
super.restartBatteryStatsLoader(refreshType);
mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
}
@Override
@@ -409,13 +413,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
mBatteryTipPreferenceController.saveInstanceState(outState);
}
void restartBatteryStatsLoader(boolean clearHeader) {
super.restartBatteryStatsLoader();
if (clearHeader) {
mBatteryHeaderPreferenceController.quickUpdateHeaderPreference();
}
}
@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
restartBatteryTipLoader();
@@ -430,7 +427,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
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) {

View File

@@ -120,6 +120,11 @@ public class RestrictedAppDetails extends DashboardFragment {
return MetricsProto.MetricsEvent.FUELGAUGE_RESTRICTED_APP_DETAILS;
}
@Override
public int getHelpResource() {
return R.string.help_uri_restricted_apps;
}
@VisibleForTesting
void refreshUi() {
mRestrictedAppListGroup.removeAll();

View File

@@ -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;
}
}

View File

@@ -153,6 +153,7 @@ public class SoundSettings extends DashboardFragment {
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);

View File

@@ -83,7 +83,9 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
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 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
@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);

View File

@@ -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 @@ public class ZenModeBackend {
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) {

View File

@@ -22,13 +22,13 @@ import androidx.preference.Preference;
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 class ZenModeBehaviorPreferenceController extends
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
getZenMode()));
preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
}
}

View File

@@ -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 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
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 @@ public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePr
@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) {

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorMsgEventReminderPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBehaviorMsgEventReminderPreferenceController(Context context,
Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
return KEY_BEHAVIOR_SETTINGS;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy()));
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorSoundPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
return KEY_BEHAVIOR_SETTINGS;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy()));
}
}

View File

@@ -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 android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable
public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
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, R.string.zen_mode_calls_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_calls_settings;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_calls_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null);
}
};
}

View File

@@ -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.ArrayList;
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 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
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 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
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;
}

View File

@@ -70,7 +70,6 @@ public class ZenModeRestrictNotificationsSettings extends ZenModeSettingsBase im
custom.displayPreference(getPreferenceScreen());
if (mShowMenuSelected) {
custom.select();
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, true);
} else {
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, false);

View File

@@ -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.Arrays;
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 @@ public class ZenModeSettings extends ZenModeSettingsBase {
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 @@ public class ZenModeSettings extends ZenModeSettingsBase {
// 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 @@ public class ZenModeSettings extends ZenModeSettingsBase {
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 @@ public class ZenModeSettings extends ZenModeSettingsBase {
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 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private boolean isCategoryEnabled(Policy policy, int categoryType) {
return (policy.priorityCategories & categoryType) != 0;
}
private boolean isEffectSuppressed(Policy policy, int effect) {
return (policy.suppressedVisualEffects & effect) != 0;
}
}
/**

View File

@@ -0,0 +1,90 @@
/*
* 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.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable
public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
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 ZenModeBehaviorFooterPreferenceController(context, lifecycle,
R.string.zen_sound_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_sound_vibration_settings;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_sound_vibration_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null);
}
};
}

View File

@@ -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;
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.notification;
import android.app.NotificationManager.Policy;
import android.content.Context;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -57,15 +58,12 @@ public class ZenModeVisEffectsCustomPreferenceController
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 @@ public class ZenModeVisEffectsCustomPreferenceController
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();
}
}

View File

@@ -21,7 +21,6 @@ import android.os.UserHandle;
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 @@ public class LockdownButtonPreferenceController extends TogglePreferenceControll
@Override
public int getAvailabilityStatus() {
if (mLockPatternUtils.isSecure(UserHandle.myUserId())) {
return BasePreferenceController.AVAILABLE;
return AVAILABLE;
} else {
return BasePreferenceController.DISABLED_FOR_USER;
return DISABLED_FOR_USER;
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.security;
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.ArrayList;
import java.util.Arrays;
import java.util.List;
import androidx.annotation.VisibleForTesting;
/**
* Settings screen for lock screen preference
*/

View File

@@ -27,9 +27,7 @@ import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiManager;
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;
@@ -45,6 +43,8 @@ import java.util.Map;
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;

View File

@@ -161,7 +161,6 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
*/
@Override
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
updateState(mPreference);
}
@Override
@@ -174,6 +173,12 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
updateState(mPreference);
}
@Override
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) {
updateState(mPreference);
}
@Override
public void onBluetoothStateChanged(int bluetoothState) {
}

View File

@@ -18,7 +18,15 @@ package com.android.settings.accessibility;
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 com.android.settings.testutils.XmlTestUtils;
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 @@ public class AccessibilitySettingsTest {
assertThat(keys).containsAllIn(niks);
}
}
@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));
}
}

View File

@@ -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;
@@ -150,60 +150,61 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
}
@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);
}

View File

@@ -155,6 +155,11 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
return true;
}
@Override
public int getProfileId() {
return 0;
}
@Override
public int getOrdinal() {
return 0;

View File

@@ -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.spy;
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 @@ public class ConnectedBluetoothDeviceUpdaterTest {
private Collection<CachedBluetoothDevice> cachedDevices;
private ShadowAudioManager mShadowAudioManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -151,60 +153,61 @@ public class ConnectedBluetoothDeviceUpdaterTest {
}
@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);
}

View File

@@ -22,7 +22,7 @@ import static org.mockito.Mockito.spy;
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;
@@ -76,7 +76,7 @@ public class SavedBluetoothDeviceUpdaterTest {
}
@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 +86,7 @@ public class SavedBluetoothDeviceUpdaterTest {
}
@Test
public void testUpdate_filterNotMatch_removePreference() {
public void update_filterNotMatch_removePreference() {
doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
doReturn(true).when(mBluetoothDevice).isConnected();
@@ -96,17 +96,17 @@ public class SavedBluetoothDeviceUpdaterTest {
}
@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);
}

View File

@@ -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.Test;
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)
@@ -72,6 +74,13 @@ public class BasePreferenceControllerTest {
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@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 @@ public class BasePreferenceControllerTest {
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;

View File

@@ -48,8 +48,8 @@ public class NightDisplaySettingsTest {
}
@Test
public void getCategoryKey_isCategoryNightLight() {
public void getCategoryKey_isCategoryNightDisplay() {
NightDisplaySettings settings = new NightDisplaySettings();
assertThat(settings.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_NIGHT_LIGHT);
assertThat(settings.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_NIGHT_DISPLAY);
}
}

View File

@@ -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 @@ public class BatteryBroadcastReceiverTest {
}
@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 @@ public class BatteryBroadcastReceiverTest {
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 @@ public class BatteryBroadcastReceiverTest {
assertThat(mBatteryBroadcastReceiver.mBatteryLevel).isEqualTo(batteryLevel);
assertThat(mBatteryBroadcastReceiver.mBatteryStatus).isEqualTo(batteryStatus);
verify(mBatteryListener, never()).onBatteryChanged();
verify(mBatteryListener, never()).onBatteryChanged(anyInt());
}
@Test
@@ -115,6 +118,6 @@ public class BatteryBroadcastReceiverTest {
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);
}
}

View File

@@ -18,27 +18,49 @@ package com.android.settings.fuelgauge;
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 @@ public class HighPowerDetailTest {
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);
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
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 @@ public class PowerUsageAdvancedTest {
@Test
public void testOptionsMenu_menuAppToggle_metricEventInvoked() {
mFragment.mShowAllApps = false;
doNothing().when(mFragment).restartBatteryStatsLoader();
doNothing().when(mFragment).restartBatteryStatsLoader(anyInt());
mFragment.onOptionsItemSelected(mToggleAppsMenu);

View File

@@ -74,7 +74,7 @@ public class PowerUsageBaseTest {
}
@Override
protected void refreshUi() {
protected void refreshUi(int refreshType) {
// Do nothing
}

View File

@@ -149,7 +149,7 @@ public class PowerUsageSummaryTest {
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();
@@ -316,15 +316,6 @@ public class PowerUsageSummaryTest {
verify(mSummary1, times(2)).setOnLongClickListener(any(View.OnLongClickListener.class));
}
@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())
@@ -360,7 +351,18 @@ public class PowerUsageSummaryTest {
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 @@ public class PowerUsageSummaryTest {
when(mFragment.mBatteryTipPreferenceController.needUpdate()).thenReturn(true);
mFragment.updateBatteryTipFlag(new Bundle());
mFragment.refreshUi();
mFragment.refreshUi(BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
verify(mFragment).restartBatteryTipLoader();
}

View File

@@ -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);
}
}

View File

@@ -50,17 +50,20 @@ public class VolumeSeekBarPreferenceTest {
}
@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);
}
}

View File

@@ -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());
}
}

View File

@@ -41,6 +41,7 @@ import androidx.preference.Preference;
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 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
private Context mContext;
private ContentResolver mContentResolver;
private int mTitleResId = R.string.zen_sound_title;
@Before
public void setup() {
@@ -88,8 +90,8 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
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 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
@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 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
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 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
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

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
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;
@@ -46,54 +46,140 @@ public class ZenModeSettingsTest {
mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
}
@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

View File

@@ -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();
}
}

View File

@@ -150,18 +150,4 @@ public class ZenModeVisEffectsCustomPreferenceControllerTest {
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));
}
}

View File

@@ -42,7 +42,8 @@ import java.util.ArrayList;
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 class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManag
public void reset() {
mDeviceCallbacks.clear();
}
public void setBluetoothScoOn(boolean bluetoothScoOn) {
mBluetoothScoOn = bluetoothScoOn;
}
@Implementation
public boolean isBluetoothScoOn() { return mBluetoothScoOn; }
}

View File

@@ -69,9 +69,9 @@ public class ThemePreferenceControllerTest {
@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 @@ public class ThemePreferenceControllerTest {
@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 @@ public class ThemePreferenceControllerTest {
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 @@ public class ThemePreferenceControllerTest {
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();
}