Merge "Use setVisible instead of removePreference everywhere."
diff --git a/res/layout/dialog_hardware_info.xml b/res/layout/dialog_hardware_info.xml
index 9431961..7ea4783 100644
--- a/res/layout/dialog_hardware_info.xml
+++ b/res/layout/dialog_hardware_info.xml
@@ -26,46 +26,40 @@
android:padding="24dp">
<TextView
+ style="@style/device_info_dialog_label"
android:id="@+id/model_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"
android:text="@string/model_info" />
<TextView
+ style="@style/device_info_dialog_value"
android:id="@+id/model_value"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="24dp"
- android:textAppearance="@android:style/TextAppearance.Material.Body2" />
+ android:layout_height="wrap_content" />
<TextView
+ style="@style/device_info_dialog_label"
android:id="@+id/serial_number_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"
android:text="@string/status_serial_number" />
<TextView
+ style="@style/device_info_dialog_value"
android:id="@+id/serial_number_value"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="24dp"
- android:textAppearance="@android:style/TextAppearance.Material.Body2" />
+ android:layout_height="wrap_content" />
<TextView
+ style="@style/device_info_dialog_label"
android:id="@+id/hardware_rev_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:textColor="?android:attr/textColorSecondary"
android:text="@string/hardware_revision" />
<TextView
+ style="@style/device_info_dialog_value"
android:id="@+id/hardware_rev_value"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="24dp"
- android:textAppearance="@android:style/TextAppearance.Material.Body2" />
+ android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
diff --git a/res/values-ar/arrays.xml b/res/values-ar/arrays.xml
index 69be316..311e5d4 100644
--- a/res/values-ar/arrays.xml
+++ b/res/values-ar/arrays.xml
@@ -217,7 +217,7 @@
<item msgid="7471182818083460781">"IS95A"</item>
</string-array>
<string-array name="mvno_type_entries">
- <item msgid="4367119357633573465">"None"</item>
+ <item msgid="4367119357633573465">"بدون"</item>
<item msgid="6062567900587138000">"SPN"</item>
<item msgid="2454085083342423481">"IMSI"</item>
<item msgid="2681427309183221543">"GID"</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4582bc4..d1920a6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1572,9 +1572,9 @@
<!-- Bluetooth settings. Message for disconnecting from the PAN profile (user role). [CHAR LIMIT=80] -->
<string name="bluetooth_disconnect_pan_user_profile">Internet access via <xliff:g id="device_name">%1$s</xliff:g> will be disconnected.</string>
<!-- Bluetooth settings. Message for disconnecting from the PAN profile (NAP role). [CHAR LIMIT=80] -->
- <string name="bluetooth_disconnect_pan_nap_profile" product="tablet"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from sharing this tablet\u2019s Internet connection.</string>
+ <string name="bluetooth_disconnect_pan_nap_profile" product="tablet"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from sharing this tablet\u2019s internet connection.</string>
<!-- Bluetooth settings. Message for disconnecting from the PAN profile (NAP role). [CHAR LIMIT=80] -->
- <string name="bluetooth_disconnect_pan_nap_profile" product="default"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from sharing this phone\u2019s Internet connection.</string>
+ <string name="bluetooth_disconnect_pan_nap_profile" product="default"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from sharing this phone\u2019s internet connection.</string>
<!-- Bluetooth settings. Connection options screen. The title of the screen. [CHAR LIMIT=40] -->
<string name="bluetooth_device_advanced_title">Paired Bluetooth device</string>
@@ -1590,9 +1590,9 @@
<!-- Bluetooth settings. Connection options screen. Title for checkbox to enable incoming file transfers [CHAR LIMIT=30] -->
<string name="bluetooth_device_advanced_enable_opp_title">Allow incoming file transfers</string>
<!-- Bluetooth settings. Connection options screen. The summary for the checkbox preference when PAN is connected (user role). [CHAR LIMIT=25]-->
- <string name="bluetooth_pan_user_profile_summary_connected">Connected to device for Internet access</string>
+ <string name="bluetooth_pan_user_profile_summary_connected">Connected to device for internet access</string>
<!-- Bluetooth settings. Connection options screen. The summary for the checkbox preference when PAN is connected (NAP role). [CHAR LIMIT=25]-->
- <string name="bluetooth_pan_nap_profile_summary_connected">Sharing local Internet connection with device</string>
+ <string name="bluetooth_pan_nap_profile_summary_connected">Sharing local internet connection with device</string>
<!-- Bluetooth settings. Dock Setting Title -->
<string name="bluetooth_dock_settings">Dock Settings</string>
@@ -1726,9 +1726,9 @@
<!-- Checkbox title for option to toggle poor network detection -->
<string name="wifi_poor_network_detection">Avoid poor connections</string>
<!-- Checkbox summary for option to toggle poor network detection -->
- <string name="wifi_poor_network_detection_summary">Don\u2019t use a Wi\u2011Fi network unless it has a good Internet connection</string>
+ <string name="wifi_poor_network_detection_summary">Don\u2019t use a Wi\u2011Fi network unless it has a good internet connection</string>
<!-- Checkbox summary for option to toggle poor network detection [CHAR LIMIT=60] -->
- <string name="wifi_avoid_poor_network_detection_summary">Only use networks that have a good Internet connection</string>
+ <string name="wifi_avoid_poor_network_detection_summary">Only use networks that have a good internet connection</string>
<!-- Checkbox title for option to connect to open Wi-Fi automatically [CHAR LIMIT=40] -->
<string name="use_open_wifi_automatically_title">Connect to open networks</string>
<!-- Checkbox summary for option to connect to open Wi-Fi automatically [CHAR LIMIT=100] -->
@@ -1770,11 +1770,11 @@
<!-- Checkbox summary for option to toggle suspend power optimizations [CHAR LIMIT=30] -->
<string name="wifi_limit_optimizations_summary">Limit battery used by Wi\u2011Fi</string>
<!-- Checkbox title. Should we switch to using cellular data if Wi-Fi is still connected but the Wi-Fi network we're connected to no longer has Internet access (e.g., due to an outage)? -->
- <string name="wifi_switch_away_when_unvalidated">Switch to mobile data if Wi\u2011Fi loses Internet access.</string>
+ <string name="wifi_switch_away_when_unvalidated">Switch to mobile data if Wi\u2011Fi loses internet access.</string>
<!-- Preference title for option to automatically switch away from bad wifi networks [CHAR LIMIT=60]-->
<string name="wifi_cellular_data_fallback_title">Switch to mobile data automatically</string>
<!-- Preference summary to automatically switch away from bad wifi networks [CHAR LIMIT=None]-->
- <string name="wifi_cellular_data_fallback_summary">Use mobile data when Wi\u2011Fi has no Internet access. Data usage may apply.</string>
+ <string name="wifi_cellular_data_fallback_summary">Use mobile data when Wi\u2011Fi has no internet access. Data usage charges may apply.</string>
<!-- Action bar text message to manually add a wifi network [CHAR LIMIT=20]-->
<string name="wifi_add_network">Add network</string>
<!-- Action bar title to open additional Wi-Fi settings-->
@@ -1948,11 +1948,11 @@
<string name="wifi_hotspot_connect">CONNECT</string>
<!-- Dialog text to tell the user that the selected network does not have Internet access. -->
- <string name="no_internet_access_text">This network has no Internet access. Stay connected?</string>
+ <string name="no_internet_access_text">This network has no internet access. Stay connected?</string>
<string name="no_internet_access_remember">Don\u2019t ask again for this network</string>
<!-- Dialog text to tell the user that the selected network has lost Internet access, and asking the user whether they want to avoid this network. -->
- <string name="lost_internet_access_title">Wi\u2011Fi is not connected to the Internet</string>
+ <string name="lost_internet_access_title">Wi\u2011Fi is not connected to the internet</string>
<string name="lost_internet_access_text">You can switch to the mobile network whenever Wi\u2011Fi has a bad connection. Data usage charges may apply.</string>
<!-- Button text to let user switch to mobile data -->
<string name="lost_internet_access_switch">Switch to mobile</string>
@@ -1994,7 +1994,7 @@
<!-- Wifi Network Details -->
<!-- Wifi details title-->
- <string name="wifi_details_title">Network info</string>
+ <string name="wifi_details_title">Network details</string>
<!-- Wifi details preference title to display router IP subnet mask -->
<string name="wifi_details_subnet_mask">Subnet mask</string>
<!-- Wifi details preference title to display router DNS info -->
@@ -2065,13 +2065,13 @@
<!-- Label for Wifi tether checkbox. Toggles Access Point on/off [CHAR LIMIT=30] -->
<string name="wifi_hotspot_checkbox_text">Wi\u2011Fi hotspot</string>
<!-- Summary text when turning hotspot off -->
- <string name="wifi_hotspot_off_subtext">Not sharing Internet or content with other devices</string>
+ <string name="wifi_hotspot_off_subtext">Not sharing internet or content with other devices</string>
<!-- Summary text when tethering is on -->
- <string name="wifi_hotspot_tethering_on_subtext" product="tablet">Sharing this tablet\u2019s Internet connection via hotspot</string>
+ <string name="wifi_hotspot_tethering_on_subtext" product="tablet">Sharing this tablet\u2019s internet connection via hotspot</string>
<!-- Summary text when tethering is on -->
- <string name="wifi_hotspot_tethering_on_subtext" product="default">Sharing this phone\u2019s Internet connection via hotspot</string>
+ <string name="wifi_hotspot_tethering_on_subtext" product="default">Sharing this phone\u2019s internet connection via hotspot</string>
<!-- Summary text when hotspot is on for local-only -->
- <string name="wifi_hotspot_on_local_only_subtext">App is sharing content. To share Internet connection, turn hotspot off, then on</string>
+ <string name="wifi_hotspot_on_local_only_subtext">App is sharing content. To share internet connection, turn hotspot off, then on</string>
<!-- Wifi hotspot settings -->
<!-- Label for Wifi hotspot name. -->
@@ -2085,7 +2085,7 @@
<!-- Label for Wifi hotspot AP Band. -->
<string name="wifi_hotspot_ap_band_title">AP Band</string>
<!-- Wifi hotspot footer info for regular hotspot [CHAR LIMIT=NONE]-->
- <string name="wifi_hotspot_footer_info_regular">Use hotspot to create a Wi\u2011Fi network for your other devices. Hotspot provides Internet using your mobile data connection. Additional mobile data charges may apply.</string>
+ <string name="wifi_hotspot_footer_info_regular">Use hotspot to create a Wi\u2011Fi network for your other devices. Hotspot provides internet using your mobile data connection. Additional mobile data charges may apply.</string>
<!-- Wifi hotspot footer info [CHAR LIMIT=NONE]-->
<string name="wifi_hotspot_footer_info_local_only">Apps can create a hotspot to share content with nearby devices.</string>
@@ -2949,7 +2949,7 @@
<string name="storage_detail_explore">Explore <xliff:g id="name" example="SD card">^1</xliff:g></string>
<!-- Body of dialog informing user about other files on a storage device [CHAR LIMIT=NONE]-->
- <string name="storage_detail_dialog_other">Other includes shared files saved by apps, files downloaded from the Internet or Bluetooth, Android files, and so on.
+ <string name="storage_detail_dialog_other">Other includes shared files saved by apps, files downloaded from the internet or Bluetooth, Android files, and so on.
\n\nTo see the visible contents of this <xliff:g id="name" example="SD card">^1</xliff:g>, tap Explore.</string>
<!-- Body of dialog informing user about the storage used by the Android System [CHAR LIMIT=NONE]-->
@@ -3252,25 +3252,25 @@
<!-- USB Tethering options -->
<string name="usb_title">USB</string>
<string name="usb_tethering_button_text">USB tethering</string>
- <string name="usb_tethering_subtext" product="default">Share phone\u2019s Internet connection via USB</string>
- <string name="usb_tethering_subtext" product="tablet">Share tablet\u2019s Internet connection via USB</string>
+ <string name="usb_tethering_subtext" product="default">Share phone\u2019s internet connection via USB</string>
+ <string name="usb_tethering_subtext" product="tablet">Share tablet\u2019s internet connection via USB</string>
<!-- Bluetooth Tethering settings-->
<!-- Label for bluetooth tether checkbox [CHAR LIMIT=25]-->
<string name="bluetooth_tether_checkbox_text">Bluetooth tethering</string>
<!-- Bluetooth Tethering subtext [CHAR LIMIT=70]-->
- <string name="bluetooth_tethering_subtext" product="tablet">Share tablet\u2019s Internet connection via Bluetooth</string>
+ <string name="bluetooth_tethering_subtext" product="tablet">Share tablet\u2019s internet connection via Bluetooth</string>
<!-- Bluetooth Tethering subtext [CHAR LIMIT=70]-->
- <string name="bluetooth_tethering_subtext" product="default">Share phone\u2019s Internet connection via Bluetooth</string>
+ <string name="bluetooth_tethering_subtext" product="default">Share phone\u2019s internet connection via Bluetooth</string>
<!-- Bluetooth tethering off subtext - shown when Bluetooth Tethering is turned off [CHAR LIMIT=80]-->
- <string name="bluetooth_tethering_off_subtext_config">Sharing this <xliff:g id="device_name">%1$d</xliff:g>\u2019s Internet connection via Bluetooth</string>
+ <string name="bluetooth_tethering_off_subtext_config">Sharing this <xliff:g id="device_name">%1$d</xliff:g>\u2019s internet connection via Bluetooth</string>
<!-- Bluetooth Tethering settings. Error message shown when trying to connect an 8th device [CHAR LIMIT=50]-->
<string name="bluetooth_tethering_overflow_error">Can\u2019t tether to more than <xliff:g id="maxConnection">%1$d</xliff:g> devices.</string>
<!-- Bluetooth Tethering settings. Message for untethering from a bluetooth device [CHAR LIMIT=50]-->
<string name="bluetooth_untether_blank"><xliff:g id="device_name">%1$s</xliff:g> will be untethered.</string>
<!-- Tethering footer info [CHAR LIMIT=NONE]-->
- <string name="tethering_footer_info">Use hotspot and tethering to provide Internet to other devices through your mobile data connection. Apps can also create a hotspot to share content with nearby devices.</string>
+ <string name="tethering_footer_info">Use hotspot and tethering to provide internet to other devices through your mobile data connection. Apps can also create a hotspot to share content with nearby devices.</string>
<!-- Tethering help button - calls up a web view with general tethering info -->
<string name="tethering_help_button_text">Help</string>
@@ -3442,7 +3442,7 @@
<!-- About phone settings, Safety Legal information setting option name and title of dialog box holding safety legal info -->
<string name="settings_safetylegal_activity_title">Safety information</string>
<!-- About phone settings screen, Safety legal dialog message when data network is not connected -->
- <string name="settings_safetylegal_activity_unreachable">You don\u2019t have a data connection. To view this information now, go to %s from any computer connected to the Internet.</string>
+ <string name="settings_safetylegal_activity_unreachable">You don\u2019t have a data connection. To view this information now, go to %s from any computer connected to the internet.</string>
<!-- About phone settings screen, Safety Legal dialog title until the link is fully loaded -->
<string name="settings_safetylegal_activity_loading">Loading\u2026</string>
@@ -5861,9 +5861,9 @@
<!-- Dialog message title to set always-on VPN when another app was not already set. -->
<string name="vpn_set_vpn_title">Set always-on VPN?</string>
<!-- Dialog message body to explain that always-on VPN will disable network traffic while the VPN is connecting. -->
- <string name="vpn_first_always_on_vpn_message">By turning on this setting, you won\'t have an Internet connection until the VPN successfully connects</string>
+ <string name="vpn_first_always_on_vpn_message">When this setting is on, you won\'t have an internet connection until the VPN successfully connects</string>
<!-- Dialog message body to explain that always-on VPN will disable network traffic while the VPN is connecting, and that this will replace the current VPN. -->
- <string name="vpn_replace_always_on_vpn_enable_message">Your existing VPN will be replaced, and you won\'t have an Internet connection until the VPN successfully connects</string>
+ <string name="vpn_replace_always_on_vpn_enable_message">Your existing VPN will be replaced, and you won\'t have an internet connection until the VPN successfully connects</string>
<!-- Dialog message body to connect a VPN app, replacing another VPN app that is already always-on [CHAR LIMIT=NONE] -->
<string name="vpn_replace_always_on_vpn_disable_message">You\'re already connected to an always-on VPN. If you connect to a different one, your existing VPN will be replaced, and always-on mode will turn off.</string>
<!-- Dialog message body to set another VPN app to be always-on [CHAR LIMIT=NONE] -->
@@ -8189,7 +8189,7 @@
<string name="condition_airplane_title">Airplane mode is on</string>
<!-- Summary of condition that airplane mode is on [CHAR LIMIT=NONE] -->
- <string name="condition_airplane_summary">Wi-Fi, Bluetooth, and mobile network are turned off. You can\'t make phone calls or connect to the Internet.</string>
+ <string name="condition_airplane_summary">Wi-Fi, Bluetooth, and mobile network are turned off. You can\'t make phone calls or connect to the internet.</string>
<!-- Title of condition that do not disturb is on [CHAR LIMIT=30] -->
<string name="condition_zen_title">Do not disturb is on (<xliff:g name="zen_mode_type" example="Alarms only">%1$s</xliff:g>)</string>
@@ -8794,9 +8794,9 @@
<!-- setting enable OEM unlock Checkbox's summary to explain this Checkbox is disabled because the bootloader has been unlocked [CHAR_LIMIT=60] -->
<string name="oem_unlock_enable_disabled_summary_bootloader_unlocked">Bootloader is already unlocked</string>
<!-- setting enable OEM unlock Checkbox's summary to explain this Checkbox is disabled because there is no connectivity. [CHAR_LIMIT=60] -->
- <string name="oem_unlock_enable_disabled_summary_connectivity">Connect to the Internet first</string>
+ <string name="oem_unlock_enable_disabled_summary_connectivity">Connect to the internet first</string>
<!-- setting enable OEM unlock Checkbox's summary to explain this Checkbox is disabled because there is no connectivity or the device is locked by the carrier [CHAR_LIMIT=60] -->
- <string name="oem_unlock_enable_disabled_summary_connectivity_or_locked">Connect to the Internet or contact your carrier</string>
+ <string name="oem_unlock_enable_disabled_summary_connectivity_or_locked">Connect to the internet or contact your carrier</string>
<!-- setting enable OEM unlock Checkbox's summary to explain this Checkbox is disabled because this setting is unavailable on sim-locked devices. [CHAR_LIMIT=60] -->
<string name="oem_unlock_enable_disabled_summary_sim_locked_device">Unavailable on carrier-locked devices</string>
<!-- Information displayed after user locks OEM lock [Char Limit=None]-->
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
new file mode 100644
index 0000000..00a9142
--- /dev/null
+++ b/res/xml/app_notification_settings.xml
@@ -0,0 +1,55 @@
+<?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/com.android.settings">
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="pref_app_header"
+ android:layout="@layout/settings_entity_header" />
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="block"
+ android:layout="@layout/styled_switch_bar" />
+
+ <!-- Show badge -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="badge"
+ android:title="@string/notification_badge_title"
+ settings:useAdditionalSummary="true"
+ settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+
+ <!-- Channels/Channel groups added here -->
+
+ <Preference
+ android:key="app_link"
+ android:title="@string/app_settings_link"
+ android:order="500"
+ settings:allowDividerAbove="true"/>
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="block_desc"
+ android:order="1000" />
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="desc"
+ android:order="5000" />
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="deleted"
+ android:order="8000" />
+
+</PreferenceScreen>
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
new file mode 100644
index 0000000..aaadce4
--- /dev/null
+++ b/res/xml/channel_notification_settings.xml
@@ -0,0 +1,90 @@
+<?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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="pref_app_header"
+ android:layout="@layout/settings_entity_header" />
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="block"
+ android:layout="@layout/styled_switch_bar" />
+
+ <!-- Importance -->
+ <Preference
+ android:key="importance"
+ android:title="@string/notification_importance_title" />
+
+ <!-- Importance toggle -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="allow_sound"
+ android:title="@string/allow_interruption"
+ android:summary="@string/allow_interruption_summary" />
+
+ <!-- Default ringtone -->
+ <com.android.settings.notification.NotificationSoundPreference
+ android:key="ringtone"
+ android:title="@string/notification_channel_sound_title"
+ android:dialogTitle="@string/notification_channel_sound_title"
+ android:showSilent="true"
+ android:showDefault="true"
+ android:ringtoneType="notification" />
+
+ <!-- Vibration -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="vibrate"
+ android:title="@string/notification_vibrate_title"
+ settings:useAdditionalSummary="true" />
+
+ <!-- Visibility Override -->
+ <com.android.settings.notification.RestrictedDropDownPreference
+ android:key="visibility_override"
+ android:title="@string/app_notification_visibility_override_title"/>
+
+ <!-- Lights -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="lights"
+ android:title="@string/notification_show_lights_title"
+ settings:useAdditionalSummary="true"/>
+
+ <!-- Show badge -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="badge"
+ android:title="@string/notification_channel_badge_title"
+ settings:useAdditionalSummary="true"
+ settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
+
+ <!-- Bypass DND -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="bypass_dnd"
+ android:title="@string/app_notification_override_dnd_title"
+ android:summary="@string/app_notification_override_dnd_summary"
+ settings:useAdditionalSummary="true"/>
+
+ <Preference
+ android:key="app_link"
+ android:title="@string/app_settings_link"
+ settings:allowDividerAbove="true"/>
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="desc" />
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="block_desc" />
+
+</PreferenceScreen>
diff --git a/res/xml/legacy_channel_notification_settings.xml b/res/xml/legacy_channel_notification_settings.xml
deleted file mode 100644
index 519bf5d..0000000
--- a/res/xml/legacy_channel_notification_settings.xml
+++ /dev/null
@@ -1,45 +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/com.android.settings" >
-
- <!-- Show badge -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="badge"
- android:title="@string/notification_badge_title"
- settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin" />
-
- <!-- Importance toggle -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="allow_sound"
- android:title="@string/allow_interruption"
- android:summary="@string/allow_interruption_summary"/>
-
- <!-- Visibility Override -->
- <com.android.settings.notification.RestrictedDropDownPreference
- android:key="visibility_override"
- android:title="@string/app_notification_visibility_override_title" />
-
- <!-- Bypass DND -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="bypass_dnd"
- android:title="@string/app_notification_override_dnd_title"
- android:summary="@string/app_notification_override_dnd_summary"
- settings:useAdditionalSummary="true" />
-
-</PreferenceScreen>
diff --git a/res/xml/notification_group_settings.xml b/res/xml/notification_group_settings.xml
new file mode 100644
index 0000000..c138197
--- /dev/null
+++ b/res/xml/notification_group_settings.xml
@@ -0,0 +1,40 @@
+<?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/com.android.settings">
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="pref_app_header"
+ android:layout="@layout/settings_entity_header" />
+
+ <com.android.settings.applications.LayoutPreference
+ android:key="block"
+ android:layout="@layout/styled_switch_bar" />
+
+ <!-- Channels added here -->
+
+ <Preference
+ android:key="app_link"
+ android:title="@string/app_settings_link"
+ settings:allowDividerAbove="true"/>
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="desc" />
+
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="block_desc" />
+</PreferenceScreen>
diff --git a/res/xml/upgraded_app_notification_settings.xml b/res/xml/upgraded_app_notification_settings.xml
deleted file mode 100644
index f9a3304..0000000
--- a/res/xml/upgraded_app_notification_settings.xml
+++ /dev/null
@@ -1,27 +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/com.android.settings">
-
- <!-- Show badge -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="badge"
- android:title="@string/notification_badge_title"
- settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin" />
-
-</PreferenceScreen>
diff --git a/res/xml/upgraded_channel_notification_settings.xml b/res/xml/upgraded_channel_notification_settings.xml
deleted file mode 100644
index ee23435..0000000
--- a/res/xml/upgraded_channel_notification_settings.xml
+++ /dev/null
@@ -1,71 +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.
--->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" >
-
- <!-- Importance -->
- <Preference
- android:key="importance"
- android:title="@string/notification_importance_title" />
-
- <!-- Default ringtone -->
- <com.android.settings.notification.NotificationSoundPreference
- android:key="ringtone"
- android:title="@string/notification_channel_sound_title"
- android:dialogTitle="@string/notification_channel_sound_title"
- android:showSilent="true"
- android:showDefault="true"
- android:ringtoneType="notification" />
-
- <!-- Vibration -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="vibrate"
- android:title="@string/notification_vibrate_title"
- settings:useAdditionalSummary="true" />
-
- <PreferenceCategory
- android:key="advanced"
- android:title="@string/advanced_apps">
-
- <!-- Visibility Override -->
- <com.android.settings.notification.RestrictedDropDownPreference
- android:key="visibility_override"
- android:title="@string/app_notification_visibility_override_title" />
-
- <!-- Lights -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="lights"
- android:title="@string/notification_show_lights_title"
- settings:useAdditionalSummary="true" />
-
- <!-- Show badge -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="badge"
- android:title="@string/notification_channel_badge_title"
- settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin" />
-
- <!-- Bypass DND -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="bypass_dnd"
- android:title="@string/app_notification_override_dnd_title"
- android:summary="@string/app_notification_override_dnd_summary"
- settings:useAdditionalSummary="true" />
-
- </PreferenceCategory>
-
-</PreferenceScreen>
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
index a44e182..e547570 100644
--- a/src/com/android/settings/PrivacySettings.java
+++ b/src/com/android/settings/PrivacySettings.java
@@ -63,7 +63,6 @@
@VisibleForTesting
static final String DATA_MANAGEMENT = "data_management";
private static final String BACKUP_INACTIVE = "backup_inactive";
- private static final String FACTORY_RESET = "factory_reset";
private static final String TAG = "PrivacySettings";
private IBackupManager mBackupManager;
private Preference mBackup;
@@ -245,9 +244,5 @@
nonVisibleKeys.add(AUTO_RESTORE);
nonVisibleKeys.add(CONFIGURE_ACCOUNT);
}
- if (RestrictedLockUtils.hasBaseUserRestriction(context,
- UserManager.DISALLOW_FACTORY_RESET, UserHandle.myUserId())) {
- nonVisibleKeys.add(FACTORY_RESET);
- }
}
}
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index b108c62..cab3139 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -48,7 +48,6 @@
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -62,7 +61,6 @@
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
-import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Bundle;
@@ -97,7 +95,6 @@
import android.text.style.TtsSpan;
import android.util.ArraySet;
import android.util.Log;
-import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@@ -108,13 +105,10 @@
import com.android.internal.app.UnlaunchableAppActivity;
import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.UserIcons;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
import com.android.settings.wrapper.FingerprintManagerWrapper;
-import java.io.IOException;
-import java.io.InputStream;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Iterator;
@@ -131,11 +125,6 @@
public static final int UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY = 1;
/**
- * The opacity level of a disabled icon.
- */
- public static final float DISABLED_ALPHA = 0.4f;
-
- /**
* Color spectrum to use to indicate badness. 0 is completely transparent (no data),
* 1 is most bad (red), the last value is least bad (green).
*/
@@ -152,8 +141,6 @@
public static final String OS_PKG = "os";
- private static SparseArray<Bitmap> sDarkDefaultUserBitmapCache = new SparseArray<Bitmap>();
-
/**
* Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference.
@@ -344,46 +331,6 @@
view.setPaddingRelative(paddingStart, 0, paddingEnd, paddingBottom);
}
- /* Used by UserSettings as well. Call this on a non-ui thread. */
- public static void copyMeProfilePhoto(Context context, UserInfo user) {
- Uri contactUri = Profile.CONTENT_URI;
-
- int userId = user != null ? user.id : UserHandle.myUserId();
-
- InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
- context.getContentResolver(),
- contactUri, true);
- // If there's no profile photo, assign a default avatar
- if (avatarDataStream == null) {
- assignDefaultPhoto(context, userId);
- return;
- }
-
- UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
- Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
- um.setUserIcon(userId, icon);
- try {
- avatarDataStream.close();
- } catch (IOException ioe) { }
- }
-
- /**
- * Assign the default photo to user with {@paramref userId}
- * @param context used to get the {@link UserManager}
- * @param userId used to get the icon bitmap
- * @return true if assign photo successfully, false if failed
- */
- public static boolean assignDefaultPhoto(Context context, int userId) {
- if (context == null) {
- return false;
- }
- UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
- Bitmap bitmap = getDefaultUserIconAsBitmap(userId);
- um.setUserIcon(userId, bitmap);
-
- return true;
- }
-
public static String getMeProfileName(Context context, boolean full) {
if (full) {
return getProfileDisplayName(context);
@@ -504,6 +451,26 @@
metricsCategory);
}
+
+ /**
+ * Start a new instance of the activity, showing only the given fragment.
+ * When launched in this mode, the given preference fragment will be instantiated and fill the
+ * entire activity.
+ *
+ * @param context The context.
+ * @param fragmentName The name of the fragment to display.
+ * @param titleResId resource id for the String to display for the title of this set
+ * of preferences.
+ * @param metricsCategory The current metricsCategory for logging source when fragment starts
+ * @param intentFlags flag that should be added to the intent.
+ */
+ public static void startWithFragment(Context context, String fragmentName, int titleResId,
+ int metricsCategory, int intentFlags) {
+ startWithFragment(context, fragmentName, null, null, 0,
+ null /* titleResPackageName */, titleResId, null, false /* not a shortcut */,
+ metricsCategory, intentFlags);
+ }
+
/**
* Start a new instance of the activity, showing only the given fragment.
* When launched in this mode, the given preference fragment will be instantiated and fill the
@@ -544,8 +511,17 @@
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
CharSequence title, boolean isShortcut, int metricsCategory) {
+ startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
+ titleResPackageName, titleResId, title, isShortcut, metricsCategory, 0);
+ }
+
+
+ public static void startWithFragment(Context context, String fragmentName, Bundle args,
+ Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
+ CharSequence title, boolean isShortcut, int metricsCategory, int flags) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
titleResId, title, isShortcut, metricsCategory);
+ intent.addFlags(flags);
if (resultTo == null) {
context.startActivity(intent);
} else {
@@ -936,23 +912,6 @@
return (sm.getStorageBytesUntilLow(context.getFilesDir()) < 0);
}
- /**
- * Returns a default user icon (as a {@link Bitmap}) for the given user.
- *
- * Note that for guest users, you should pass in {@code UserHandle.USER_NULL}.
- * @param userId the user id or {@code UserHandle.USER_NULL} for a non-user specific icon
- */
- public static Bitmap getDefaultUserIconAsBitmap(int userId) {
- Bitmap bitmap = null;
- // Try finding the corresponding bitmap in the dark bitmap cache
- bitmap = sDarkDefaultUserBitmapCache.get(userId);
- if (bitmap == null) {
- bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId, false));
- // Save it to cache
- sDarkDefaultUserBitmapCache.put(userId, bitmap);
- }
- return bitmap;
- }
public static boolean hasPreferredActivities(PackageManager pm, String packageName) {
// Get list of preferred activities
@@ -969,7 +928,7 @@
List<IntentFilter> filters = pm.getAllIntentFilters(packageName);
ArraySet<String> result = new ArraySet<>();
- if (iviList.size() > 0) {
+ if (iviList != null && iviList.size() > 0) {
for (IntentFilterVerificationInfo ivi : iviList) {
for (String host : ivi.getDomains()) {
result.add(host);
diff --git a/src/com/android/settings/applications/ManageDomainUrls.java b/src/com/android/settings/applications/ManageDomainUrls.java
index 53cad4a..93416ad 100644
--- a/src/com/android/settings/applications/ManageDomainUrls.java
+++ b/src/com/android/settings/applications/ManageDomainUrls.java
@@ -23,6 +23,7 @@
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Global;
+import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
@@ -37,6 +38,7 @@
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.widget.AppPreference;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -175,7 +177,7 @@
String key = entry.info.packageName + "|" + entry.info.uid;
DomainAppPreference preference = (DomainAppPreference) getCachedPreference(key);
if (preference == null) {
- preference = new DomainAppPreference(getPrefContext(), entry);
+ preference = new DomainAppPreference(getPrefContext(), mApplicationsState, entry);
preference.setKey(key);
preference.setOnPreferenceClickListener(this);
group.addPreference(preference);
@@ -225,12 +227,16 @@
return false;
}
- private class DomainAppPreference extends Preference {
+ @VisibleForTesting
+ static class DomainAppPreference extends AppPreference {
private final AppEntry mEntry;
private final PackageManager mPm;
+ private final ApplicationsState mApplicationsState;
- public DomainAppPreference(final Context context, AppEntry entry) {
+ public DomainAppPreference(final Context context, ApplicationsState applicationsState,
+ AppEntry entry) {
super(context);
+ mApplicationsState = applicationsState;
mPm = context.getPackageManager();
mEntry = entry;
mEntry.ensureLabel(getContext());
diff --git a/src/com/android/settings/dashboard/conditional/NightDisplayCondition.java b/src/com/android/settings/dashboard/conditional/NightDisplayCondition.java
index bfcab7f..4d885ae 100644
--- a/src/com/android/settings/dashboard/conditional/NightDisplayCondition.java
+++ b/src/com/android/settings/dashboard/conditional/NightDisplayCondition.java
@@ -18,20 +18,20 @@
import android.graphics.drawable.Icon;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.display.NightDisplaySettings;
public final class NightDisplayCondition extends Condition
- implements NightDisplayController.Callback {
+ implements ColorDisplayController.Callback {
- private NightDisplayController mController;
+ private ColorDisplayController mController;
NightDisplayCondition(ConditionManager manager) {
super(manager);
- mController = new NightDisplayController(manager.getContext());
+ mController = new ColorDisplayController(manager.getContext());
mController.setListener(this);
}
diff --git a/src/com/android/settings/display/ColorModePreferenceFragment.java b/src/com/android/settings/display/ColorModePreferenceFragment.java
index 9f18fd8..e3fb65d 100644
--- a/src/com/android/settings/display/ColorModePreferenceFragment.java
+++ b/src/com/android/settings/display/ColorModePreferenceFragment.java
@@ -17,7 +17,7 @@
import android.graphics.drawable.Drawable;
import android.support.annotation.VisibleForTesting;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
@@ -36,12 +36,12 @@
@VisibleForTesting
static final String KEY_COLOR_MODE_SATURATED = "color_mode_saturated";
- private NightDisplayController mController;
+ private ColorDisplayController mController;
@Override
public void onAttach(Context context) {
super.onAttach(context);
- mController = new NightDisplayController(context);
+ mController = new ColorDisplayController(context);
}
@Override
@@ -64,10 +64,10 @@
@Override
protected String getDefaultKey() {
- if (mController.getColorMode() == NightDisplayController.COLOR_MODE_SATURATED) {
+ if (mController.getColorMode() == ColorDisplayController.COLOR_MODE_SATURATED) {
return KEY_COLOR_MODE_SATURATED;
}
- if (mController.getColorMode() == NightDisplayController.COLOR_MODE_BOOSTED) {
+ if (mController.getColorMode() == ColorDisplayController.COLOR_MODE_BOOSTED) {
return KEY_COLOR_MODE_BOOSTED;
}
return KEY_COLOR_MODE_NATURAL;
@@ -77,13 +77,13 @@
protected boolean setDefaultKey(String key) {
switch (key) {
case KEY_COLOR_MODE_NATURAL:
- mController.setColorMode(NightDisplayController.COLOR_MODE_NATURAL);
+ mController.setColorMode(ColorDisplayController.COLOR_MODE_NATURAL);
break;
case KEY_COLOR_MODE_BOOSTED:
- mController.setColorMode(NightDisplayController.COLOR_MODE_BOOSTED);
+ mController.setColorMode(ColorDisplayController.COLOR_MODE_BOOSTED);
break;
case KEY_COLOR_MODE_SATURATED:
- mController.setColorMode(NightDisplayController.COLOR_MODE_SATURATED);
+ mController.setColorMode(ColorDisplayController.COLOR_MODE_SATURATED);
break;
}
return true;
diff --git a/src/com/android/settings/display/NightDisplayPreference.java b/src/com/android/settings/display/NightDisplayPreference.java
index b966530..ea39f75 100644
--- a/src/com/android/settings/display/NightDisplayPreference.java
+++ b/src/com/android/settings/display/NightDisplayPreference.java
@@ -18,7 +18,7 @@
import android.support.v14.preference.SwitchPreference;
import android.util.AttributeSet;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.settings.R;
import java.text.DateFormat;
@@ -27,15 +27,15 @@
import java.util.TimeZone;
public class NightDisplayPreference extends SwitchPreference
- implements NightDisplayController.Callback {
+ implements ColorDisplayController.Callback {
- private NightDisplayController mController;
+ private ColorDisplayController mController;
private DateFormat mTimeFormatter;
public NightDisplayPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mController = new NightDisplayController(context);
+ mController = new ColorDisplayController(context);
mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@@ -78,12 +78,12 @@
final String autoModeSummary;
switch (autoMode) {
default:
- case NightDisplayController.AUTO_MODE_DISABLED:
+ case ColorDisplayController.AUTO_MODE_DISABLED:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_never
: R.string.night_display_summary_off_auto_mode_never);
break;
- case NightDisplayController.AUTO_MODE_CUSTOM:
+ case ColorDisplayController.AUTO_MODE_CUSTOM:
if (isActivated) {
autoModeSummary = context.getString(
R.string.night_display_summary_on_auto_mode_custom,
@@ -94,7 +94,7 @@
getFormattedTimeString(mController.getCustomStartTime()));
}
break;
- case NightDisplayController.AUTO_MODE_TWILIGHT:
+ case ColorDisplayController.AUTO_MODE_TWILIGHT:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_twilight
: R.string.night_display_summary_off_auto_mode_twilight);
diff --git a/src/com/android/settings/display/NightDisplayPreferenceController.java b/src/com/android/settings/display/NightDisplayPreferenceController.java
index f42e324..643f1d4 100644
--- a/src/com/android/settings/display/NightDisplayPreferenceController.java
+++ b/src/com/android/settings/display/NightDisplayPreferenceController.java
@@ -15,7 +15,7 @@
import android.content.Context;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -30,7 +30,7 @@
@Override
public boolean isAvailable() {
- return NightDisplayController.isAvailable(mContext);
+ return ColorDisplayController.isAvailable(mContext);
}
@Override
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index 5879297..ab94720 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -25,7 +25,7 @@
import android.support.v7.preference.TwoStatePreference;
import android.widget.TimePicker;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.widget.SeekBarPreference;
@@ -40,7 +40,7 @@
* Settings screen for Night display.
*/
public class NightDisplaySettings extends SettingsPreferenceFragment
- implements NightDisplayController.Callback, Preference.OnPreferenceChangeListener {
+ implements ColorDisplayController.Callback, Preference.OnPreferenceChangeListener {
private static final String KEY_NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";
private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
@@ -51,7 +51,7 @@
private static final int DIALOG_START_TIME = 0;
private static final int DIALOG_END_TIME = 1;
- private NightDisplayController mController;
+ private ColorDisplayController mController;
private DateFormat mTimeFormatter;
private DropDownPreference mAutoModePreference;
@@ -65,7 +65,7 @@
super.onCreate(savedInstanceState);
final Context context = getContext();
- mController = new NightDisplayController(context);
+ mController = new ColorDisplayController(context);
mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -98,9 +98,9 @@
getString(R.string.night_display_auto_mode_twilight)
});
mAutoModePreference.setEntryValues(new CharSequence[] {
- String.valueOf(NightDisplayController.AUTO_MODE_DISABLED),
- String.valueOf(NightDisplayController.AUTO_MODE_CUSTOM),
- String.valueOf(NightDisplayController.AUTO_MODE_TWILIGHT)
+ String.valueOf(ColorDisplayController.AUTO_MODE_DISABLED),
+ String.valueOf(ColorDisplayController.AUTO_MODE_CUSTOM),
+ String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT)
});
mAutoModePreference.setOnPreferenceChangeListener(this);
mActivatedPreference.setOnPreferenceChangeListener(this);
@@ -192,7 +192,7 @@
public void onAutoModeChanged(int autoMode) {
mAutoModePreference.setValue(String.valueOf(autoMode));
- final boolean showCustomSchedule = autoMode == NightDisplayController.AUTO_MODE_CUSTOM;
+ final boolean showCustomSchedule = autoMode == ColorDisplayController.AUTO_MODE_CUSTOM;
mStartTimePreference.setVisible(showCustomSchedule);
mEndTimePreference.setVisible(showCustomSchedule);
}
diff --git a/src/com/android/settings/notification/AllowSoundPreferenceController.java b/src/com/android/settings/notification/AllowSoundPreferenceController.java
new file mode 100644
index 0000000..dcd5e45
--- /dev/null
+++ b/src/com/android/settings/notification/AllowSoundPreferenceController.java
@@ -0,0 +1,81 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import android.app.NotificationChannel;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.util.Log;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+public class AllowSoundPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "AllowSoundPrefContr";
+ private static final String KEY_IMPORTANCE = "allow_sound";
+ private NotificationSettingsBase.ImportanceListener mImportanceListener;
+
+ public AllowSoundPreferenceController(Context context,
+ NotificationSettingsBase.ImportanceListener importanceListener,
+ NotificationBackend backend) {
+ super(context, backend);
+ mImportanceListener = importanceListener;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_IMPORTANCE;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ return mChannel != null && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
+
+ }
+
+ public void updateState(Preference preference) {
+ if (mChannel != null) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ pref.setDisabledByAdmin(mAdmin);
+ pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
+ pref.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
+ || mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
+ } else { Log.i(TAG, "tried to updatestate on a null channel?!"); }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ final int importance =
+ ((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_LOW);
+ mChannel.setImportance(importance);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
+ saveChannel();
+ mImportanceListener.onImportanceChanged();
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/notification/AppLinkPreferenceController.java b/src/com/android/settings/notification/AppLinkPreferenceController.java
new file mode 100644
index 0000000..ff5945b
--- /dev/null
+++ b/src/com/android/settings/notification/AppLinkPreferenceController.java
@@ -0,0 +1,55 @@
+/*
+ * 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 android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+
+/**
+ * Controls link to reach more preference settings inside the app.
+ */
+public class AppLinkPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String TAG = "AppLinkPrefContr";
+ private static final String KEY_APP_LINK = "app_link";
+
+ public AppLinkPreferenceController(Context context) {
+ super(context, null);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_APP_LINK;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ return mAppRow.settingsIntent != null;
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null) {
+ preference.setIntent(mAppRow.settingsIntent);
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 95c9560..af168d6 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -16,12 +16,10 @@
package com.android.settings.notification;
-import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
-import android.app.NotificationManager;
+import android.content.Context;
import android.content.Intent;
-import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
@@ -29,43 +27,29 @@
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup;
import android.text.TextUtils;
-import android.util.ArrayMap;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Switch;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
-import com.android.settings.applications.LayoutPreference;
-import com.android.settings.notification.NotificationBackend.AppRow;
-import com.android.settings.widget.EntityHeaderController;
import com.android.settings.widget.MasterSwitchPreference;
-import com.android.settings.widget.SwitchBar;
-import com.android.settingslib.RestrictedSwitchPreference;
-import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import static android.app.NotificationManager.IMPORTANCE_NONE;
-import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
-
/** These settings are per app, so should not be returned in global search results. */
public class AppNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "AppNotificationSettings";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static String KEY_GENERAL_CATEGORY = "categories";
- private static String KEY_DELETED = "deleted";
private List<NotificationChannelGroup> mChannelGroupList;
- private List<PreferenceCategory> mChannelGroups = new ArrayList();
- private FooterPreference mDeletedChannels;
@Override
public int getMetricsCategory() {
@@ -84,24 +68,13 @@
if (getPreferenceScreen() != null) {
getPreferenceScreen().removeAll();
- mChannelGroups.clear();
- mDeletedChannels = null;
- mShowLegacyChannelConfig = false;
+ mDynamicPreferences.clear();
}
- addPreferencesFromResource(R.xml.notification_settings);
- getPreferenceScreen().setOrderingAsAdded(true);
- setupBlock();
- addHeaderPref();
-
- mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid);
if (mShowLegacyChannelConfig) {
- mChannel = mBackend.getChannel(
- mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
- populateDefaultChannelPrefs();
+ addPreferencesFromResource(R.xml.channel_notification_settings);
} else {
- addPreferencesFromResource(R.xml.upgraded_app_notification_settings);
- setupBadge();
+ addPreferencesFromResource(R.xml.app_notification_settings);
// Load channel settings
new AsyncTask<Void, Void, Void>() {
@Override
@@ -117,41 +90,59 @@
return;
}
populateList();
- addAppLinkPref();
}
}.execute();
}
+ getPreferenceScreen().setOrderingAsAdded(true);
- updateDependents(mAppRow.banned);
+ for (NotificationPreferenceController controller : mControllers) {
+ controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
+ controller.displayPreference(getPreferenceScreen());
+ }
+ updatePreferenceStates();
}
- private void addHeaderPref() {
- ArrayMap<String, AppRow> rows = new ArrayMap<>();
- rows.put(mAppRow.pkg, mAppRow);
- collectConfigActivities(rows);
- final Activity activity = getActivity();
- final Preference pref = EntityHeaderController
- .newInstance(activity, this /* fragment */, null /* header */)
- .setRecyclerView(getListView(), getLifecycle())
- .setIcon(mAppRow.icon)
- .setLabel(mAppRow.label)
- .setPackageName(mAppRow.pkg)
- .setUid(mAppRow.uid)
- .setHasAppInfoLink(true)
- .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
- EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
- .done(activity, getPrefContext());
- pref.setKey(KEY_HEADER);
- getPreferenceScreen().addPreference(pref);
+ @Override
+ protected String getLogTag() {
+ return TAG;
}
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.notification_settings;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ mControllers = new ArrayList<>();
+ mControllers.add(new HeaderPreferenceController(context, this));
+ mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
+ mControllers.add(new BadgePreferenceController(context, mBackend));
+ mControllers.add(new AllowSoundPreferenceController(
+ context, mImportanceListener, mBackend));
+ mControllers.add(new ImportancePreferenceController(context));
+ mControllers.add(new SoundPreferenceController(context, this,
+ mImportanceListener, mBackend));
+ mControllers.add(new LightsPreferenceController(context, mBackend));
+ mControllers.add(new VibrationPreferenceController(context, mBackend));
+ mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
+ mBackend));
+ mControllers.add(new DndPreferenceController(context, getLifecycle(), mBackend));
+ mControllers.add(new AppLinkPreferenceController(context));
+ mControllers.add(new DescriptionPreferenceController(context));
+ mControllers.add(new NotificationsOffPreferenceController(context));
+ mControllers.add(new DeletedChannelsPreferenceController(context, mBackend));
+ return new ArrayList<>(mControllers);
+ }
+
+
private void populateList() {
- if (!mChannelGroups.isEmpty()) {
+ if (!mDynamicPreferences.isEmpty()) {
// If there's anything in mChannelGroups, we've called populateChannelList twice.
// Clear out existing channels and log.
Log.w(TAG, "Notification channel group posted twice to settings - old size " +
- mChannelGroups.size() + ", new size " + mChannelGroupList.size());
- for (Preference p : mChannelGroups) {
+ mDynamicPreferences.size() + ", new size " + mChannelGroupList.size());
+ for (Preference p : mDynamicPreferences) {
getPreferenceScreen().removePreference(p);
}
}
@@ -160,7 +151,7 @@
groupCategory.setTitle(R.string.notification_channels);
groupCategory.setKey(KEY_GENERAL_CATEGORY);
getPreferenceScreen().addPreference(groupCategory);
- mChannelGroups.add(groupCategory);
+ mDynamicPreferences.add(groupCategory);
Preference empty = new Preference(getPrefContext());
empty.setTitle(R.string.no_channels);
@@ -168,20 +159,8 @@
groupCategory.addPreference(empty);
} else {
populateGroupList();
- int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
- if (deletedChannelCount > 0 &&
- getPreferenceScreen().findPreference(KEY_DELETED) == null) {
- mDeletedChannels = new FooterPreference(getPrefContext());
- mDeletedChannels.setSelectable(false);
- mDeletedChannels.setTitle(getResources().getQuantityString(
- R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
- mDeletedChannels.setEnabled(false);
- mDeletedChannels.setKey(KEY_DELETED);
- mDeletedChannels.setOrder(ORDER_LAST);
- getPreferenceScreen().addPreference(mDeletedChannels);
- }
+ mImportanceListener.onImportanceChanged();
}
- updateDependents(mAppRow.banned);
}
private void populateGroupList() {
@@ -190,7 +169,7 @@
groupCategory.setKey(KEY_GENERAL_CATEGORY);
groupCategory.setOrderingAsAdded(true);
getPreferenceScreen().addPreference(groupCategory);
- mChannelGroups.add(groupCategory);
+ mDynamicPreferences.add(groupCategory);
for (NotificationChannelGroup group : mChannelGroupList) {
final List<NotificationChannel> channels = group.getChannels();
int N = channels.size();
@@ -240,91 +219,6 @@
parent.addPreference(groupPref);
}
- void setupBadge() {
- mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
- mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
- if (mChannel == null) {
- mBadge.setChecked(mAppRow.showBadge);
- } else {
- mBadge.setChecked(mChannel.canShowBadge());
- }
- mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean value = (Boolean) newValue;
- if (mChannel == null) {
- mBackend.setShowBadge(mPkg, mUid, value);
- } else {
- mChannel.setShowBadge(value);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- }
- return true;
- }
- });
- }
-
- protected void setupBlock() {
- View switchBarContainer = LayoutInflater.from(
- getPrefContext()).inflate(R.layout.styled_switch_bar, null);
- mSwitchBar = switchBarContainer.findViewById(R.id.switch_bar);
- mSwitchBar.show();
- mSwitchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
- mSwitchBar.setChecked(!mAppRow.banned);
- mSwitchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
- @Override
- public void onSwitchChanged(Switch switchView, boolean isChecked) {
- if (mShowLegacyChannelConfig && mChannel != null) {
- final int importance = isChecked ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_NONE;
- mImportanceToggle.setChecked(importance == IMPORTANCE_UNSPECIFIED);
- mChannel.setImportance(importance);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- }
- mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid, isChecked);
- mAppRow.banned = true;
- updateDependents(!isChecked);
- }
- });
-
- mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
- mBlockBar.setOrder(ORDER_FIRST);
- mBlockBar.setKey(KEY_BLOCK);
- getPreferenceScreen().addPreference(mBlockBar);
-
- if (mAppRow.systemApp && !mAppRow.banned) {
- setVisible(mBlockBar, false);
- }
-
- setupBlockDesc(R.string.app_notifications_off_desc);
- }
-
- protected void updateDependents(boolean banned) {
- for (PreferenceCategory category : mChannelGroups) {
- setVisible(category, !banned);
- }
- if (mDeletedChannels != null) {
- setVisible(mDeletedChannels, !banned);
- }
- setVisible(mBlockedDesc, banned);
- setVisible(mBadge, !banned);
- if (mShowLegacyChannelConfig) {
- setVisible(mImportanceToggle, !banned);
- setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
- || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
- && mDndVisualEffectsSuppressed));
- setVisible(mVisibilityOverride, !banned &&
- checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure());
- }
- if (mAppLink != null) {
- setVisible(mAppLink, !banned);
- }
- if (mAppRow.systemApp && !mAppRow.banned) {
- setVisible(mBlockBar, false);
- }
- }
-
-
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
new Comparator<NotificationChannelGroup>() {
diff --git a/src/com/android/settings/notification/BadgePreferenceController.java b/src/com/android/settings/notification/BadgePreferenceController.java
new file mode 100644
index 0000000..6b72c50
--- /dev/null
+++ b/src/com/android/settings/notification/BadgePreferenceController.java
@@ -0,0 +1,90 @@
+/*
+ * 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 static android.provider.Settings.Secure.NOTIFICATION_BADGING;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+public class BadgePreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "BadgePrefContr";
+ private static final String KEY_BADGE = "badge";
+ private static final int SYSTEM_WIDE_ON = 1;
+ private static final int SYSTEM_WIDE_OFF = 0;
+
+ public BadgePreferenceController(Context context,
+ NotificationBackend backend) {
+ super(context, backend);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BADGE;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mAppRow == null && mChannel == null) {
+ return false;
+ }
+ if (Settings.Secure.getInt(mContext.getContentResolver(),
+ NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) {
+ return false;
+ }
+ if (mChannel != null && !mAppRow.showBadge) {
+ return false;
+ }
+ return true;
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ pref.setDisabledByAdmin(mAdmin);
+ if (mChannel != null) {
+ pref.setChecked(mChannel.canShowBadge());
+ pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
+ } else {
+ pref.setChecked(mAppRow.showBadge);
+ }
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean showBadge = (Boolean) newValue;
+ if (mChannel != null) {
+ mChannel.setShowBadge(showBadge);
+ saveChannel();
+ } else if (mAppRow != null){
+ mAppRow.showBadge = showBadge;
+ mBackend.setShowBadge(mAppRow.pkg, mAppRow.uid, showBadge);
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/android/settings/notification/BlockPreferenceController.java b/src/com/android/settings/notification/BlockPreferenceController.java
new file mode 100644
index 0000000..5c366ea
--- /dev/null
+++ b/src/com/android/settings/notification/BlockPreferenceController.java
@@ -0,0 +1,113 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.widget.Switch;
+
+import com.android.settings.R;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.widget.SwitchBar;
+
+public class BlockPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, SwitchBar.OnSwitchChangeListener {
+
+ private static final String KEY_BLOCK = "block";
+ private NotificationSettingsBase.ImportanceListener mImportanceListener;
+
+ public BlockPreferenceController(Context context,
+ NotificationSettingsBase.ImportanceListener importanceListener,
+ NotificationBackend backend) {
+ super(context, backend);
+ mImportanceListener = importanceListener;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BLOCK;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (mAppRow == null) {
+ return false;
+ }
+ if (mChannel != null) {
+ return isChannelBlockable();
+ } else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
+ return isChannelGroupBlockable();
+ } else {
+ return !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
+ }
+ }
+
+ public void updateState(Preference preference) {
+ LayoutPreference pref = (LayoutPreference) preference;
+ SwitchBar bar = pref.findViewById(R.id.switch_bar);
+ if (bar != null) {
+ bar.show();
+ try {
+ bar.addOnSwitchChangeListener(this);
+ } catch (IllegalStateException e) {
+ // an exception is thrown if you try to add the listener twice
+ }
+ bar.setDisabledByAdmin(mAdmin);
+
+ if (mChannel != null) {
+ bar.setChecked(!mAppRow.banned
+ && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
+ } else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
+ bar.setChecked(!mAppRow.banned && !mChannelGroup.isBlocked());
+ } else {
+ bar.setChecked(!mAppRow.banned);
+ }
+ }
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ boolean blocked = !isChecked;
+ if (mChannel != null) {
+ final int originalImportance = mChannel.getImportance();
+ // setting the initial state of the switch in updateState() triggers this callback.
+ // It's always safe to override the importance if it's meant to be blocked or if
+ // it was blocked and we are unblocking it.
+ if (blocked || originalImportance == IMPORTANCE_NONE) {
+ final int importance = blocked ? IMPORTANCE_NONE
+ : DEFAULT_CHANNEL_ID.equals(mChannel.getId())
+ ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_DEFAULT;
+ mChannel.setImportance(importance);
+ saveChannel();
+ }
+ } else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
+ mChannelGroup.setBlocked(blocked);
+ mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, mChannelGroup.getGroup());
+ } else if (mAppRow != null) {
+ mAppRow.banned = blocked;
+ mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
+ }
+ mImportanceListener.onImportanceChanged();
+ }
+}
diff --git a/src/com/android/settings/notification/ChannelGroupNotificationSettings.java b/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
index 7837ec8..68dd91b 100644
--- a/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelGroupNotificationSettings.java
@@ -16,20 +16,15 @@
package com.android.settings.notification;
-import android.app.Activity;
import android.app.NotificationChannel;
+import android.content.Context;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
-import android.util.ArrayMap;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.applications.LayoutPreference;
-import com.android.settings.widget.EntityHeaderController;
-import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.Collections;
@@ -38,12 +33,6 @@
public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "ChannelGroupSettings";
- private static String KEY_DELETED = "deleted";
-
- private EntityHeaderController mHeaderPref;
- private List<Preference> mChannels = new ArrayList();
- private FooterPreference mDeletedChannels;
-
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_CHANNEL_GROUP;
@@ -52,137 +41,68 @@
@Override
public void onResume() {
super.onResume();
- if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannelGroup == null) {
+ if (mAppRow == null || mChannelGroup == null || mChannelGroup.getGroup() == null) {
Log.w(TAG, "Missing package or uid or packageinfo or group");
finish();
return;
}
- if (getPreferenceScreen() != null) {
- getPreferenceScreen().removeAll();
- }
- addPreferencesFromResource(R.xml.notification_settings);
- setupBlock();
- addHeaderPref();
- addAppLinkPref();
- addFooterPref();
populateChannelList();
-
- updateDependents(mChannelGroup.isBlocked());
+ for (NotificationPreferenceController controller : mControllers) {
+ controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
+ controller.displayPreference(getPreferenceScreen());
+ }
+ updatePreferenceStates();
}
@Override
- void setupBadge() {
+ protected String getLogTag() {
+ return TAG;
+ }
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.notification_group_settings;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ mControllers = new ArrayList<>();
+ mControllers.add(new HeaderPreferenceController(context, this));
+ mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
+ mControllers.add(new AppLinkPreferenceController(context));
+ mControllers.add(new NotificationsOffPreferenceController(context));
+ mControllers.add(new DescriptionPreferenceController(context));
+ return new ArrayList<>(mControllers);
}
private void populateChannelList() {
- if (!mChannels.isEmpty()) {
- // If there's anything in mChannels, we've called populateChannelList twice.
+ if (!mDynamicPreferences.isEmpty()) {
+ // If there's anything in mDynamicPreferences, we've called populateChannelList twice.
// Clear out existing channels and log.
Log.w(TAG, "Notification channel group posted twice to settings - old size " +
- mChannels.size() + ", new size " + mChannels.size());
- for (Preference p : mChannels) {
+ mDynamicPreferences.size() + ", new size " + mDynamicPreferences.size());
+ for (Preference p : mDynamicPreferences) {
getPreferenceScreen().removePreference(p);
}
}
- if (mChannelGroup.getChannels().isEmpty()) {
+ if (mChannelGroup.getGroup().getChannels().isEmpty()) {
Preference empty = new Preference(getPrefContext());
empty.setTitle(R.string.no_channels);
empty.setEnabled(false);
getPreferenceScreen().addPreference(empty);
- mChannels.add(empty);
+ mDynamicPreferences.add(empty);
} else {
- final List<NotificationChannel> channels = mChannelGroup.getChannels();
+ final List<NotificationChannel> channels = mChannelGroup.getGroup().getChannels();
Collections.sort(channels, mChannelComparator);
for (NotificationChannel channel : channels) {
- mChannels.add(populateSingleChannelPrefs(
- getPreferenceScreen(), channel, getImportanceSummary(channel)));
+ mDynamicPreferences.add(populateSingleChannelPrefs(
+ getPreferenceScreen(), channel,
+ ImportancePreferenceController.getImportanceSummary(
+ getPrefContext(), channel)));
}
- int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
- if (deletedChannelCount > 0) {
- mDeletedChannels = new FooterPreference(getPrefContext());
- mDeletedChannels.setSelectable(false);
- mDeletedChannels.setTitle(getResources().getQuantityString(
- R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
- mDeletedChannels.setEnabled(false);
- mDeletedChannels.setKey(KEY_DELETED);
- mDeletedChannels.setOrder(ORDER_LAST);
- getPreferenceScreen().addPreference(mDeletedChannels);
- mChannels.add(mDeletedChannels);
- }
}
-
- updateDependents(mAppRow.banned);
- }
-
- private void addHeaderPref() {
- ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<>();
- rows.put(mAppRow.pkg, mAppRow);
- collectConfigActivities(rows);
- final Activity activity = getActivity();
- mHeaderPref = EntityHeaderController
- .newInstance(activity, this /* fragment */, null /* header */)
- .setRecyclerView(getListView(), getLifecycle());
- final Preference pref = mHeaderPref
- .setIcon(mAppRow.icon)
- .setLabel(mChannelGroup.getName())
- .setSummary(mAppRow.label)
- .setPackageName(mAppRow.pkg)
- .setUid(mAppRow.uid)
- .setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
- EntityHeaderController.ActionType.ACTION_NONE)
- .setHasAppInfoLink(true)
- .done(activity, getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
-
- private void addFooterPref() {
- if (!TextUtils.isEmpty(mChannelGroup.getDescription())) {
- FooterPreference descPref = new FooterPreference(getPrefContext());
- descPref.setOrder(ORDER_LAST);
- descPref.setSelectable(false);
- descPref.setTitle(mChannelGroup.getDescription());
- getPreferenceScreen().addPreference(descPref);
- mChannels.add(descPref);
- }
- }
-
- private void setupBlock() {
- View switchBarContainer = LayoutInflater.from(
- getPrefContext()).inflate(R.layout.styled_switch_bar, null);
- mSwitchBar = switchBarContainer.findViewById(R.id.switch_bar);
- mSwitchBar.show();
- mSwitchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
- mSwitchBar.setChecked(!mChannelGroup.isBlocked());
- mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
- mChannelGroup.setBlocked(!isChecked);
- mBackend.updateChannelGroup(mPkg, mUid, mChannelGroup);
- updateDependents(!isChecked);
- });
-
- mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
- mBlockBar.setOrder(ORDER_FIRST);
- mBlockBar.setKey(KEY_BLOCK);
- getPreferenceScreen().addPreference(mBlockBar);
-
- if (!isChannelGroupBlockable(mChannelGroup)) {
- setVisible(mBlockBar, false);
- }
-
- setupBlockDesc(R.string.channel_group_notifications_off_desc);
- }
-
- protected void updateDependents(boolean banned) {
- for (Preference channel : mChannels) {
- setVisible(channel, !banned);
- }
- if (mAppLink != null) {
- setVisible(mAppLink, !banned);
- }
- setVisible(mBlockBar, isChannelGroupBlockable(mChannelGroup));
- setVisible(mBlockedDesc, mAppRow.banned || mChannelGroup.isBlocked());
}
}
diff --git a/src/com/android/settings/notification/ChannelImportanceSettings.java b/src/com/android/settings/notification/ChannelImportanceSettings.java
index 9e9ffd6..27b23b8 100644
--- a/src/com/android/settings/notification/ChannelImportanceSettings.java
+++ b/src/com/android/settings/notification/ChannelImportanceSettings.java
@@ -37,6 +37,7 @@
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.widget.RadioButtonPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
@@ -60,8 +61,8 @@
@Override
public void onResume() {
super.onResume();
- if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mChannel == null) {
- Log.w(TAG, "Missing package or uid or packageinfo or channel");
+ if (mAppRow == null || mChannel == null) {
+ Log.w(TAG, "Missing package or channel");
finish();
return;
}
@@ -69,10 +70,19 @@
}
@Override
- void setupBadge() {}
+ protected String getLogTag() {
+ return TAG;
+ }
@Override
- void updateDependents(boolean banned) {}
+ protected int getPreferenceScreenResId() {
+ return R.xml.notification_importance;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ return null;
+ }
@Override
public void onPause() {
@@ -81,11 +91,6 @@
private PreferenceScreen createPreferenceHierarchy() {
PreferenceScreen root = getPreferenceScreen();
- if (root != null) {
- root.removeAll();
- }
- addPreferencesFromResource(R.xml.notification_importance);
- root = getPreferenceScreen();
for (int i = 0; i < root.getPreferenceCount(); i++) {
Preference pref = root.getPreference(i);
@@ -148,8 +153,9 @@
// but the sound you had selected was "Silence",
// then set sound for this channel to your default sound,
// because you probably intended to cause this channel to actually start making sound.
- if (oldImportance < IMPORTANCE_DEFAULT && !hasValidSound(mChannel) &&
- mChannel.getImportance() >= IMPORTANCE_DEFAULT) {
+ if (oldImportance < IMPORTANCE_DEFAULT
+ && !SoundPreferenceController.hasValidSound(mChannel)
+ && mChannel.getImportance() >= IMPORTANCE_DEFAULT) {
mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
mChannel.getAudioAttributes());
mChannel.lockFields(USER_LOCKED_SOUND);
@@ -157,15 +163,4 @@
mChannel.lockFields(USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel);
}
-
- // This page exists per notification channel; should not be included
- // in search
- public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- return null;
- }
- };
}
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index 9484f7e..ea17a05 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -16,59 +16,23 @@
package com.android.settings.notification;
-import android.app.Activity;
-import android.app.NotificationChannel;
-import android.app.NotificationChannelGroup;
-import android.app.NotificationManager;
+import android.content.Context;
import android.content.Intent;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.AsyncTask;
-import android.provider.Settings;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceGroup;
+import android.preference.PreferenceManager;
import android.text.TextUtils;
-import android.text.BidiFormatter;
-import android.text.SpannableStringBuilder;
-import android.util.ArrayMap;
import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Switch;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
-import com.android.settings.RingtonePreference;
-import com.android.settings.Utils;
-import com.android.settings.applications.AppInfoBase;
-import com.android.settings.applications.LayoutPreference;
-import com.android.settings.widget.EntityHeaderController;
-import com.android.settings.widget.SwitchBar;
-import com.android.settingslib.RestrictedSwitchPreference;
-import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
-import static android.app.NotificationManager.IMPORTANCE_LOW;
-import static android.app.NotificationManager.IMPORTANCE_NONE;
-import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+import java.util.ArrayList;
+import java.util.List;
public class ChannelNotificationSettings extends NotificationSettingsBase {
private static final String TAG = "ChannelSettings";
- private static final String KEY_LIGHTS = "lights";
- private static final String KEY_VIBRATE = "vibrate";
- private static final String KEY_RINGTONE = "ringtone";
- private static final String KEY_IMPORTANCE = "importance";
- private static final String KEY_ADVANCED = "advanced";
-
- private Preference mImportance;
- private RestrictedSwitchPreference mLights;
- private RestrictedSwitchPreference mVibrate;
- private NotificationSoundPreference mRingtone;
- private FooterPreference mFooter;
- private NotificationChannelGroup mChannelGroup;
- private EntityHeaderController mHeaderPref;
- private PreferenceGroup mAdvanced;
-
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
@@ -83,308 +47,52 @@
return;
}
- if (getPreferenceScreen() != null) {
- getPreferenceScreen().removeAll();
+ for (NotificationPreferenceController controller : mControllers) {
+ controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
+ controller.displayPreference(getPreferenceScreen());
}
- addPreferencesFromResource(R.xml.notification_settings);
- setupBlock();
- addHeaderPref();
- addAppLinkPref();
- addFooterPref();
-
- if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
- populateDefaultChannelPrefs();
- mShowLegacyChannelConfig = true;
- } else {
- populateUpgradedChannelPrefs();
-
- if (mChannel.getGroup() != null) {
- mChannelGroup = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
- if (mChannelGroup != null) {
- setChannelGroupLabel(mChannelGroup.getName());
- }
- }
- }
-
- updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
- }
-
- private void populateUpgradedChannelPrefs() {
- addPreferencesFromResource(R.xml.upgraded_channel_notification_settings);
- setupBadge();
- setupPriorityPref(mChannel.canBypassDnd());
- setupVisOverridePref(mChannel.getLockscreenVisibility());
- setupLights();
- setupVibrate();
- setupRingtone();
- setupImportance();
- mAdvanced = (PreferenceGroup) findPreference(KEY_ADVANCED);
- }
-
- private void addHeaderPref() {
- ArrayMap<String, NotificationBackend.AppRow> rows = new ArrayMap<>();
- rows.put(mAppRow.pkg, mAppRow);
- collectConfigActivities(rows);
- final Activity activity = getActivity();
- mHeaderPref = EntityHeaderController
- .newInstance(activity, this /* fragment */, null /* header */)
- .setRecyclerView(getListView(), getLifecycle());
- final Preference pref = mHeaderPref
- .setIcon(mAppRow.icon)
- .setLabel(mChannel.getName())
- .setSummary(mAppRow.label)
- .setPackageName(mAppRow.pkg)
- .setUid(mAppRow.uid)
- .setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
- EntityHeaderController.ActionType.ACTION_NONE)
- .setHasAppInfoLink(true)
- .done(activity, getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
-
- private void setChannelGroupLabel(CharSequence groupName) {
- final SpannableStringBuilder summary = new SpannableStringBuilder();
- BidiFormatter bidi = BidiFormatter.getInstance();
- summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
- if (groupName != null) {
- summary.append(bidi.unicodeWrap(mContext.getText(
- R.string.notification_header_divider_symbol_with_spaces)));
- summary.append(bidi.unicodeWrap(groupName.toString()));
- }
- final Activity activity = getActivity();
- mHeaderPref.setSummary(summary.toString());
- mHeaderPref.done(activity, getPrefContext());
- }
-
- private void addFooterPref() {
- if (!TextUtils.isEmpty(mChannel.getDescription())) {
- FooterPreference descPref = new FooterPreference(getPrefContext());
- descPref.setOrder(ORDER_LAST);
- descPref.setSelectable(false);
- descPref.setTitle(mChannel.getDescription());
- getPreferenceScreen().addPreference(descPref);
- }
- }
-
- protected void setupBadge() {
- mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
- mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
- mBadge.setEnabled(mAppRow.showBadge);
- mBadge.setChecked(mChannel.canShowBadge());
-
- mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean value = (Boolean) newValue;
- mChannel.setShowBadge(value);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- }
-
- private void setupLights() {
- mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
- mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
- mLights.setChecked(mChannel.shouldShowLights());
- mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean lights = (Boolean) newValue;
- mChannel.enableLights(lights);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_LIGHTS);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- }
-
- private void setupVibrate() {
- mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
- mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
- mVibrate.setEnabled(!mVibrate.isDisabledByAdmin() && isChannelConfigurable(mChannel));
- mVibrate.setChecked(mChannel.shouldVibrate());
- mVibrate.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean vibrate = (Boolean) newValue;
- mChannel.enableVibration(vibrate);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_VIBRATION);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- }
-
- private void setupRingtone() {
- mRingtone = (NotificationSoundPreference) findPreference(KEY_RINGTONE);
- mRingtone.setRingtone(mChannel.getSound());
- mRingtone.setEnabled(isChannelConfigurable(mChannel));
- mRingtone.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- mChannel.setSound((Uri) newValue, mChannel.getAudioAttributes());
- mChannel.lockFields(NotificationChannel.USER_LOCKED_SOUND);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return false;
- }
- });
- }
-
- private void setupBlock() {
- View switchBarContainer = LayoutInflater.from(
- getPrefContext()).inflate(R.layout.styled_switch_bar, null);
- mSwitchBar = switchBarContainer.findViewById(R.id.switch_bar);
- mSwitchBar.show();
- mSwitchBar.setDisabledByAdmin(mSuspendedAppsAdmin);
- mSwitchBar.setChecked(mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
- mSwitchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
- @Override
- public void onSwitchChanged(Switch switchView, boolean isChecked) {
- int importance = 0;
- if (mShowLegacyChannelConfig) {
- importance = isChecked ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_NONE;
- mImportanceToggle.setChecked(importance == IMPORTANCE_UNSPECIFIED);
- } else {
- importance = isChecked ? IMPORTANCE_LOW : IMPORTANCE_NONE;
- mImportance.setSummary(getImportanceSummary(importance));
- }
- mChannel.setImportance(importance);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
- }
- });
-
- mBlockBar = new LayoutPreference(getPrefContext(), switchBarContainer);
- mBlockBar.setOrder(ORDER_FIRST);
- mBlockBar.setKey(KEY_BLOCK);
- getPreferenceScreen().addPreference(mBlockBar);
-
- if (!isChannelBlockable(mChannel)) {
- setVisible(mBlockBar, false);
- }
-
- setupBlockDesc(R.string.channel_notifications_off_desc);
- }
-
- private void setupImportance() {
- mImportance = findPreference(KEY_IMPORTANCE);
- Bundle channelArgs = new Bundle();
- channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
- channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
- channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
- mImportance.setEnabled(mSuspendedAppsAdmin == null && isChannelConfigurable(mChannel));
- // Set up intent to show importance selection only if this setting is enabled.
- if (mImportance.isEnabled()) {
- Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
- ChannelImportanceSettings.class.getName(),
- channelArgs, null, R.string.notification_importance_title, null,
- false, getMetricsCategory());
- mImportance.setIntent(channelIntent);
- }
- mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
- }
-
- private String getImportanceSummary(int importance) {
- String title;
- String summary = null;
- switch (importance) {
- case IMPORTANCE_UNSPECIFIED:
- title = getContext().getString(R.string.notification_importance_unspecified);
- break;
- case NotificationManager.IMPORTANCE_MIN:
- title = getContext().getString(R.string.notification_importance_min_title);
- summary = getContext().getString(R.string.notification_importance_min);
- break;
- case NotificationManager.IMPORTANCE_LOW:
- title = getContext().getString(R.string.notification_importance_low_title);
- summary = getContext().getString(R.string.notification_importance_low);
- break;
- case NotificationManager.IMPORTANCE_DEFAULT:
- title = getContext().getString(R.string.notification_importance_default_title);
- if (hasValidSound(mChannel)) {
- summary = getContext().getString(R.string.notification_importance_default);
- } else {
- summary = getContext().getString(R.string.notification_importance_low);
- }
- break;
- case NotificationManager.IMPORTANCE_HIGH:
- case NotificationManager.IMPORTANCE_MAX:
- title = getContext().getString(R.string.notification_importance_high_title);
- if (hasValidSound(mChannel)) {
- summary = getContext().getString(R.string.notification_importance_high);
- } else {
- summary = getContext().getString(R.string.notification_importance_high_silent);
- }
- break;
- default:
- return "";
- }
-
- if (summary != null) {
- return getContext().getString(R.string.notification_importance_divider, title, summary);
- } else {
- return title;
- }
- }
-
- @Override
- public boolean onPreferenceTreeClick(Preference preference) {
- if (preference instanceof RingtonePreference) {
- mRingtone.onPrepareRingtonePickerIntent(mRingtone.getIntent());
- startActivityForResult(preference.getIntent(), 200);
- return true;
- }
- return super.onPreferenceTreeClick(preference);
+ updatePreferenceStates();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (mRingtone != null) {
- mRingtone.onActivityResult(requestCode, resultCode, data);
- }
- if (mChannel != null) {
- mImportance.setSummary(getImportanceSummary(mChannel.getImportance()));
+ for (NotificationPreferenceController controller : mControllers) {
+ if (controller instanceof PreferenceManager.OnActivityResultListener) {
+ ((PreferenceManager.OnActivityResultListener) controller)
+ .onActivityResult(requestCode, resultCode, data);
+ }
}
}
- boolean canPulseLight() {
- if (!getResources()
- .getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
- return false;
- }
- return Settings.System.getInt(getContentResolver(),
- Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
+ @Override
+ protected String getLogTag() {
+ return TAG;
}
- void updateDependents(boolean banned) {
- PreferenceGroup parent;
- if (mShowLegacyChannelConfig) {
- parent = getPreferenceScreen();
- setVisible(mImportanceToggle, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- } else {
- setVisible(mAdvanced, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- setVisible(mAdvanced, mLights, checkCanBeVisible(
- NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight());
- setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
- setVisible(mRingtone, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
- parent = mAdvanced;
- }
- setVisible(parent, mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- setVisible(parent, mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
- || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
- && mDndVisualEffectsSuppressed));
- setVisible(parent, mVisibilityOverride, isLockScreenSecure()
- &&checkCanBeVisible(NotificationManager.IMPORTANCE_LOW));
- setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
- if (mAppLink != null) {
- setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- }
- if (mFooter != null) {
- setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
- }
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.channel_notification_settings;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ mControllers = new ArrayList<>();
+ mControllers.add(new HeaderPreferenceController(context, this));
+ mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
+ mControllers.add(new ImportancePreferenceController(context));
+ mControllers.add(new AllowSoundPreferenceController(
+ context, mImportanceListener, mBackend));
+ mControllers.add(new SoundPreferenceController(context, this,
+ mImportanceListener, mBackend));
+ mControllers.add(new VibrationPreferenceController(context, mBackend));
+ mControllers.add(new AppLinkPreferenceController(context));
+ mControllers.add(new DescriptionPreferenceController(context));
+ mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context),
+ mBackend));
+ mControllers.add(new LightsPreferenceController(context, mBackend));
+ mControllers.add(new BadgePreferenceController(context, mBackend));
+ mControllers.add(new DndPreferenceController(context, getLifecycle(), mBackend));
+ mControllers.add(new NotificationsOffPreferenceController(context));
+ return new ArrayList<>(mControllers);
}
}
diff --git a/src/com/android/settings/notification/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/DeletedChannelsPreferenceController.java
new file mode 100644
index 0000000..16eb9ed
--- /dev/null
+++ b/src/com/android/settings/notification/DeletedChannelsPreferenceController.java
@@ -0,0 +1,61 @@
+/*
+ * 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 android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class DeletedChannelsPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String KEY_DELETED = "deleted";
+
+ public DeletedChannelsPreferenceController(Context context, NotificationBackend backend) {
+ super(context, backend);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_DELETED;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ // only visible on app screen
+ if (mChannel != null || hasValidGroup()) {
+ return false;
+ }
+
+ return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null) {
+ int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
+ preference.setTitle(mContext.getResources().getQuantityString(
+ R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
+ }
+ preference.setEnabled(false);
+ preference.setSelectable(false);
+ }
+}
diff --git a/src/com/android/settings/notification/DescriptionPreferenceController.java b/src/com/android/settings/notification/DescriptionPreferenceController.java
new file mode 100644
index 0000000..fae2f5f
--- /dev/null
+++ b/src/com/android/settings/notification/DescriptionPreferenceController.java
@@ -0,0 +1,67 @@
+/*
+ * 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 android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class DescriptionPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String KEY_DESC = "desc";
+
+ public DescriptionPreferenceController(Context context) {
+ super(context, null);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_DESC;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mChannel == null && !hasValidGroup()) {
+ return false;
+ }
+ if (mChannel != null && !TextUtils.isEmpty(mChannel.getDescription())) {
+ return true;
+ }
+ if (hasValidGroup() && !TextUtils.isEmpty(mChannelGroup.getDescription())) {
+ return true;
+ }
+ return false;
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null) {
+ if (mChannel != null) {
+ preference.setTitle(mChannel.getDescription());
+ } else if (hasValidGroup()) {
+ preference.setTitle(mChannelGroup.getDescription());
+ }
+ }
+ preference.setEnabled(false);
+ preference.setSelectable(false);
+ }
+}
diff --git a/src/com/android/settings/notification/DndPreferenceController.java b/src/com/android/settings/notification/DndPreferenceController.java
new file mode 100644
index 0000000..af60401
--- /dev/null
+++ b/src/com/android/settings/notification/DndPreferenceController.java
@@ -0,0 +1,86 @@
+/*
+ * 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.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class DndPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
+ LifecycleObserver, OnResume {
+
+ private static final String KEY_BYPASS_DND = "bypass_dnd";
+ private boolean mVisualEffectsSuppressed;
+
+ public DndPreferenceController(Context context, Lifecycle lifecycle,
+ NotificationBackend backend) {
+ super(context, backend);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ NotificationManager.Policy policy = mNm.getNotificationPolicy();
+ mVisualEffectsSuppressed = policy != null && policy.suppressedVisualEffects != 0;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BYPASS_DND;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
+ || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW)
+ && mVisualEffectsSuppressed);
+ }
+
+ public void updateState(Preference preference) {
+ if (mChannel != null) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ pref.setDisabledByAdmin(mAdmin);
+ pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
+ pref.setChecked(mChannel.canBypassDnd());
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ final boolean bypassZenMode = (Boolean) newValue;
+ mChannel.setBypassDnd(bypassZenMode);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
+ saveChannel();
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java
new file mode 100644
index 0000000..3d51b25
--- /dev/null
+++ b/src/com/android/settings/notification/HeaderPreferenceController.java
@@ -0,0 +1,100 @@
+/*
+ * 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 static com.android.settings.widget.EntityHeaderController.PREF_KEY_APP_HEADER;
+
+import android.content.Context;
+import android.support.v14.preference.PreferenceFragment;
+import android.support.v7.preference.Preference;
+import android.text.BidiFormatter;
+import android.text.SpannableStringBuilder;
+import android.text.TextUtils;
+import android.view.View;
+
+import com.android.settings.R;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.widget.EntityHeaderController;
+
+public class HeaderPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private final PreferenceFragment mFragment;
+
+ public HeaderPreferenceController(Context context, PreferenceFragment fragment) {
+ super(context, null);
+ mFragment = fragment;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY_APP_HEADER;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mAppRow != null;
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null && mFragment != null) {
+ LayoutPreference pref = (LayoutPreference) preference;
+ EntityHeaderController controller = EntityHeaderController
+ .newInstance(mFragment.getActivity(), mFragment,
+ pref.findViewById(R.id.entity_header));
+ pref = controller.setIcon(mAppRow.icon)
+ .setLabel(getLabel())
+ .setSummary(getSummary())
+ .setPackageName(mAppRow.pkg)
+ .setUid(mAppRow.uid)
+ .setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
+ EntityHeaderController.ActionType.ACTION_NONE)
+ .setHasAppInfoLink(true)
+ .done(mFragment.getActivity(), mContext);
+ pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
+ }
+ }
+
+ CharSequence getLabel() {
+ return mChannel != null ? mChannel.getName()
+ : mChannelGroup != null && mChannelGroup.getGroup() != null
+ ? mChannelGroup.getGroup().getName()
+ : mAppRow.label;
+ }
+
+ CharSequence getSummary() {
+ if (mChannel != null) {
+ if (mChannelGroup != null && mChannelGroup.getGroup() != null
+ && !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
+ final SpannableStringBuilder summary = new SpannableStringBuilder();
+ BidiFormatter bidi = BidiFormatter.getInstance();
+ summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
+ summary.append(bidi.unicodeWrap(mContext.getText(
+ R.string.notification_header_divider_symbol_with_spaces)));
+ summary.append(bidi.unicodeWrap(mChannelGroup.getGroup().getName().toString()));
+ return summary;
+ } else {
+ return mAppRow.label;
+ }
+ } else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
+ return mAppRow.label;
+ } else {
+ return "";
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/ImportancePreferenceController.java b/src/com/android/settings/notification/ImportancePreferenceController.java
new file mode 100644
index 0000000..ba47c54
--- /dev/null
+++ b/src/com/android/settings/notification/ImportancePreferenceController.java
@@ -0,0 +1,127 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.applications.AppInfoBase;
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class ImportancePreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String KEY_IMPORTANCE = "importance";
+
+ // Ironically doesn't take an importance listener because the importance is not changed
+ // by this controller's preference but by the screen it links to.
+ public ImportancePreferenceController(Context context) {
+ super(context, null);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_IMPORTANCE;
+ }
+
+ private int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mChannel == null) {
+ return false;
+ }
+ return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow!= null && mChannel != null) {
+ preference.setEnabled(mAdmin == null && isChannelConfigurable());
+ Bundle channelArgs = new Bundle();
+ channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mAppRow.uid);
+ channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
+ channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
+ if (preference.isEnabled()) {
+ Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
+ ChannelImportanceSettings.class.getName(),
+ channelArgs, null, R.string.notification_importance_title, null,
+ false, getMetricsCategory());
+ preference.setIntent(channelIntent);
+ preference.setSummary(getImportanceSummary(mContext, mChannel));
+ }
+ }
+ }
+
+ protected static String getImportanceSummary(Context context, NotificationChannel channel) {
+ String title;
+ String summary = null;
+ int importance = channel.getImportance();
+ switch (importance) {
+ case IMPORTANCE_UNSPECIFIED:
+ title = context.getString(R.string.notification_importance_unspecified);
+ break;
+ case NotificationManager.IMPORTANCE_MIN:
+ title = context.getString(R.string.notification_importance_min_title);
+ summary = context.getString(R.string.notification_importance_min);
+ break;
+ case NotificationManager.IMPORTANCE_LOW:
+ title = context.getString(R.string.notification_importance_low_title);
+ summary = context.getString(R.string.notification_importance_low);
+ break;
+ case NotificationManager.IMPORTANCE_DEFAULT:
+ title = context.getString(R.string.notification_importance_default_title);
+ if (SoundPreferenceController.hasValidSound(channel)) {
+ summary = context.getString(R.string.notification_importance_default);
+ } else {
+ summary = context.getString(R.string.notification_importance_low);
+ }
+ break;
+ case NotificationManager.IMPORTANCE_HIGH:
+ case NotificationManager.IMPORTANCE_MAX:
+ title = context.getString(R.string.notification_importance_high_title);
+ if (SoundPreferenceController.hasValidSound(channel)) {
+ summary = context.getString(R.string.notification_importance_high);
+ } else {
+ summary = context.getString(R.string.notification_importance_high_silent);
+ }
+ break;
+ default:
+ return "";
+ }
+
+ if (summary != null) {
+ return context.getString(R.string.notification_importance_divider, title, summary);
+ } else {
+ return title;
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/LightsPreferenceController.java b/src/com/android/settings/notification/LightsPreferenceController.java
new file mode 100644
index 0000000..230c3e2
--- /dev/null
+++ b/src/com/android/settings/notification/LightsPreferenceController.java
@@ -0,0 +1,85 @@
+/*
+ * 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.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class LightsPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_LIGHTS = "lights";
+
+ public LightsPreferenceController(Context context, NotificationBackend backend) {
+ super(context, backend);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_LIGHTS;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mChannel == null) {
+ return false;
+ }
+ return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight()
+ && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
+ }
+
+ public void updateState(Preference preference) {
+ if (mChannel != null) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ pref.setDisabledByAdmin(mAdmin);
+ pref.setEnabled(isChannelConfigurable() && !pref.isDisabledByAdmin());
+ pref.setChecked(mChannel.shouldShowLights());
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ final boolean lights = (Boolean) newValue;
+ mChannel.enableLights(lights);
+ saveChannel();
+ }
+ return true;
+ }
+
+ boolean canPulseLight() {
+ if (!mContext.getResources()
+ .getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) {
+ return false;
+ }
+ return Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
+ }
+
+}
diff --git a/src/com/android/settings/notification/NotificationFooterPreference.java b/src/com/android/settings/notification/NotificationFooterPreference.java
new file mode 100644
index 0000000..d44ebee
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationFooterPreference.java
@@ -0,0 +1,57 @@
+/*
+ * 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 android.support.v4.content.res.TypedArrayUtils;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.text.method.LinkMovementMethod;
+import android.util.AttributeSet;
+import android.widget.TextView;
+
+import com.android.settingslib.R;
+
+/**
+ * FooterPreference that can have any key or ordering.
+ */
+public class NotificationFooterPreference extends Preference {
+
+ public NotificationFooterPreference(Context context, AttributeSet attrs) {
+ super(context, attrs, TypedArrayUtils.getAttr(
+ context, R.attr.footerPreferenceStyle, android.R.attr.preferenceStyle));
+ init();
+ }
+
+ public NotificationFooterPreference(Context context) {
+ this(context, null);
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+ TextView title = holder.itemView.findViewById(android.R.id.title);
+ title.setMovementMethod(new LinkMovementMethod());
+ title.setClickable(false);
+ title.setLongClickable(false);
+ }
+
+ private void init() {
+ setIcon(R.drawable.ic_info_outline_24dp);
+ setSelectable(false);
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java
new file mode 100644
index 0000000..b1ef69e
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationPreferenceController.java
@@ -0,0 +1,188 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import android.annotation.Nullable;
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserManager;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.Log;
+
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import java.util.Objects;
+
+/**
+ * Parent class for preferences appearing on notification setting pages at the app,
+ * notification channel group, or notification channel level.
+ */
+public abstract class NotificationPreferenceController extends AbstractPreferenceController
+{
+ private static final String TAG = "ChannelPrefContr";
+ @Nullable protected NotificationChannel mChannel;
+ @Nullable protected NotificationChannelGroupWrapper mChannelGroup;
+ protected RestrictedLockUtils.EnforcedAdmin mAdmin;
+ protected NotificationBackend.AppRow mAppRow;
+ protected final NotificationManager mNm;
+ protected final NotificationBackend mBackend;
+ protected final Context mContext;
+ protected final UserManager mUm;
+ protected final PackageManager mPm;
+ protected Preference mPreference;
+
+ public NotificationPreferenceController(Context context, NotificationBackend backend) {
+ super(context);
+ mContext = context;
+ mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ mBackend = backend;
+ mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ mPm = mContext.getPackageManager();
+ }
+
+ /**
+ * Returns true if field's parent object is not blocked.
+ */
+ @Override
+ public boolean isAvailable() {
+ if (mAppRow == null) {
+ return false;
+ }
+ if (mAppRow.banned) {
+ return false;
+ }
+ if (mChannel != null) {
+ return mChannel.getImportance() != IMPORTANCE_NONE;
+ }
+ if (mChannelGroup != null && mChannelGroup.getGroup() == null) {
+ return !mChannelGroup.isBlocked();
+ }
+ return true;
+ }
+
+ /**
+ * Displays or removes preference in this controller.
+ */
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ if (isAvailable()) {
+ final Preference preference = screen.findPreference(getPreferenceKey());
+ if (mPreference != null && preference == null) {
+ screen.addPreference(mPreference);
+ }
+ if (preference != null) {
+ mPreference = preference;
+ }
+ if (this instanceof Preference.OnPreferenceChangeListener) {
+ mPreference.setOnPreferenceChangeListener(
+ (Preference.OnPreferenceChangeListener) this);
+ }
+ } else {
+ findAndRemovePreference(screen, getPreferenceKey());
+ }
+ }
+
+ // finds the preference recursively and removes it from its parent
+ private void findAndRemovePreference(PreferenceGroup prefGroup, String key) {
+ final int preferenceCount = prefGroup.getPreferenceCount();
+ for (int i = preferenceCount - 1; i >= 0; i--) {
+ final Preference preference = prefGroup.getPreference(i);
+ final String curKey = preference.getKey();
+
+ if (curKey != null && curKey.equals(key)) {
+ mPreference = preference;
+ prefGroup.removePreference(preference);
+ }
+
+ if (preference instanceof PreferenceGroup) {
+ findAndRemovePreference((PreferenceGroup) preference, key);
+ }
+ }
+ }
+
+ protected void onResume(NotificationBackend.AppRow appRow,
+ @Nullable NotificationChannel channel, @Nullable NotificationChannelGroupWrapper group,
+ RestrictedLockUtils.EnforcedAdmin admin) {
+ mAppRow = appRow;
+ mChannel = channel;
+ mChannelGroup = group;
+ mAdmin = admin;
+ }
+
+ protected boolean checkCanBeVisible(int minImportanceVisible) {
+ if (mChannel == null) {
+ Log.w(TAG, "No channel");
+ return false;
+ }
+
+ int importance = mChannel.getImportance();
+ if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
+ return true;
+ }
+ return importance >= minImportanceVisible;
+ }
+
+ protected void saveChannel() {
+ if (mChannel != null && mAppRow != null) {
+ mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel);
+ }
+ }
+
+ protected boolean isChannelConfigurable() {
+ if (mChannel != null && mAppRow != null) {
+ return !Objects.equals(mChannel.getId(), mAppRow.lockedChannelId);
+ }
+ return false;
+ }
+
+ protected boolean isChannelBlockable() {
+ if (mChannel != null && mAppRow != null) {
+ if (!mAppRow.systemApp) {
+ return true;
+ }
+
+ return mChannel.isBlockableSystem()
+ || mChannel.getImportance() == IMPORTANCE_NONE;
+ }
+ return false;
+ }
+
+ protected boolean isChannelGroupBlockable() {
+ if (mChannelGroup != null && mChannelGroup.getGroup() == null && mAppRow != null) {
+ if (!mAppRow.systemApp) {
+ return true;
+ }
+
+ return mChannelGroup.isBlocked();
+ }
+ return false;
+ }
+
+ protected boolean hasValidGroup() {
+ return mChannelGroup != null && mChannelGroup.getGroup() != null;
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 3f366e1..9afb618 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -27,10 +27,15 @@
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.LayoutPreference;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.SwitchBar;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;
import android.app.Notification;
@@ -53,10 +58,12 @@
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
@@ -68,66 +75,30 @@
import java.util.Comparator;
import java.util.List;
-abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
+abstract public class NotificationSettingsBase extends DashboardFragment {
private static final String TAG = "NotifiSettingsBase";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
- private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
- = new Intent(Intent.ACTION_MAIN)
- .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
-
- protected static final int ORDER_FIRST = -500;
- protected static final int ORDER_LAST = 1000;
-
- protected static final String KEY_APP_LINK = "app_link";
- protected static final String KEY_HEADER = "header";
- protected static final String KEY_BLOCK = "block";
- protected static final String KEY_BADGE = "badge";
- protected static final String KEY_BYPASS_DND = "bypass_dnd";
- protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
- protected static final String KEY_BLOCKED_DESC = "block_desc";
- protected static final String KEY_ALLOW_SOUND = "allow_sound";
-
protected PackageManager mPm;
- protected UserManager mUm;
protected NotificationBackend mBackend = new NotificationBackend();
- protected LockPatternUtils mLockPatternUtils;
protected NotificationManager mNm;
protected Context mContext;
- protected boolean mCreated;
+
protected int mUid;
protected int mUserId;
protected String mPkg;
protected PackageInfo mPkgInfo;
- protected RestrictedSwitchPreference mBadge;
- protected RestrictedSwitchPreference mPriority;
- protected RestrictedDropDownPreference mVisibilityOverride;
- protected RestrictedSwitchPreference mImportanceToggle;
- protected LayoutPreference mBlockBar;
- protected SwitchBar mSwitchBar;
- protected FooterPreference mBlockedDesc;
- protected Preference mAppLink;
-
protected EnforcedAdmin mSuspendedAppsAdmin;
- protected boolean mDndVisualEffectsSuppressed;
-
- protected NotificationChannelGroup mChannelGroup;
+ protected NotificationChannelGroupWrapper mChannelGroup;
protected NotificationChannel mChannel;
protected NotificationBackend.AppRow mAppRow;
- protected boolean mShowLegacyChannelConfig = false;
+ protected boolean mShowLegacyChannelConfig = false;
protected boolean mListeningToPackageRemove;
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (DEBUG) Log.d(TAG, "onActivityCreated mCreated=" + mCreated);
- if (mCreated) {
- Log.w(TAG, "onActivityCreated: ignoring duplicate call");
- return;
- }
- mCreated = true;
- }
+ protected List<NotificationPreferenceController> mControllers = new ArrayList<>();
+ protected List<Preference> mDynamicPreferences = new ArrayList<>();
+ protected ImportanceListener mImportanceListener = new ImportanceListener();
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -143,7 +114,6 @@
}
mPm = getPackageManager();
- mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mNm = NotificationManager.from(mContext);
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
@@ -187,35 +157,41 @@
return;
}
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
+ if (mAppRow == null) {
+ Log.w(TAG, "Can't load package");
+ finish();
+ return;
+ }
+ collectConfigActivities();
Bundle args = getArguments();
mChannel = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_ID)) ?
mBackend.getChannel(mPkg, mUid, args.getString(Settings.EXTRA_CHANNEL_ID)) : null;
- mChannelGroup = (args != null && args.containsKey(Settings.EXTRA_CHANNEL_GROUP_ID)) ?
- mBackend.getGroupWithChannels(mPkg, mUid,
+ NotificationChannelGroup group =
+ (args != null && args.containsKey(Settings.EXTRA_CHANNEL_GROUP_ID))
+ ? mBackend.getGroupWithChannels(mPkg, mUid,
args.getString(Settings.EXTRA_CHANNEL_GROUP_ID))
- : null;
+ : null;
+ if (group != null) {
+ mChannelGroup = new NotificationChannelGroupWrapper(group);
+ }
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
- NotificationManager.Policy policy = mNm.getNotificationPolicy();
- mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
- mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
- mContext, mPkg, mUserId);
- }
+ mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
+ || (mChannel != null
+ && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()));
- protected void setVisible(Preference p, boolean visible) {
- setVisible(getPreferenceScreen(), p, visible);
- }
-
- protected void setVisible(PreferenceGroup parent, Preference p, boolean visible) {
- final boolean isVisible = parent.findPreference(p.getKey()) != null;
- if (isVisible == visible) return;
- if (visible) {
- parent.addPreference(p);
- } else {
- parent.removePreference(p);
+ if (mShowLegacyChannelConfig) {
+ mChannel = mBackend.getChannel(
+ mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
+ }
+ if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
+ group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
+ if (group != null) {
+ mChannelGroup = new NotificationChannelGroupWrapper(group);
+ }
}
}
@@ -224,49 +200,38 @@
getActivity().finish();
}
- private List<ResolveInfo> queryNotificationConfigActivities() {
- if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
- + APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
+ protected void collectConfigActivities() {
+ Intent intent = new Intent(Intent.ACTION_MAIN)
+ .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)
+ .setPackage(mAppRow.pkg);
final List<ResolveInfo> resolveInfos = mPm.queryIntentActivities(
- APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
+ intent,
0 //PackageManager.MATCH_DEFAULT_ONLY
);
- return resolveInfos;
- }
-
- protected void collectConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows) {
- final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities();
- applyConfigActivities(rows, resolveInfos);
- }
-
- private void applyConfigActivities(ArrayMap<String, NotificationBackend.AppRow> rows,
- List<ResolveInfo> resolveInfos) {
- if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
- + (resolveInfos.size() == 0 ? " ;_;" : ""));
+ if (DEBUG) {
+ Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
+ + (resolveInfos.size() == 0 ? " ;_;" : ""));
+ }
for (ResolveInfo ri : resolveInfos) {
final ActivityInfo activityInfo = ri.activityInfo;
final ApplicationInfo appInfo = activityInfo.applicationInfo;
- final NotificationBackend.AppRow row = rows.get(appInfo.packageName);
- if (row == null) {
- if (DEBUG) Log.v(TAG, "Ignoring notification preference activity ("
- + activityInfo.name + ") for unknown package "
- + activityInfo.packageName);
+ if (mAppRow.settingsIntent != null) {
+ if (DEBUG) {
+ Log.d(TAG, "Ignoring duplicate notification preference activity ("
+ + activityInfo.name + ") for package "
+ + activityInfo.packageName);
+ }
continue;
}
- if (row.settingsIntent != null) {
- if (DEBUG) Log.v(TAG, "Ignoring duplicate notification preference activity ("
- + activityInfo.name + ") for package "
- + activityInfo.packageName);
- continue;
- }
- row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
+ mAppRow.settingsIntent = intent
+ .setPackage(null)
.setClassName(activityInfo.packageName, activityInfo.name);
if (mChannel != null) {
- row.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
+ mAppRow.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
}
if (mChannelGroup != null) {
- row.settingsIntent.putExtra(
- Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getId());
+ mAppRow.settingsIntent.putExtra(
+ Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getGroup().getId());
}
}
}
@@ -292,134 +257,6 @@
return null;
}
- protected void addAppLinkPref() {
- if (mAppRow.settingsIntent != null && mAppLink == null) {
- addPreferencesFromResource(R.xml.inapp_notification_settings);
- mAppLink = findPreference(KEY_APP_LINK);
- mAppLink.setIntent(mAppRow.settingsIntent);
- }
- }
-
- protected void populateDefaultChannelPrefs() {
- if (mPkgInfo != null && mChannel != null) {
- addPreferencesFromResource(R.xml.legacy_channel_notification_settings);
- setupPriorityPref(mChannel.canBypassDnd());
- setupVisOverridePref(mChannel.getLockscreenVisibility());
- setupImportanceToggle();
- setupBadge();
- }
- mSwitchBar.setChecked(!mAppRow.banned
- && mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
- }
-
- abstract void setupBadge();
-
- abstract void updateDependents(boolean banned);
-
- // 'allow sound'
- private void setupImportanceToggle() {
- mImportanceToggle = (RestrictedSwitchPreference) findPreference(KEY_ALLOW_SOUND);
- mImportanceToggle.setDisabledByAdmin(mSuspendedAppsAdmin);
- mImportanceToggle.setEnabled(isChannelConfigurable(mChannel)
- && !mImportanceToggle.isDisabledByAdmin());
- mImportanceToggle.setChecked(mChannel.getImportance() >= IMPORTANCE_DEFAULT
- || mChannel.getImportance() == IMPORTANCE_UNSPECIFIED);
- mImportanceToggle.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final int importance =
- ((Boolean) newValue ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_LOW);
- mChannel.setImportance(importance);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- updateDependents(mChannel.getImportance() == IMPORTANCE_NONE);
- return true;
- }
- });
- }
-
- protected void setupPriorityPref(boolean priority) {
- mPriority = (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
- mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
- mPriority.setEnabled(isChannelConfigurable(mChannel) && !mPriority.isDisabledByAdmin());
- mPriority.setChecked(priority);
- mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean bypassZenMode = (Boolean) newValue;
- mChannel.setBypassDnd(bypassZenMode);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- }
-
- protected void setupVisOverridePref(int sensitive) {
- mVisibilityOverride =
- (RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
- ArrayList<CharSequence> entries = new ArrayList<>();
- ArrayList<CharSequence> values = new ArrayList<>();
-
- mVisibilityOverride.clearRestrictedItems();
- if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
- final String summaryShowEntry =
- getString(R.string.lock_screen_notifications_summary_show);
- final String summaryShowEntryValue =
- Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
- entries.add(summaryShowEntry);
- values.add(summaryShowEntryValue);
- setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
- DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
- | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
- }
-
- final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
- final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
- entries.add(summaryHideEntry);
- values.add(summaryHideEntryValue);
- setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
- DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
- entries.add(getString(R.string.lock_screen_notifications_summary_disable));
- values.add(Integer.toString(Notification.VISIBILITY_SECRET));
- mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
- mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
-
- if (sensitive == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) {
- mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
- } else {
- mVisibilityOverride.setValue(Integer.toString(sensitive));
- }
- mVisibilityOverride.setSummary("%s");
-
- mVisibilityOverride.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- int sensitive = Integer.parseInt((String) newValue);
- if (sensitive == getGlobalVisibility()) {
- sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
- }
- mChannel.setLockscreenVisibility(sensitive);
- mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
- mBackend.updateChannel(mPkg, mUid, mChannel);
- return true;
- }
- });
- mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
- }
-
- protected void setupBlockDesc(int summaryResId) {
- mBlockedDesc = new FooterPreference(getPrefContext());
- mBlockedDesc.setSelectable(false);
- mBlockedDesc.setTitle(summaryResId);
- mBlockedDesc.setEnabled(false);
- mBlockedDesc.setOrder(50);
- mBlockedDesc.setKey(KEY_BLOCKED_DESC);
- getPreferenceScreen().addPreference(mBlockedDesc);
- }
-
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
final NotificationChannel channel, String summary) {
MasterSwitchPreference channelPref = new MasterSwitchPreference(
@@ -447,7 +284,7 @@
public boolean onPreferenceChange(Preference preference,
Object o) {
boolean value = (Boolean) o;
- int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
+ int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
channel.setImportance(importance);
channel.lockFields(
NotificationChannel.USER_LOCKED_IMPORTANCE);
@@ -461,105 +298,48 @@
return channelPref;
}
- protected boolean checkCanBeVisible(int minImportanceVisible) {
- int importance = mChannel.getImportance();
- if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
- return true;
- }
- return importance >= minImportanceVisible;
- }
-
- protected String getImportanceSummary(NotificationChannel channel) {
- switch (channel.getImportance()) {
- case NotificationManager.IMPORTANCE_UNSPECIFIED:
- return getContext().getString(R.string.notification_importance_unspecified);
- case NotificationManager.IMPORTANCE_NONE:
- return getContext().getString(R.string.notification_toggle_off);
- case NotificationManager.IMPORTANCE_MIN:
- return getContext().getString(R.string.notification_importance_min);
- case NotificationManager.IMPORTANCE_LOW:
- return getContext().getString(R.string.notification_importance_low);
- case NotificationManager.IMPORTANCE_DEFAULT:
- if (hasValidSound(channel)) {
- return getContext().getString(R.string.notification_importance_default);
- } else { // Silent
- return getContext().getString(R.string.notification_importance_low);
- }
- case NotificationManager.IMPORTANCE_HIGH:
- case NotificationManager.IMPORTANCE_MAX:
- default:
- if (hasValidSound(channel)) {
- return getContext().getString(R.string.notification_importance_high);
- } else { // Silent
- return getContext().getString(R.string.notification_importance_high_silent);
- }
- }
- }
-
- private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
- CharSequence entryValue, int keyguardNotificationFeatures) {
- RestrictedLockUtils.EnforcedAdmin admin =
- RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
- mContext, keyguardNotificationFeatures, mUserId);
- if (admin != null) {
- RestrictedDropDownPreference.RestrictedItem item =
- new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
- mVisibilityOverride.addRestrictedItem(item);
- }
- }
-
- private int getGlobalVisibility() {
- int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
- if (!getLockscreenNotificationsEnabled()) {
- globalVis = Notification.VISIBILITY_SECRET;
- } else if (!getLockscreenAllowPrivateNotifications()) {
- globalVis = Notification.VISIBILITY_PRIVATE;
- }
- return globalVis;
- }
-
- private boolean getLockscreenNotificationsEnabled() {
- return Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
- }
-
- private boolean getLockscreenAllowPrivateNotifications() {
- return Settings.Secure.getInt(getContentResolver(),
- Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
- }
-
- protected boolean isLockScreenSecure() {
- if (mLockPatternUtils == null) {
- mLockPatternUtils = new LockPatternUtils(getActivity());
- }
- boolean lockscreenSecure = mLockPatternUtils.isSecure(UserHandle.myUserId());
- UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
- if (parentUser != null){
- lockscreenSecure |= mLockPatternUtils.isSecure(parentUser.id);
- }
-
- return lockscreenSecure;
- }
-
protected boolean isChannelConfigurable(NotificationChannel channel) {
- return !channel.getId().equals(mAppRow.lockedChannelId);
+ if (channel != null && mAppRow != null) {
+ return !channel.getId().equals(mAppRow.lockedChannelId);
+ }
+ return false;
}
protected boolean isChannelBlockable(NotificationChannel channel) {
- if (!mAppRow.systemApp) {
- return true;
- }
+ if (channel != null && mAppRow != null) {
+ if (!mAppRow.systemApp) {
+ return true;
+ }
- return channel.isBlockableSystem()
- || channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
+ return channel.isBlockableSystem()
+ || channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
+ }
+ return false;
}
protected boolean isChannelGroupBlockable(NotificationChannelGroup group) {
- if (!mAppRow.systemApp) {
- return true;
- }
+ if (group != null && mAppRow != null) {
+ if (!mAppRow.systemApp) {
+ return true;
+ }
- return group.isBlocked();
+ return group.isBlocked();
+ }
+ return false;
+ }
+
+ protected void setVisible(Preference p, boolean visible) {
+ setVisible(getPreferenceScreen(), p, visible);
+ }
+
+ protected void setVisible(PreferenceGroup parent, Preference p, boolean visible) {
+ final boolean isVisible = parent.findPreference(p.getKey()) != null;
+ if (isVisible == visible) return;
+ if (visible) {
+ parent.addPreference(p);
+ } else {
+ parent.removePreference(p);
+ }
}
protected void startListeningToPackageRemove() {
@@ -589,8 +369,10 @@
public void onReceive(Context context, Intent intent) {
String packageName = intent.getData().getSchemeSpecificPart();
if (mPkgInfo == null || TextUtils.equals(mPkgInfo.packageName, packageName)) {
- if (DEBUG) Log.d(TAG, "Package (" + packageName + ") removed. Removing"
- + "NotificationSettingsBase.");
+ if (DEBUG) {
+ Log.d(TAG, "Package (" + packageName + ") removed. Removing"
+ + "NotificationSettingsBase.");
+ }
onPackageRemoved();
}
}
@@ -604,7 +386,27 @@
return left.getId().compareTo(right.getId());
};
- boolean hasValidSound(NotificationChannel channel) {
- return channel.getSound() != null && !Uri.EMPTY.equals(channel.getSound());
+ protected class ImportanceListener {
+ protected void onImportanceChanged() {
+ final PreferenceScreen screen = getPreferenceScreen();
+ for (NotificationPreferenceController controller : mControllers) {
+ controller.displayPreference(screen);
+ }
+ updatePreferenceStates();
+
+ boolean hideDynamicFields = false;
+ if (mAppRow == null || mAppRow.banned) {
+ hideDynamicFields = true;
+ } else {
+ if (mChannel != null) {
+ hideDynamicFields = mChannel.getImportance() == IMPORTANCE_NONE;
+ } else if (mChannelGroup != null) {
+ hideDynamicFields = mChannelGroup.isBlocked();
+ }
+ }
+ for (Preference preference : mDynamicPreferences) {
+ setVisible(getPreferenceScreen(), preference, !hideDynamicFields);
+ }
+ }
}
}
diff --git a/src/com/android/settings/notification/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/NotificationsOffPreferenceController.java
new file mode 100644
index 0000000..74591cf
--- /dev/null
+++ b/src/com/android/settings/notification/NotificationsOffPreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * 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 android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.widget.FooterPreference;
+
+public class NotificationsOffPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin {
+
+ private static final String KEY_BLOCKED_DESC = "block_desc";
+
+ public NotificationsOffPreferenceController(Context context) {
+ super(context, null);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BLOCKED_DESC;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (mAppRow == null) {
+ return false;
+ }
+ // Available only when other controllers are unavailable - this UI replaces the UI that
+ // would give more detailed notification controls.
+ return !super.isAvailable();
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow != null) {
+ if (mChannel != null) {
+ preference.setTitle(R.string.channel_notifications_off_desc);
+ } else if (mChannelGroup != null && mChannelGroup.getGroup() == null) {
+ preference.setTitle(R.string.channel_group_notifications_off_desc);
+ } else {
+ preference.setTitle(R.string.app_notifications_off_desc);
+ }
+ }
+ preference.setEnabled(false);
+ preference.setSelectable(false);
+ }
+}
diff --git a/src/com/android/settings/notification/SoundPreferenceController.java b/src/com/android/settings/notification/SoundPreferenceController.java
new file mode 100644
index 0000000..e4414b6
--- /dev/null
+++ b/src/com/android/settings/notification/SoundPreferenceController.java
@@ -0,0 +1,119 @@
+/*
+ * 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.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.preference.PreferenceManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.core.PreferenceControllerMixin;
+
+public class SoundPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
+ PreferenceManager.OnActivityResultListener {
+
+ private static final String KEY_SOUND = "ringtone";
+ private final SettingsPreferenceFragment mFragment;
+ private final NotificationSettingsBase.ImportanceListener mListener;
+ private NotificationSoundPreference mPreference;
+ protected static final int CODE = 200;
+
+ public SoundPreferenceController(Context context, SettingsPreferenceFragment hostFragment,
+ NotificationSettingsBase.ImportanceListener importanceListener,
+ NotificationBackend backend) {
+ super(context, backend);
+ mFragment = hostFragment;
+ mListener = importanceListener;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_SOUND;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mChannel == null) {
+ return false;
+ }
+ return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
+ && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ mPreference = (NotificationSoundPreference) screen.findPreference(getPreferenceKey());
+ }
+
+ public void updateState(Preference preference) {
+ if (mAppRow!= null && mChannel != null) {
+ NotificationSoundPreference pref = (NotificationSoundPreference) preference;
+ pref.setEnabled(mAdmin == null && isChannelConfigurable());
+ pref.setRingtone(mChannel.getSound());
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ mChannel.setSound((Uri) newValue, mChannel.getAudioAttributes());
+ saveChannel();
+ }
+ return true;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (KEY_SOUND.equals(preference.getKey()) && mFragment != null) {
+ NotificationSoundPreference pref = (NotificationSoundPreference) preference;
+ pref.onPrepareRingtonePickerIntent(pref.getIntent());
+ mFragment.startActivityForResult(preference.getIntent(), CODE);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (CODE == requestCode) {
+ if (mPreference != null) {
+ mPreference.onActivityResult(requestCode, resultCode, data);
+ }
+ // the importance hasn't changed, but the importance description might as a result of
+ // user's selection.
+ mListener.onImportanceChanged();
+ return true;
+ }
+ return false;
+ }
+
+ protected static boolean hasValidSound(NotificationChannel channel) {
+ return channel != null
+ && channel.getSound() != null && !Uri.EMPTY.equals(channel.getSound());
+ }
+}
diff --git a/src/com/android/settings/notification/VibrationPreferenceController.java b/src/com/android/settings/notification/VibrationPreferenceController.java
new file mode 100644
index 0000000..f9b786d
--- /dev/null
+++ b/src/com/android/settings/notification/VibrationPreferenceController.java
@@ -0,0 +1,73 @@
+/*
+ * 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.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Vibrator;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+public class VibrationPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_VIBRATE = "vibrate";
+ private final Vibrator mVibrator;
+
+ public VibrationPreferenceController(Context context, NotificationBackend backend) {
+ super(context, backend);
+ mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_VIBRATE;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable() || mChannel == null) {
+ return false;
+ }
+ return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
+ && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())
+ && mVibrator != null
+ && mVibrator.hasVibrator();
+ }
+
+ public void updateState(Preference preference) {
+ if (mChannel != null) {
+ RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
+ pref.setDisabledByAdmin(mAdmin);
+ pref.setEnabled(!pref.isDisabledByAdmin() && isChannelConfigurable());
+ pref.setChecked(mChannel.shouldVibrate());
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ final boolean vibrate = (Boolean) newValue;
+ mChannel.enableVibration(vibrate);
+ saveChannel();
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/notification/VisibilityPreferenceController.java b/src/com/android/settings/notification/VisibilityPreferenceController.java
new file mode 100644
index 0000000..76caac0
--- /dev/null
+++ b/src/com/android/settings/notification/VisibilityPreferenceController.java
@@ -0,0 +1,165 @@
+/*
+ * 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.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.service.notification.NotificationListenerService;
+import android.support.v7.preference.Preference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.RestrictedLockUtils;
+
+import java.util.ArrayList;
+
+public class VisibilityPreferenceController extends NotificationPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "ChannelVisPrefContr";
+ private static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
+ private LockPatternUtils mLockPatternUtils;
+
+ public VisibilityPreferenceController(Context context, LockPatternUtils utils,
+ NotificationBackend backend) {
+ super(context, backend);
+ mLockPatternUtils = utils;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_VISIBILITY_OVERRIDE;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ if (!super.isAvailable()) {
+ return false;
+ }
+ if (mChannel == null || mAppRow.banned) {
+ return false;
+ }
+ return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
+ }
+
+ public void updateState(Preference preference) {
+ if (mChannel != null && mAppRow != null) {
+ RestrictedDropDownPreference pref = (RestrictedDropDownPreference) preference;
+ ArrayList<CharSequence> entries = new ArrayList<>();
+ ArrayList<CharSequence> values = new ArrayList<>();
+
+ pref.clearRestrictedItems();
+ if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
+ final String summaryShowEntry =
+ mContext.getString(R.string.lock_screen_notifications_summary_show);
+ final String summaryShowEntryValue =
+ Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
+ entries.add(summaryShowEntry);
+ values.add(summaryShowEntryValue);
+ setRestrictedIfNotificationFeaturesDisabled(pref, summaryShowEntry,
+ summaryShowEntryValue,
+ DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
+ | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
+ }
+
+ final String summaryHideEntry =
+ mContext.getString(R.string.lock_screen_notifications_summary_hide);
+ final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
+ entries.add(summaryHideEntry);
+ values.add(summaryHideEntryValue);
+ setRestrictedIfNotificationFeaturesDisabled(pref,
+ summaryHideEntry, summaryHideEntryValue,
+ DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+ entries.add(mContext.getString(R.string.lock_screen_notifications_summary_disable));
+ values.add(Integer.toString(Notification.VISIBILITY_SECRET));
+ pref.setEntries(entries.toArray(new CharSequence[entries.size()]));
+ pref.setEntryValues(values.toArray(new CharSequence[values.size()]));
+
+ if (mChannel.getLockscreenVisibility()
+ == NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) {
+ pref.setValue(Integer.toString(getGlobalVisibility()));
+ } else {
+ pref.setValue(Integer.toString(mChannel.getLockscreenVisibility()));
+ }
+ pref.setSummary("%s");
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ int sensitive = Integer.parseInt((String) newValue);
+ if (sensitive == getGlobalVisibility()) {
+ sensitive = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
+ }
+ mChannel.setLockscreenVisibility(sensitive);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
+ saveChannel();
+ }
+ return true;
+ }
+
+ private void setRestrictedIfNotificationFeaturesDisabled(RestrictedDropDownPreference pref,
+ CharSequence entry, CharSequence entryValue, int keyguardNotificationFeatures) {
+ RestrictedLockUtils.EnforcedAdmin admin =
+ RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
+ mContext, keyguardNotificationFeatures, mAppRow.userId);
+ if (admin != null) {
+ RestrictedDropDownPreference.RestrictedItem item =
+ new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
+ pref.addRestrictedItem(item);
+ }
+ }
+
+ private int getGlobalVisibility() {
+ int globalVis = NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
+ if (!getLockscreenNotificationsEnabled()) {
+ globalVis = Notification.VISIBILITY_SECRET;
+ } else if (!getLockscreenAllowPrivateNotifications()) {
+ globalVis = Notification.VISIBILITY_PRIVATE;
+ }
+ return globalVis;
+ }
+
+ private boolean getLockscreenNotificationsEnabled() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0;
+ }
+
+ private boolean getLockscreenAllowPrivateNotifications() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0;
+ }
+
+ protected boolean isLockScreenSecure() {
+ boolean lockscreenSecure = mLockPatternUtils.isSecure(UserHandle.myUserId());
+ UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
+ if (parentUser != null){
+ lockscreenSecure |= mLockPatternUtils.isSecure(parentUser.id);
+ }
+
+ return lockscreenSecure;
+ }
+
+}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 05fd3c9..c524346 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -64,7 +64,6 @@
import com.android.settings.location.ScanningSettings;
import com.android.settings.network.NetworkDashboardFragment;
import com.android.settings.nfc.PaymentSettings;
-import com.android.settings.notification.ChannelImportanceSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
@@ -158,7 +157,6 @@
addIndex(TtsEnginePreferenceFragment.class);
addIndex(MagnificationPreferenceFragment.class);
addIndex(AccessibilityShortcutPreferenceFragment.class);
- addIndex(ChannelImportanceSettings.class);
addIndex(DreamSettings.class);
addIndex(SupportDashboardActivity.class);
addIndex(AutomaticStorageManagerSettings.class);
diff --git a/src/com/android/settings/users/ProfileUpdateReceiver.java b/src/com/android/settings/users/ProfileUpdateReceiver.java
index d532089..80fa10a 100644
--- a/src/com/android/settings/users/ProfileUpdateReceiver.java
+++ b/src/com/android/settings/users/ProfileUpdateReceiver.java
@@ -38,13 +38,13 @@
// Profile changed, lets get the photo and write to user manager
new Thread() {
public void run() {
- Utils.copyMeProfilePhoto(context, null);
+ UserSettings.copyMeProfilePhoto(context, null);
copyProfileName(context);
}
}.start();
}
- static void copyProfileName(Context context) {
+ private static void copyProfileName(Context context) {
SharedPreferences prefs = context.getSharedPreferences("profile", Context.MODE_PRIVATE);
if (prefs.contains(KEY_PROFILE_NAME_COPIED_ONCE)) {
return;
@@ -55,7 +55,8 @@
String profileName = Utils.getMeProfileName(context, false /* partial name */);
if (profileName != null && profileName.length() > 0) {
um.setUserName(userId, profileName);
- // Flag that we've written the profile one time at least. No need to do it in the future.
+ // Flag that we've written the profile one time at least. No need to do it in the
+ // future.
prefs.edit().putBoolean(KEY_PROFILE_NAME_COPIED_ONCE, true).commit();
}
}
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 642f289..906c9d4 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -30,7 +30,9 @@
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
@@ -38,7 +40,10 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.ContactsContract;
import android.provider.Settings.Global;
+import android.support.annotation.VisibleForTesting;
+import android.support.annotation.WorkerThread;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceGroup;
@@ -53,6 +58,7 @@
import android.widget.SimpleAdapter;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.util.UserIcons;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
@@ -68,6 +74,8 @@
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.drawable.CircleFramedDrawable;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -134,7 +142,8 @@
private boolean mShouldUpdateUserList = true;
private final Object mUserLock = new Object();
private UserManager mUserManager;
- private SparseArray<Bitmap> mUserIcons = new SparseArray<Bitmap>();
+ private SparseArray<Bitmap> mUserIcons = new SparseArray<>();
+ private static SparseArray<Bitmap> sDarkDefaultUserBitmapCache = new SparseArray<>();
private EditUserInfoController mEditUserInfoController =
new EditUserInfoController();
@@ -324,7 +333,7 @@
UserInfo user = mUserManager.getUserInfo(UserHandle.myUserId());
if (user.iconPath == null || user.iconPath.equals("")) {
// Assign profile photo.
- Utils.copyMeProfilePhoto(getActivity(), user);
+ copyMeProfilePhoto(getActivity(), user);
}
return user.name;
}
@@ -397,7 +406,7 @@
private UserInfo createRestrictedProfile() {
UserInfo newUserInfo = mUserManager.createRestrictedProfile(mAddingUserName);
- if (newUserInfo != null && !Utils.assignDefaultPhoto(getActivity(), newUserInfo.id)) {
+ if (newUserInfo != null && !assignDefaultPhoto(getActivity(), newUserInfo.id)) {
return null;
}
return newUserInfo;
@@ -405,7 +414,7 @@
private UserInfo createTrustedUser() {
UserInfo newUserInfo = mUserManager.createUser(mAddingUserName, 0);
- if (newUserInfo != null && !Utils.assignDefaultPhoto(getActivity(), newUserInfo.id)) {
+ if (newUserInfo != null && !assignDefaultPhoto(getActivity(), newUserInfo.id)) {
return null;
}
return newUserInfo;
@@ -914,7 +923,7 @@
for (int userId : values[0]) {
Bitmap bitmap = mUserManager.getUserIcon(userId);
if (bitmap == null) {
- bitmap = Utils.getDefaultUserIconAsBitmap(userId);
+ bitmap = getDefaultUserIconAsBitmap(userId);
}
mUserIcons.append(userId, bitmap);
}
@@ -925,7 +934,7 @@
private Drawable getEncircledDefaultIcon() {
if (mDefaultIconDrawable == null) {
- mDefaultIconDrawable = encircle(Utils.getDefaultUserIconAsBitmap(UserHandle.USER_NULL));
+ mDefaultIconDrawable = encircle(getDefaultUserIconAsBitmap(UserHandle.USER_NULL));
}
return mDefaultIconDrawable;
}
@@ -1025,6 +1034,65 @@
mMePreference.setTitle(label);
}
+ /**
+ * Returns a default user icon (as a {@link Bitmap}) for the given user.
+ *
+ * Note that for guest users, you should pass in {@code UserHandle.USER_NULL}.
+ * @param userId the user id or {@code UserHandle.USER_NULL} for a non-user specific icon
+ */
+ private static Bitmap getDefaultUserIconAsBitmap(int userId) {
+ Bitmap bitmap = null;
+ // Try finding the corresponding bitmap in the dark bitmap cache
+ bitmap = sDarkDefaultUserBitmapCache.get(userId);
+ if (bitmap == null) {
+ bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId, false));
+ // Save it to cache
+ sDarkDefaultUserBitmapCache.put(userId, bitmap);
+ }
+ return bitmap;
+ }
+
+ /**
+ * Assign the default photo to user with {@paramref userId}
+ * @param context used to get the {@link UserManager}
+ * @param userId used to get the icon bitmap
+ * @return true if assign photo successfully, false if failed
+ */
+ @VisibleForTesting
+ static boolean assignDefaultPhoto(Context context, int userId) {
+ if (context == null) {
+ return false;
+ }
+ UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ Bitmap bitmap = getDefaultUserIconAsBitmap(userId);
+ um.setUserIcon(userId, bitmap);
+
+ return true;
+ }
+
+ @WorkerThread
+ static void copyMeProfilePhoto(Context context, UserInfo user) {
+ Uri contactUri = ContactsContract.Profile.CONTENT_URI;
+
+ int userId = user != null ? user.id : UserHandle.myUserId();
+
+ InputStream avatarDataStream = ContactsContract.Contacts.openContactPhotoInputStream(
+ context.getContentResolver(),
+ contactUri, true);
+ // If there's no profile photo, assign a default avatar
+ if (avatarDataStream == null) {
+ assignDefaultPhoto(context, userId);
+ return;
+ }
+
+ UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ Bitmap icon = BitmapFactory.decodeStream(avatarDataStream);
+ um.setUserIcon(userId, icon);
+ try {
+ avatarDataStream.close();
+ } catch (IOException ioe) { }
+ }
+
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
index ca37b64..77142ed 100644
--- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
+++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java
@@ -51,9 +51,9 @@
@VisibleForTesting
void startFallbackSuggestion() {
// fall back to default wallpaper picker
- Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(), null, null, 0,
- R.string.wallpaper_suggestion_title, null,
- MetricsProto.MetricsEvent.DASHBOARD_SUMMARY);
+ Utils.startWithFragment(this, WallpaperTypeSettings.class.getName(),
+ R.string.wallpaper_suggestion_title, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY,
+ Intent.FLAG_ACTIVITY_FORWARD_RESULT);
}
@VisibleForTesting
diff --git a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
index 1ca8ac7..3c95785 100644
--- a/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
+++ b/src/com/android/settings/wallpaper/WallpaperTypeSettings.java
@@ -16,6 +16,7 @@
package com.android.settings.wallpaper;
+import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -67,7 +68,7 @@
// Add Preference items for each of the matching activities
for (ResolveInfo info : rList) {
Preference pref = new Preference(getPrefContext());
- Intent prefIntent = new Intent(intent);
+ Intent prefIntent = new Intent(intent).addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
prefIntent.setComponent(new ComponentName(
info.activityInfo.packageName, info.activityInfo.name));
pref.setIntent(prefIntent);
@@ -79,6 +80,16 @@
}
}
+ @Override
+ public boolean onPreferenceTreeClick(Preference preference) {
+ if (preference.getIntent() == null) {
+ return super.onPreferenceTreeClick(preference);
+ }
+ startActivity(preference.getIntent());
+ finish();
+ return true;
+ }
+
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
diff --git a/src/com/android/settings/wifi/ConnectedAccessPointPreference.java b/src/com/android/settings/wifi/ConnectedAccessPointPreference.java
new file mode 100644
index 0000000..6b9c788
--- /dev/null
+++ b/src/com/android/settings/wifi/ConnectedAccessPointPreference.java
@@ -0,0 +1,78 @@
+/*
+ * 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.wifi;
+
+import android.content.Context;
+import android.support.annotation.DrawableRes;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.View;
+
+import com.android.settings.R;
+import com.android.settingslib.wifi.AccessPoint;
+import com.android.settingslib.wifi.AccessPointPreference;
+
+/**
+ * An AP preference for the currently connected AP
+ */
+public class ConnectedAccessPointPreference extends AccessPointPreference implements
+ View.OnClickListener {
+
+ private OnGearClickListener mOnGearClickListener;
+
+ public ConnectedAccessPointPreference(AccessPoint accessPoint, Context context,
+ UserBadgeCache cache, @DrawableRes int iconResId, boolean forSavedNetworks) {
+ super(accessPoint, context, cache, iconResId, forSavedNetworks);
+ }
+
+ public void setOnGearClickListener(OnGearClickListener l) {
+ mOnGearClickListener = l;
+ notifyChanged();
+ }
+
+ @Override
+ protected int getSecondTargetResId() {
+ return R.layout.preference_widget_gear;
+ }
+
+ @Override
+ protected boolean shouldHideSecondTarget() {
+ return mOnGearClickListener == null;
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+ final View gear = holder.findViewById(R.id.settings_button);
+ if (gear != null) {
+ gear.setOnClickListener(this);
+ }
+ setDividerVisibility(holder, View.VISIBLE);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.settings_button) {
+ if (mOnGearClickListener != null) {
+ mOnGearClickListener.onGearClick(this);
+ }
+ }
+ }
+
+ public interface OnGearClickListener {
+ void onGearClick(ConnectedAccessPointPreference p);
+ }
+}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 5490889..14db3d3 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -782,7 +782,7 @@
continue;
}
LongPressAccessPointPreference preference =
- createLongPressActionPointPreference(accessPoint);
+ createLongPressAccessPointPreference(accessPoint);
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
@@ -817,10 +817,17 @@
}
@NonNull
- private LongPressAccessPointPreference createLongPressActionPointPreference(
+ private LongPressAccessPointPreference createLongPressAccessPointPreference(
AccessPoint accessPoint) {
return new LongPressAccessPointPreference(accessPoint, getPrefContext(), mUserBadgeCache,
- false, R.drawable.ic_wifi_signal_0, this);
+ false /* forSavedNetworks */, R.drawable.ic_wifi_signal_0, this);
+ }
+
+ @NonNull
+ private ConnectedAccessPointPreference createConnectedAccessPointPreference(
+ AccessPoint accessPoint) {
+ return new ConnectedAccessPointPreference(accessPoint, getPrefContext(), mUserBadgeCache,
+ R.drawable.ic_wifi_signal_0, false /* forSavedNetworks */);
}
/**
@@ -859,7 +866,7 @@
// Else same AP is connected, simply refresh the connected access point preference
// (first and only access point in this category).
- ((LongPressAccessPointPreference) mConnectedAccessPointPreferenceCategory.getPreference(0))
+ ((AccessPointPreference) mConnectedAccessPointPreferenceCategory.getPreference(0))
.refresh();
return true;
}
@@ -869,20 +876,19 @@
* {@link #mConnectedAccessPointPreferenceCategory}.
*/
private void addConnectedAccessPointPreference(AccessPoint connectedAp) {
- final LongPressAccessPointPreference pref = getOrCreatePreference(connectedAp);
+ final ConnectedAccessPointPreference pref = createConnectedAccessPointPreference(
+ connectedAp);
// Launch details page on click.
- pref.setOnPreferenceClickListener(preference -> {
- // Save the state of the current access point in the bundle so that we can restore it
- // in the Wifi Network Details Fragment
+ pref.setOnGearClickListener(l -> {
pref.getAccessPoint().saveWifiState(pref.getExtras());
SettingsActivity activity = (SettingsActivity) WifiSettings.this.getActivity();
activity.startPreferencePanel(this,
WifiNetworkDetailsFragment.class.getName(), pref.getExtras(),
R.string.wifi_details_title, null, null, 0);
- return true;
});
+
pref.refresh();
mConnectedAccessPointPreferenceCategory.addPreference(pref);
@@ -893,15 +899,6 @@
}
}
- private LongPressAccessPointPreference getOrCreatePreference(AccessPoint ap) {
- LongPressAccessPointPreference pref = (LongPressAccessPointPreference)
- getCachedPreference(AccessPointPreference.generatePreferenceKey(ap));
- if (pref == null) {
- pref = createLongPressActionPointPreference(ap);
- }
- return pref;
- }
-
/** Removes all preferences and hide the {@link #mConnectedAccessPointPreferenceCategory}. */
private void removeConnectedAccessPointPreference() {
mConnectedAccessPointPreferenceCategory.removeAll();
@@ -1093,7 +1090,7 @@
public void run() {
Object tag = accessPoint.getTag();
if (tag != null) {
- ((LongPressAccessPointPreference) tag).refresh();
+ ((AccessPointPreference) tag).refresh();
}
}
});
@@ -1102,7 +1099,7 @@
@Override
public void onLevelChanged(AccessPoint accessPoint) {
- ((LongPressAccessPointPreference) accessPoint.getTag()).onLevelChanged();
+ ((AccessPointPreference) accessPoint.getTag()).onLevelChanged();
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
diff --git a/src/com/android/settings/wrapper/NotificationChannelGroupWrapper.java b/src/com/android/settings/wrapper/NotificationChannelGroupWrapper.java
new file mode 100644
index 0000000..dbfff1a
--- /dev/null
+++ b/src/com/android/settings/wrapper/NotificationChannelGroupWrapper.java
@@ -0,0 +1,64 @@
+/*
+ * 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.wrapper;
+
+import android.app.NotificationChannelGroup;
+
+/**
+ * Wrapper for {@link NotificationChannelGroup} until roboletric supports O MR1.
+ */
+public class NotificationChannelGroupWrapper {
+
+ private final NotificationChannelGroup mGroup;
+
+ public NotificationChannelGroupWrapper(NotificationChannelGroup group) {
+ mGroup = group;
+ }
+
+ /**
+ * Get the real group object so we can call APIs directly on it.
+ */
+ public NotificationChannelGroup getGroup() {
+ return mGroup;
+ }
+
+ public String getDescription() {
+ if (mGroup != null) {
+ return mGroup.getDescription();
+ }
+ return null;
+ }
+
+ public void setDescription(String desc) {
+ if (mGroup != null) {
+ mGroup.setDescription(desc);
+ }
+ }
+
+ public boolean isBlocked() {
+ if (mGroup != null) {
+ return mGroup.isBlocked();
+ }
+ return true;
+ }
+
+ public void setBlocked(boolean blocked) {
+ if (mGroup != null) {
+ mGroup.setBlocked(blocked);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index fda5c8a..6704fc3 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -7,6 +7,10 @@
com.android.settings.development.featureflags.FeatureFlagsDashboard
com.android.settings.development.qstile.DevelopmentTileConfigFragment
com.android.settings.deviceinfo.StorageProfileFragment
+com.android.settings.notification.ChannelNotificationSettings
+com.android.settings.notification.ChannelImportanceSettings
+com.android.settings.notification.ChannelGroupNotificationSettings
+com.android.settings.notification.AppNotificationSettings
com.android.settings.wifi.details.WifiNetworkDetailsFragment
com.android.settings.wifi.p2p.WifiP2pSettings
com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionCamera
@@ -15,4 +19,4 @@
com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages
com.android.settings.enterprise.EnterpriseSetDefaultAppsListFragment
com.android.settings.wifi.tether.WifiTetherSettings
-com.android.settings.wifi.SavedAccessPointsWifiSettings
+com.android.settings.wifi.SavedAccessPointsWifiSettings
\ No newline at end of file
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index 4ea5338..c2a084c 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -19,8 +19,6 @@
com.android.settings.applications.VrListenerSettings
com.android.settings.inputmethod.UserDictionaryList
com.android.settings.datausage.DataSaverSummary
-com.android.settings.notification.ChannelNotificationSettings
-com.android.settings.notification.ChannelGroupNotificationSettings
com.android.settings.datausage.AppDataUsage
com.android.settings.datausage.DataPlanUsageSummary
com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard
@@ -55,7 +53,6 @@
com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment
com.android.settings.print.PrintServiceSettingsFragment
com.android.settings.wfd.WifiDisplaySettings
-com.android.settings.notification.AppNotificationSettings
com.android.settings.deviceinfo.PrivateVolumeSettings
com.android.settings.users.AppRestrictionsFragment
com.android.settings.deviceinfo.PrivateVolumeUnmount
@@ -82,4 +79,4 @@
com.android.settings.TetherSettings
com.android.settings.ApnEditor
com.android.settings.UserCredentialsSettings
-com.android.settings.TestingSettings
+com.android.settings.TestingSettings
\ No newline at end of file
diff --git a/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider b/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider
index b329072..a71b040 100644
--- a/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider
+++ b/tests/robotests/assets/grandfather_not_sharing_pref_controllers_with_search_provider
@@ -1 +1 @@
-com.android.settings.fuelgauge.PowerUsageSummary
+com.android.settings.fuelgauge.PowerUsageSummary
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/internal/app/NightDisplayController.java b/tests/robotests/src/com/android/internal/app/ColorDisplayController.java
similarity index 97%
rename from tests/robotests/src/com/android/internal/app/NightDisplayController.java
rename to tests/robotests/src/com/android/internal/app/ColorDisplayController.java
index b20de68..74e7d8a 100644
--- a/tests/robotests/src/com/android/internal/app/NightDisplayController.java
+++ b/tests/robotests/src/com/android/internal/app/ColorDisplayController.java
@@ -19,7 +19,7 @@
* Fake controller to make robolectric test compile. Should be removed when Robolectric supports
* API 25.
*/
-public class NightDisplayController {
+public class ColorDisplayController {
public static final int AUTO_MODE_DISABLED = 0;
public static final int AUTO_MODE_CUSTOM = 1;
diff --git a/tests/robotests/src/com/android/settings/UtilsTest.java b/tests/robotests/src/com/android/settings/UtilsTest.java
index ca02c1d..f813457 100644
--- a/tests/robotests/src/com/android/settings/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/UtilsTest.java
@@ -47,9 +47,8 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UtilsTest {
- private static final String TIME_DESCRIPTION = "1 day 20 hours 30 minutes";
private static final String PACKAGE_NAME = "com.android.app";
- private Context mContext;
+
@Mock
private WifiManager wifiManager;
@Mock
@@ -60,6 +59,7 @@
private DevicePolicyManagerWrapper mDevicePolicyManager;
@Mock
private UserManager mUserManager;
+ private Context mContext;
@Before
public void setUp() {
@@ -100,12 +100,6 @@
}
@Test
- public void testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash() {
- // Should not crash here
- assertThat(Utils.assignDefaultPhoto(null, 0)).isFalse();
- }
-
- @Test
public void testFormatElapsedTime_WithSeconds_ShowSeconds() {
final double testMillis = 5 * DateUtils.MINUTE_IN_MILLIS + 30 * DateUtils.SECOND_IN_MILLIS;
final String expectedTime = "5m 30s";
diff --git a/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
index 583a004..35d1194 100644
--- a/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/applications/LayoutPreferenceTest.java
@@ -24,11 +24,10 @@
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
-import android.view.View;
import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
@@ -37,19 +36,17 @@
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LayoutPreferenceTest {
private Context mContext;
private LayoutPreference mPreference;
- private View mRootView;
private PreferenceViewHolder mHolder;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mPreference = new LayoutPreference(mContext, R.layout.two_action_buttons);
- mRootView = mPreference.mRootView;
mHolder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext)
.inflate(R.layout.layout_preference_frame, null, false));
}
diff --git a/tests/robotests/src/com/android/settings/applications/ManageDomainUrlsTest.java b/tests/robotests/src/com/android/settings/applications/ManageDomainUrlsTest.java
new file mode 100644
index 0000000..3e89647
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/ManageDomainUrlsTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.applications;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.applications.ApplicationsState;
+
+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(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class ManageDomainUrlsTest {
+
+ @Mock
+ private ApplicationsState.AppEntry mAppEntry;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test
+ public void domainAppPreferenceShouldUseAppPreferenceLayout() {
+ mAppEntry.info = new ApplicationInfo();
+ mAppEntry.info.packageName = "com.android.settings.test";
+ final ManageDomainUrls.DomainAppPreference pref =
+ new ManageDomainUrls.DomainAppPreference(mContext, null, mAppEntry);
+
+ assertThat(pref.getLayoutResource()).isEqualTo(R.layout.preference_app);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
index fb9bb9f..dc3d27a 100644
--- a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
@@ -25,7 +25,7 @@
import android.os.Bundle;
-import com.android.internal.app.NightDisplayController;
+import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.TestConfig;
@@ -52,7 +52,7 @@
private ColorModePreferenceFragment mFragment;
@Mock
- private NightDisplayController mController;
+ private ColorDisplayController mController;
@Before
public void setup() {
@@ -88,7 +88,7 @@
@Test
public void getKey_natural() {
Mockito.when(mController.getColorMode()).thenReturn(
- NightDisplayController.COLOR_MODE_NATURAL);
+ ColorDisplayController.COLOR_MODE_NATURAL);
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
@@ -98,7 +98,7 @@
@Test
public void getKey_boosted() {
Mockito.when(mController.getColorMode()).thenReturn(
- NightDisplayController.COLOR_MODE_BOOSTED);
+ ColorDisplayController.COLOR_MODE_BOOSTED);
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
@@ -108,7 +108,7 @@
@Test
public void getKey_saturated() {
Mockito.when(mController.getColorMode()).thenReturn(
- NightDisplayController.COLOR_MODE_SATURATED);
+ ColorDisplayController.COLOR_MODE_SATURATED);
assertThat(mFragment.getDefaultKey())
.isEqualTo(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
@@ -118,21 +118,21 @@
@Test
public void setKey_natural() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
- verify(mController).setColorMode(NightDisplayController.COLOR_MODE_NATURAL);
+ verify(mController).setColorMode(ColorDisplayController.COLOR_MODE_NATURAL);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_boosted() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
- verify(mController).setColorMode(NightDisplayController.COLOR_MODE_BOOSTED);
+ verify(mController).setColorMode(ColorDisplayController.COLOR_MODE_BOOSTED);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_saturated() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
- verify(mController).setColorMode(NightDisplayController.COLOR_MODE_SATURATED);
+ verify(mController).setColorMode(ColorDisplayController.COLOR_MODE_SATURATED);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java
new file mode 100644
index 0000000..9ba8706
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/AllowSoundPreferenceControllerTest.java
@@ -0,0 +1,244 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class AllowSoundPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ @Mock
+ NotificationSettingsBase.ImportanceListener mImportanceListener;
+
+ private AllowSoundPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController =
+ spy(new AllowSoundPreferenceController(mContext, mImportanceListener, mBackend));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedSwitchPreference.class));
+ mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, mock(NotificationChannel.class), null, null);
+ assertFalse(mController.isAvailable());
+
+ mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppCreatedChannel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something new");
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_configurable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_checkedForHighImportanceChannel() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_checkedForUnspecifiedImportanceChannel() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_notCheckedForLowImportanceChannel() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+ pref.setChecked(true);
+ mController.onPreferenceChange(pref, true);
+
+ assertEquals(IMPORTANCE_UNSPECIFIED, mController.mChannel.getImportance());
+ verify(mImportanceListener, times(1)).onImportanceChanged();
+ }
+
+ @Test
+ public void testOnPreferenceChange_off() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ pref.setChecked(false);
+ mController.onPreferenceChange(pref, false);
+
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ assertEquals(IMPORTANCE_LOW, mController.mChannel.getImportance());
+ verify(mImportanceListener, times(1)).onImportanceChanged();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java
new file mode 100644
index 0000000..b440704
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/AppLinkPreferenceControllerTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class AppLinkPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private AppLinkPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new AppLinkPreferenceController(mContext));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notNoIntent() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.settingsIntent = new Intent("test");
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ Intent intent = new Intent("action");
+ appRow.settingsIntent = intent;
+ mController.onResume(appRow, null, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertEquals(intent, pref.getIntent());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java
new file mode 100644
index 0000000..6052478
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java
@@ -0,0 +1,298 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class BadgePreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private BadgePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new BadgePreferenceController(mContext, mBackend));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedSwitchPreference.class));
+ mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_channel_notIfAppOff() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = false;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfOffGlobally() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
+
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_app() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ mController.onResume(appRow, null, null, null);
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
+
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_channel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
+
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_channelNotConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_channel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = "a";
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.canShowBadge()).thenReturn(true);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isChecked());
+
+ when(channel.canShowBadge()).thenReturn(false);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(pref);
+
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_app() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ mController.onResume(appRow, null, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+
+ appRow.showBadge = false;
+ mController.onResume(appRow, null, null, null);
+
+ mController.updateState(pref);
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on_channel() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
+ channel.setShowBadge(false);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, true);
+ assertTrue(channel.canShowBadge());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceChange_off_channel() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ channel.setShowBadge(true);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, false);
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ assertFalse(channel.canShowBadge());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on_app() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = false;
+ mController.onResume(appRow, null, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, true);
+
+ assertTrue(appRow.showBadge);
+ verify(mBackend, times(1)).setShowBadge(any(), anyInt(), eq(true));
+ }
+
+ @Test
+ public void testOnPreferenceChange_off_app() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.showBadge = true;
+ mController.onResume(appRow, null, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, false);
+
+ assertFalse(appRow.showBadge);
+ verify(mBackend, times(1)).setShowBadge(any(), anyInt(), eq(false));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java
new file mode 100644
index 0000000..9014f4e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java
@@ -0,0 +1,272 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.widget.SwitchBar;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class BlockPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ @Mock
+ NotificationSettingsBase.ImportanceListener mImportanceListener;
+
+ private BlockPreferenceController mController;
+ @Mock
+ private LayoutPreference mPreference;
+ private SwitchBar mSwitch;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new BlockPreferenceController(mContext, mImportanceListener, mBackend));
+ mSwitch = new SwitchBar(mContext);
+ when(mPreference.findViewById(R.id.switch_bar)).thenReturn(mSwitch);
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(LayoutPreference.class));
+ mController.onSwitchChanged(null, false);
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelNotBlockable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfGroupNotBlockable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ mController.onResume(appRow, null, mock(NotificationChannelGroupWrapper.class), null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppNotBlockable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ mController.onResume(appRow, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_systemApp() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_nonSystemApp() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = false;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_app() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+ mController.updateState(mPreference);
+
+ assertNotNull(mPreference.findViewById(R.id.switch_bar));
+
+ assertFalse(mSwitch.isChecked());
+
+ appRow.banned = false;
+ mController.onResume(appRow, null, null, null);
+ mController.updateState(mPreference);
+
+ assertTrue(mSwitch.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_group() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
+ when(group.isBlocked()).thenReturn(true);
+ mController.onResume(appRow, null, group, null);
+ mController.updateState(mPreference);
+
+ assertFalse(mSwitch.isChecked());
+
+ appRow.banned = true;
+ mController.onResume(appRow, null, group, null);
+ when(group.isBlocked()).thenReturn(true);
+ mController.updateState(mPreference);
+
+ assertFalse(mSwitch.isChecked());
+
+ appRow.banned = false;
+ mController.onResume(appRow, null, group, null);
+ when(group.isBlocked()).thenReturn(false);
+ mController.updateState(mPreference);
+
+ assertTrue(mSwitch.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_channelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ assertFalse(mSwitch.isChecked());
+
+ appRow.banned = true;
+ channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ assertFalse(mSwitch.isChecked());
+
+ appRow.banned = false;
+ channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ assertTrue(mSwitch.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_noCrashIfCalledTwice() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+ mController.updateState(mPreference);
+ }
+
+ @Test
+ public void testUpdateState_doesNotResetImportance() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ assertEquals(IMPORTANCE_LOW, channel.getImportance());
+ }
+
+ @Test
+ public void testOnSwitchChanged_channel_default() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ mController.onSwitchChanged(null, false);
+ assertEquals(IMPORTANCE_NONE, channel.getImportance());
+
+ mController.onSwitchChanged(null, true);
+ assertEquals(IMPORTANCE_UNSPECIFIED, channel.getImportance());
+
+ verify(mBackend, times(2)).updateChannel(any(), anyInt(), any());
+
+ }
+
+ @Test
+ public void testOnSwitchChanged_channel_nonDefault() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+ mController.updateState(mPreference);
+
+ mController.onSwitchChanged(null, false);
+ assertEquals(IMPORTANCE_NONE, channel.getImportance());
+
+ mController.onSwitchChanged(null, true);
+ assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
+
+ verify(mBackend, times(2)).updateChannel(any(), anyInt(), any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
new file mode 100644
index 0000000..fd903f9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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 static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class DeletedChannelsPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private DeletedChannelsPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = new DeletedChannelsPreferenceController(mContext, mBackend);
+ }
+
+ @Test
+ public void noCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ }
+
+ @Test
+ public void isAvailable_appScreen_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_groupScreen_never() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ mController.onResume(appRow, null, mock(NotificationChannelGroupWrapper.class), null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_channelScreen_never() throws Exception {
+ mController.onResume(
+ new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_appScreen_notIfNoDeletedChannels() throws Exception {
+ when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
+ mController.onResume(new NotificationBackend.AppRow(), null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_appScreen() throws Exception {
+ when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
+ mController.onResume(new NotificationBackend.AppRow(), null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void updateState() throws Exception {
+ when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
+ mController.onResume(new NotificationBackend.AppRow(), null, null, null);
+
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+
+ verify(pref, times(1)).setEnabled(false);
+ verify(pref, times(1)).setSelectable(false);
+ verify(mBackend, times(1)).getDeletedChannelCount(any(), anyInt());
+ ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);
+ verify(pref, times(1)).setTitle(argumentCaptor.capture());
+ assertTrue(argumentCaptor.getValue().toString().contains("1"));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java
new file mode 100644
index 0000000..1776a9b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/DescriptionPreferenceControllerTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class DescriptionPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private DescriptionPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new DescriptionPreferenceController(mContext));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelGroupBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(true);
+ mController.onResume(appRow, null, group, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNoChannelDesc() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNoChannelGroupDesc() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
+ mController.onResume(appRow, null, group, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_channel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getDescription()).thenReturn("AAA");
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_channelGroup() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
+ when(group.getDescription()).thenReturn("something");
+ when(group.isBlocked()).thenReturn(false);
+ mController.onResume(appRow, null, group, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_channel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getDescription()).thenReturn("AAA");
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertEquals("AAA", pref.getTitle());
+ assertFalse(pref.isEnabled());
+ assertFalse(pref.isSelectable());
+ }
+
+ @Test
+ public void testUpdateState_channelGroup() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
+ when(group.getDescription()).thenReturn("something");
+ mController.onResume(appRow, null, group, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertEquals("something", pref.getTitle());
+ assertFalse(pref.isEnabled());
+ assertFalse(pref.isSelectable());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java
new file mode 100644
index 0000000..241e279
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/DndPreferenceControllerTest.java
@@ -0,0 +1,240 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class DndPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+ @Mock
+ private Lifecycle mLifecycle;
+
+ private DndPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new DndPreferenceController(mContext, mLifecycle, mBackend));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedSwitchPreference.class));
+ mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
+ mController.onResume();
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant_noVisEffects() throws Exception {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
+ mController.onResume();
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant_visEffects() throws Exception {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
+ mController.onResume();
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_importance_noVisEffects() throws Exception {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume();
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_important_visEffects() throws Exception {
+ when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
+ assertTrue(mNm.getNotificationPolicy().suppressedVisualEffects != 0);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
+ mController.onResume();
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_configurable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_bypassDnd() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.canBypassDnd()).thenReturn(true);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_noBypassDnd() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.canBypassDnd()).thenReturn(false);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, true);
+
+ assertTrue(channel.canBypassDnd());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceChange_off() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, false);
+
+ assertFalse(channel.canBypassDnd());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
new file mode 100644
index 0000000..385376f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Activity;
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v14.preference.PreferenceFragment;
+import android.view.View;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class HeaderPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private HeaderPreferenceController mController;
+ @Mock
+ private LayoutPreference mPreference;
+ @Mock
+ private View mView;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ PreferenceFragment fragment = mock(PreferenceFragment.class);
+ when(fragment.getContext()).thenReturn(mContext);
+ Activity activity = mock(Activity.class);
+ when(activity.getApplicationContext()).thenReturn(mContext);
+ when(fragment.getActivity()).thenReturn(activity);
+ mController = spy(new HeaderPreferenceController(mContext, fragment));
+ when(mPreference.findViewById(anyInt())).thenReturn(mView);
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(LayoutPreference.class));
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testGetLabel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.label = "bananas";
+ mController.onResume(appRow, null, null, null);
+ assertEquals(appRow.label, mController.getLabel());
+
+ NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
+ NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
+ mController.onResume(appRow, null, gWrapper, null);
+ assertEquals(group.getName(), mController.getLabel());
+
+ NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, gWrapper, null);
+ assertEquals(channel.getName(), mController.getLabel());
+ }
+
+ @Test
+ public void testGetSummary() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.label = "bananas";
+ mController.onResume(appRow, null, null, null);
+ assertEquals("", mController.getSummary());
+
+ NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
+ NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
+ mController.onResume(appRow, null, gWrapper, null);
+ assertEquals(appRow.label, mController.getSummary());
+
+ NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, gWrapper, null);
+ assertTrue(mController.getSummary().toString().contains(group.getName()));
+ assertTrue(mController.getSummary().toString().contains(appRow.label));
+
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.getSummary().toString().contains(group.getName()));
+ assertTrue(mController.getSummary().toString().contains(appRow.label));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
new file mode 100644
index 0000000..aebd6c9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class ImportancePreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private ImportancePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new ImportancePreferenceController(mContext));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ }
+
+ @Test
+ public void testIsAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, mock(NotificationChannel.class), null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notForDefaultChannel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ assertNull(pref.getIntent());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ assertNull(pref.getIntent());
+ }
+
+ @Test
+ public void testUpdateState() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isEnabled());
+ assertNotNull(pref.getIntent());
+ assertFalse(TextUtils.isEmpty(pref.getSummary()));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java
new file mode 100644
index 0000000..017cb88
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/LightsPreferenceControllerTest.java
@@ -0,0 +1,245 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.provider.Settings.System.NOTIFICATION_LIGHT_PULSE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O, shadows = {
+ SettingsShadowResources.class,
+})
+public class LightsPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private LightsPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new LightsPreferenceController(mContext, mBackend));
+
+ // By default allow lights
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_intrusiveNotificationLed, true);
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 1);
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedSwitchPreference.class));
+ mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
+ }
+
+ @Test
+ public void testIsAvailable_notIfConfigNotAllowed() throws Exception {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_intrusiveNotificationLed, false);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfSettingNotAllowed() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfDefaultChannel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_configurable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_lightsOn() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.shouldShowLights()).thenReturn(true);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_lightsOff() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.shouldShowLights()).thenReturn(false);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, true);
+
+ assertTrue(channel.shouldShowLights());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceChange_off() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, false);
+
+ assertFalse(channel.shouldShowLights());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java
new file mode 100644
index 0000000..d685740
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java
@@ -0,0 +1,316 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationChannelGroup;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+import com.android.settingslib.RestrictedLockUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class NotificationPreferenceControllerTest {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private TestPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = new TestPreferenceController(mContext, mBackend);
+ }
+
+ @Test
+ public void noCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
+ mController.saveChannel();
+ assertFalse(mController.isChannelConfigurable());
+ assertFalse(mController.isChannelBlockable());
+ assertFalse(mController.isChannelGroupBlockable());
+ }
+
+ @Test
+ public void isAvailable_notIfNull() throws Exception {
+ mController.onResume(null, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_notIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, mock(NotificationChannel.class),
+ mock(NotificationChannelGroupWrapper.class), null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_notIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable_notIfChannelGroupBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+
+ mController.onResume(appRow, channel, group, null);
+ when(group.isBlocked()).thenReturn(true);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void isAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(false);
+
+ mController.onResume(appRow, channel, group, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testOnResume() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
+
+ mController.onResume(appRow, channel, group, admin);
+
+ assertEquals(appRow, mController.mAppRow);
+ assertEquals(channel, mController.mChannel);
+ assertEquals(group, mController.mChannelGroup);
+ assertEquals(admin, mController.mAdmin);
+ }
+
+ @Test
+ public void testCanBeVisible_unspecified() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
+ }
+
+ @Test
+ public void testCanBeVisible_sameImportance() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
+ }
+
+ @Test
+ public void testCanBeVisible_greaterImportance() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
+ }
+
+ @Test
+ public void testCanBeVisible_lesserImportance() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
+
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
+ }
+
+ @Test
+ public void testSaveImportance() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
+
+ mController.onResume(appRow, channel, null, null);
+ mController.saveChannel();
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testIsConfigurable() {
+ String sameId = "bananas";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = sameId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(sameId);
+
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isChannelConfigurable());
+
+ when(channel.getId()).thenReturn("something new");
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isChannelConfigurable());
+ }
+
+ @Test
+ public void testIsChannelBlockable_nonSystemAppsBlockable() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = false;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.isBlockableSystem()).thenReturn(false);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isChannelBlockable());
+ }
+
+ @Test
+ public void testIsChannelBlockable_mostSystemAppsNotBlockable() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.isBlockableSystem()).thenReturn(false);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
+
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isChannelBlockable());
+ }
+
+ @Test
+ public void testIsChannelBlockable_someSystemAppsAreBlockable() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.isBlockableSystem()).thenReturn(true);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isChannelBlockable());
+ }
+
+ @Test
+ public void testIsChannelBlockable_canUndoSystemBlock() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.isBlockableSystem()).thenReturn(false);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isChannelBlockable());
+ }
+
+ @Test
+ public void testIsChannelGroupBlockable_nonSystemBlockable() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = false;
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(false);
+
+ mController.onResume(appRow, null, group, null);
+ assertTrue(mController.isChannelGroupBlockable());
+ }
+
+ @Test
+ public void testIsChannelGroupBlockable_SystemNotBlockable() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(false);
+
+ mController.onResume(appRow, null, group, null);
+ assertFalse(mController.isChannelGroupBlockable());
+ }
+
+ @Test
+ public void testIsChannelGroupBlockable_canUndoSystemBlock() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.systemApp = true;
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(true);
+
+ mController.onResume(appRow, null, group, null);
+ assertTrue(mController.isChannelGroupBlockable());
+ }
+
+ private final class TestPreferenceController extends NotificationPreferenceController {
+
+ public TestPreferenceController(Context context,
+ NotificationBackend backend) {
+ super(context, backend);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return null;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
new file mode 100644
index 0000000..e1f9eb7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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 static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.wrapper.NotificationChannelGroupWrapper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class NotificationsOffPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+
+ private NotificationsOffPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new NotificationsOffPreferenceController(mContext));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(Preference.class));
+ }
+
+ @Test
+ public void testIsAvailable_yesIfAppBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_yesIfChannelGroupBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(true);
+ mController.onResume(appRow, null, group, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_yesIfChannelBlocked() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_channel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.getTitle().toString().contains("category"));
+ assertFalse(pref.isEnabled());
+ assertFalse(pref.isSelectable());
+ }
+
+ @Test
+ public void testUpdateState_channelGroup() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
+ when(group.isBlocked()).thenReturn(true);
+ mController.onResume(appRow, null, group, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.getTitle().toString().contains("group"));
+ assertFalse(pref.isEnabled());
+ assertFalse(pref.isSelectable());
+ }
+
+ @Test
+ public void testUpdateState_app() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ mController.onResume(appRow, null, null, null);
+
+ Preference pref = new Preference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.getTitle().toString().contains("app"));
+ assertFalse(pref.isEnabled());
+ assertFalse(pref.isSelectable());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
new file mode 100644
index 0000000..1d5a791
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java
@@ -0,0 +1,257 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Fragment;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Build;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.AttributeSet;
+
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class SoundPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+ @Mock
+ private SettingsPreferenceFragment mFragment;
+ @Mock
+ private NotificationSettingsBase.ImportanceListener mImportanceListener;
+
+ private SoundPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new SoundPreferenceController(
+ mContext, mFragment, mImportanceListener, mBackend));
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(NotificationSoundPreference.class));
+ mController.onPreferenceChange(mock(NotificationSoundPreference.class), Uri.EMPTY);
+ mController.handlePreferenceTreeClick(mock(NotificationSoundPreference.class));
+ mController.onActivityResult(1, 1, null);
+ mController.hasValidSound(null);
+ }
+
+ @Test
+ public void testIsAvailable_notIfChannelNull() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ mController.onResume(appRow, null, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfDefaultChannel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testDisplayPreference_savesPreference() throws Exception {
+ NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+
+ mController.onActivityResult(SoundPreferenceController.CODE, 1, new Intent());
+ verify(pref, times(1)).onActivityResult(anyInt(), anyInt(), any());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new NotificationSoundPreference(mContext, mock(AttributeSet.class));
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new NotificationSoundPreference(mContext, mock(AttributeSet.class));
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_configurable() throws Exception {
+ Uri sound = Settings.System.DEFAULT_ALARM_ALERT_URI;
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ when(channel.getSound()).thenReturn(sound);
+ mController.onResume(appRow, channel, null, null);
+
+ NotificationSoundPreference pref =
+ new NotificationSoundPreference(mContext, mock(AttributeSet.class));
+ mController.updateState(pref);
+
+ assertEquals(sound, pref.onRestoreRingtone());
+ assertTrue(pref.isEnabled());
+ }
+
+ @Test
+ public void testOnPreferenceChange() throws Exception {
+ Uri sound = Settings.System.DEFAULT_ALARM_ALERT_URI;
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
+ channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+
+ NotificationSoundPreference pref =
+ new NotificationSoundPreference(mContext, mock(AttributeSet.class));
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, Uri.EMPTY);
+ assertEquals(Uri.EMPTY, channel.getSound());
+ assertEquals(Notification.AUDIO_ATTRIBUTES_DEFAULT, channel.getAudioAttributes());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceTreeClick_incorrectPref() throws Exception {
+ NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
+ mController.handlePreferenceTreeClick(pref);
+
+ verify(pref, never()).onPrepareRingtonePickerIntent(any());
+ verify(mFragment, never()).startActivityForResult(any(), anyInt());
+ }
+
+
+ @Test
+ public void testOnPreferenceTreeClick_correctPref() throws Exception {
+ NotificationSoundPreference pref =
+ spy(new NotificationSoundPreference(mContext, mock(AttributeSet.class)));
+ pref.setKey(mController.getPreferenceKey());
+ mController.handlePreferenceTreeClick(pref);
+
+ verify(pref, times(1)).onPrepareRingtonePickerIntent(any());
+ verify(mFragment, times(1)).startActivityForResult(any(), anyInt());
+ }
+
+ @Test
+ public void testOnActivityResult() {
+ NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+
+ mController.onActivityResult(SoundPreferenceController.CODE, 1, new Intent("hi"));
+ verify(pref, times(1)).onActivityResult(anyInt(), anyInt(), any());
+ verify(mImportanceListener, times(1)).onImportanceChanged();
+ }
+
+ @Test
+ public void testHasValidSound() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ assertTrue(mController.hasValidSound(channel));
+
+ channel.setSound(Uri.EMPTY, Notification.AUDIO_ATTRIBUTES_DEFAULT);
+ assertFalse(mController.hasValidSound(channel));
+
+ channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
+ assertFalse(mController.hasValidSound(channel));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java
new file mode 100644
index 0000000..4695590
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/VibrationPreferenceControllerTest.java
@@ -0,0 +1,230 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.UserManager;
+import android.os.Vibrator;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O)
+public class VibrationPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ Vibrator mVibrator;
+ @Mock
+ private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private VibrationPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ shadowApplication.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new VibrationPreferenceController(mContext, mBackend));
+
+ // by default allow vibration
+ when(mVibrator.hasVibrator()).thenReturn(true);
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedSwitchPreference.class));
+ mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
+ }
+
+ @Test
+ public void testIsAvailable_notSystemDoesNotHave() throws Exception {
+ when(mVibrator.hasVibrator()).thenReturn(false);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfDefaultChannel() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_notConfigurable() throws Exception {
+ String lockedId = "locked";
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.lockedChannelId = lockedId;
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn(lockedId);
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertFalse(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_configurable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(appRow, channel, null, null);
+
+ Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ assertTrue(pref.isEnabled());
+ }
+
+ @Test
+ public void testUpdateState_vibrateOn() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.shouldVibrate()).thenReturn(true);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertTrue(pref.isChecked());
+ }
+
+ @Test
+ public void testUpdateState_vibrateOff() throws Exception {
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.shouldVibrate()).thenReturn(false);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+ assertFalse(pref.isChecked());
+ }
+
+ @Test
+ public void testOnPreferenceChange_on() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, true);
+
+ assertTrue(channel.shouldVibrate());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceChange_off() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedSwitchPreference pref =
+ new RestrictedSwitchPreference(RuntimeEnvironment.application);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, false);
+
+ assertFalse(channel.shouldVibrate());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java
new file mode 100644
index 0000000..ed658fe
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/VisibilityPreferenceControllerTest.java
@@ -0,0 +1,326 @@
+/*
+ * 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 static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
+import static android.app.NotificationManager.VISIBILITY_NO_OVERRIDE;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS;
+import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.UserInfo;
+import android.os.Build;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
+import com.android.settingslib.RestrictedLockUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = Build.VERSION_CODES.O, shadows = {
+ ShadowRestrictionUtils.class,
+})
+public class VisibilityPreferenceControllerTest {
+
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ @Mock
+ private NotificationManager mNm;
+ @Mock
+ private LockPatternUtils mLockUtils;
+ @Mock
+ private UserManager mUm;
+ @Mock
+ private DevicePolicyManager mDm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private VisibilityPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
+ shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
+ shadowApplication.setSystemService(Context.DEVICE_POLICY_SERVICE, mDm);
+ mContext = shadowApplication.getApplicationContext();
+ mController = spy(new VisibilityPreferenceController(mContext, mLockUtils, mBackend));
+
+ // by default the lockscreen is secure
+ when(mLockUtils.isSecure(anyInt())).thenReturn(true);
+ // and notifications are visible in redacted form
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1);
+ // and not restricted
+ ShadowRestrictionUtils.setRestricted(false);
+ // with no managed profile
+ UserInfo userInfo = new UserInfo();
+ when(mUm.getUserInfo(anyInt())).thenReturn(userInfo);
+ }
+
+ @Test
+ public void testNoCrashIfNoOnResume() throws Exception {
+ mController.isAvailable();
+ mController.updateState(mock(RestrictedDropDownPreference.class));
+ mController.onPreferenceChange(mock(RestrictedDropDownPreference.class), true);
+ }
+
+ @Test
+ public void testIsAvailable_notSecure() throws Exception {
+ when(mLockUtils.isSecure(anyInt())).thenReturn(false);
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable_notIfNotImportant() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
+ mController.onResume(appRow, channel, null, null);
+ assertFalse(mController.isAvailable());
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+
+ channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
+ mController.onResume(appRow, channel, null, null);
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin_disableSecure() throws Exception {
+ ShadowRestrictionUtils.setRestricted(true);
+ UserInfo userInfo = new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE);
+ when(mUm.getUserInfo(anyInt())).thenReturn(userInfo);
+ List<ComponentName> components = new ArrayList<>();
+ components.add(new ComponentName("", ""));
+ when(mDm.getActiveAdminsAsUser(anyInt())).thenReturn(components);
+ when(mDm.getKeyguardDisabledFeatures(any(), anyInt()))
+ .thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ verify(pref, times(2)).addRestrictedItem(any());
+ }
+
+ @Test
+ public void testUpdateState_disabledByAdmin_disableUnredacted() throws Exception {
+ ShadowRestrictionUtils.setRestricted(true);
+ UserInfo userInfo = new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE);
+ when(mUm.getUserInfo(anyInt())).thenReturn(userInfo);
+ List<ComponentName> components = new ArrayList<>();
+ components.add(new ComponentName("", ""));
+ when(mDm.getActiveAdminsAsUser(anyInt())).thenReturn(components);
+ when(mDm.getKeyguardDisabledFeatures(any(), anyInt()))
+ .thenReturn(KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
+
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getId()).thenReturn("something");
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
+ RestrictedLockUtils.EnforcedAdmin.class));
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ verify(pref, times(1)).addRestrictedItem(any());
+ }
+
+ @Test
+ public void testUpdateState_noLockScreenNotificationsGlobally() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class);
+ verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
+ assertFalse(Arrays.asList(argumentCaptor.getValue())
+ .contains(VISIBILITY_NO_OVERRIDE));
+ }
+
+ @Test
+ public void testUpdateState_noPrivateLockScreenNotificationsGlobally() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class);
+ verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
+ assertFalse(Arrays.asList(argumentCaptor.getValue())
+ .contains(VISIBILITY_NO_OVERRIDE));
+ }
+
+ @Test
+ public void testUpdateState_noGlobalRestriction() throws Exception {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class);
+ verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
+ List<String> values = Arrays.asList(argumentCaptor.getValue());
+ assertEquals(3, values.size());
+ assertTrue(values.contains(String.valueOf(VISIBILITY_NO_OVERRIDE)));
+ assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_PRIVATE)));
+ assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_SECRET)));
+ }
+
+ @Test
+ public void testUpdateState_noChannelOverride() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
+ verify(pref, times(1)).setValue(argumentCaptor.capture());
+
+ assertEquals(String.valueOf(Notification.VISIBILITY_PRIVATE), argumentCaptor.getValue());
+ }
+
+ @Test
+ public void testUpdateState_channelOverride() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
+ verify(pref, times(1)).setValue(argumentCaptor.capture());
+
+ assertEquals(String.valueOf(Notification.VISIBILITY_SECRET), argumentCaptor.getValue());
+ }
+
+ @Test
+ public void testOnPreferenceChange_noOverride() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", 4);
+ channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_PRIVATE));
+
+ assertEquals(VISIBILITY_NO_OVERRIDE, channel.getLockscreenVisibility());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+
+ @Test
+ public void testOnPreferenceChange_override() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0);
+
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ NotificationChannel channel = new NotificationChannel("", "", 4);
+ channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
+ mController.onResume(appRow, channel, null, null);
+
+ RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
+ mController.updateState(pref);
+
+ mController.onPreferenceChange(pref, String.valueOf(Notification.VISIBILITY_SECRET));
+
+ assertEquals(Notification.VISIBILITY_SECRET, channel.getLockscreenVisibility());
+ verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
index a578364..56f3949 100644
--- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
@@ -16,27 +16,28 @@
package com.android.settings.users;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import android.app.Activity;
import android.content.pm.UserInfo;
import android.os.UserManager;
import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
import org.robolectric.Robolectric;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -70,4 +71,9 @@
mActivity.getString(R.string.users_summary, name));
}
+ @Test
+ public void testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash() {
+ // Should not crash here
+ assertThat(UserSettings.assignDefaultPhoto(null, 0)).isFalse();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
index 49a678f..b8fe81e 100644
--- a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
@@ -42,7 +42,7 @@
import org.robolectric.shadows.ShadowActivity;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {
WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class
})
@@ -67,6 +67,8 @@
final Intent intent = activity.getNextStartedActivity();
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
+ assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ assertThat(activity.isFinishing()).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperTypeSettingsTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperTypeSettingsTest.java
new file mode 100644
index 0000000..7e15f7a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperTypeSettingsTest.java
@@ -0,0 +1,67 @@
+package com.android.settings.wallpaper;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.robolectric.RuntimeEnvironment.application;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.robolectric.Robolectric;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+public class WallpaperTypeSettingsTest {
+
+ private Preference mPreference;
+
+ private Intent mIntent;
+
+ @Before
+ public void setUp() {
+ mIntent = new Intent();
+ mPreference = new Preference(application);
+ }
+
+ @Test
+ public void testOnPreferenceTreeClick_intentNull_shouldDoNothing() {
+ Activity activity = Robolectric.setupActivity(Activity.class);
+ WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings());
+ doReturn(activity).when(fragment).getActivity();
+
+ boolean handled = fragment.onPreferenceTreeClick(mPreference);
+
+ assertThat(handled).isFalse();
+ }
+
+ @Test
+ public void testOnPreferenceTreeClick_shouldLaunchIntentAndFinish() {
+ Activity activity = Robolectric.setupActivity(Activity.class);
+ WallpaperTypeSettings fragment = spy(new WallpaperTypeSettings());
+ doReturn(activity).when(fragment).getActivity();
+ mPreference.setIntent(mIntent);
+ doNothing().when(fragment).finish();
+ ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
+ doNothing().when(fragment).startActivity(intent.capture());
+
+ boolean handled = fragment.onPreferenceTreeClick(mPreference);
+
+ assertThat(handled).isTrue();
+ verify(fragment, times(1)).finish();
+ assertThat(intent.getValue()).isSameAs(mIntent);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
new file mode 100644
index 0000000..2eaa587
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/ConnectedAccessPointPreferenceTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.wifi;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.view.View;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.wifi.AccessPoint;
+
+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(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ConnectedAccessPointPreferenceTest {
+ @Mock
+ private AccessPoint mAccessPoint;
+ @Mock
+ private View mView;
+ @Mock
+ private ConnectedAccessPointPreference.OnGearClickListener mOnGearClickListener;
+ private Context mContext;
+ private ConnectedAccessPointPreference mConnectedAccessPointPreference;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mConnectedAccessPointPreference = new ConnectedAccessPointPreference(mAccessPoint, mContext,
+ null, 0 /* iconResId */, false /* forSavedNetworks */);
+ mConnectedAccessPointPreference.setOnGearClickListener(mOnGearClickListener);
+ }
+
+ @Test
+ public void testOnClick_gearClicked_listenerInvoked() {
+ doReturn(R.id.settings_button).when(mView).getId();
+
+ mConnectedAccessPointPreference.onClick(mView);
+
+ verify(mOnGearClickListener).onGearClick(mConnectedAccessPointPreference);
+ }
+
+ @Test
+ public void testOnClick_gearNotClicked_listenerNotInvoked() {
+ mConnectedAccessPointPreference.onClick(mView);
+
+ verify(mOnGearClickListener, never()).onGearClick(mConnectedAccessPointPreference);
+ }
+
+}