Merge "Post SUW Slot Change Receiver Migration" into sc-dev
diff --git a/res/layout/dark_ui_activation_button.xml b/res/layout/dark_ui_activation_button.xml
deleted file mode 100644
index 5f9eefc..0000000
--- a/res/layout/dark_ui_activation_button.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight">
-
- <Button
- android:id="@+id/dark_ui_turn_on_button"
- style="@style/ActionPrimaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical" />
-
- <Button
- android:id="@+id/dark_ui_turn_off_button"
- style="@style/ActionSecondaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical" />
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/night_display_activation_button.xml b/res/layout/night_display_activation_button.xml
deleted file mode 100644
index df160ec..0000000
--- a/res/layout/night_display_activation_button.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight">
-
- <Button
- android:id="@+id/night_display_turn_on_button"
- style="@style/ActionPrimaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical" />
-
- <Button
- android:id="@+id/night_display_turn_off_button"
- style="@style/ActionSecondaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical" />
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/panel_layout.xml b/res/layout/panel_layout.xml
index 5f33c32..ac7a72b 100644
--- a/res/layout/panel_layout.xml
+++ b/res/layout/panel_layout.xml
@@ -48,11 +48,13 @@
</LinearLayout>
<LinearLayout
+ android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:orientation="vertical">
+
<TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
@@ -67,8 +69,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
- android:maxLines="1" />
-
+ android:maxLines="1"/>
</LinearLayout>
</LinearLayout>
diff --git a/res/layout/search_bar.xml b/res/layout/search_bar.xml
index 75b43f0..63f1c95 100644
--- a/res/layout/search_bar.xml
+++ b/res/layout/search_bar.xml
@@ -17,14 +17,12 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/search_bar_margin"
android:layout_marginStart="@dimen/search_bar_margin"
android:layout_marginEnd="@dimen/search_bar_margin"
- android:layout_marginBottom="@dimen/search_bar_margin_bottom"
- app:layout_scrollFlags="scroll|enterAlways">
+ android:layout_marginBottom="@dimen/search_bar_margin_bottom">
<com.google.android.material.card.MaterialCardView
android:id="@+id/search_bar"
diff --git a/res/layout/zen_mode_settings_button.xml b/res/layout/zen_mode_settings_button.xml
deleted file mode 100644
index db889ff..0000000
--- a/res/layout/zen_mode_settings_button.xml
+++ /dev/null
@@ -1,55 +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.
- -->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
-
- <TextView
- android:text="@string/zen_mode_settings_summary"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_marginEnd="@dimen/description_margin_sides"
- android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"/>
-
- <Button
- android:id="@+id/zen_mode_settings_turn_on_button"
- style="@style/ActionPrimaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_marginEnd="@dimen/description_margin_sides"
- android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
- android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
- android:text="@string/zen_mode_button_turn_on"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
-
- <Button
- android:id="@+id/zen_mode_settings_turn_off_button"
- style="@style/ActionSecondaryButton"
- android:layout_marginStart="@dimen/screen_margin_sides"
- android:layout_marginEnd="@dimen/description_margin_sides"
- android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
- android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
- android:text="@string/zen_mode_button_turn_off"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d497e4e..bc86338 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5254,6 +5254,8 @@
<string name="accessibility_summary_state_stopped">Not working. Tap for info.</string>
<!-- Accessibility service's description when enabled but not running (like maybe it crashed). -->
<string name="accessibility_description_state_stopped">This service is malfunctioning.</string>
+ <!-- Title for the accessibility shortcuts settings page. [CHAR LIMIT=50] -->
+ <string name="accessibility_shortcuts_settings_title">Accessibility shortcuts</string>
<!-- Title for the preference to show a tile for a particular feature in the Quick Settings pane. [CHAR LIMIT=NONE] -->
<string name="enable_quick_setting">Show in Quick Settings</string>
@@ -12584,8 +12586,10 @@
<string name="view_airplane_safe_networks">View airplane mode networks</string>
<!-- Text of message for viewing the networks that are available in airplane mode. [CHAR LIMIT=60] -->
<string name="viewing_airplane_mode_networks">Viewing airplane mode networks</string>
- <!-- Label text to turn off airplane mode. [CHAR LIMIT=40] -->
- <string name="turn_off_airplane_mode">Turn off airplane mode</string>
+ <!-- Slice title text for turning on networks (e.g. Wi-Fi). [CHAR LIMIT=40] -->
+ <string name="turn_on_networks">Turn on networks</string>
+ <!-- Slice title text for turning off networks (e.g. Wi-Fi). [CHAR LIMIT=40] -->
+ <string name="turn_off_networks">Turn off networks</string>
<!-- Title for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
<string name="reset_your_internet_title">Reset your internet?</string>
<!-- Description for interrupting the voice call alert. [CHAR_LIMIT=NONE] -->
@@ -12674,6 +12678,18 @@
<string name="graphics_driver_main_switch_title" translatable="false">Use graphics driver preferences</string>
<!-- Do not translate. Title for battery saver main switch preferences. [CHAR LIMIT=50] -->
<string name="battery_saver_main_switch_title" translatable="false">Use battery saver</string>
+ <!-- Do not translate. Title for Do Not Disturb main switch preferences. [CHAR LIMIT=50] -->
+ <string name="do_not_disturb_main_switch_title" translatable="false">Use Do Not Disturb</string>
+ <!-- Do not translate. Title for Dark theme main switch preferences. [CHAR LIMIT=50] -->
+ <string name="dark_theme_main_switch_title" translatable="false">Use Dark Theme</string>
+ <!-- Do not translate. Title for Night Light main switch preferences. [CHAR LIMIT=50] -->
+ <string name="night_light_main_switch_title" translatable="false">Use Night Light</string>
+ <!-- Do not translate. Title for NFC main switch preferences. [CHAR LIMIT=50] -->
+ <string name="nfc_main_switch_title" translatable="false">Use NFC</string>
+ <!-- Do not translate. Title for Adaptive Battery main switch preferences. [CHAR LIMIT=50] -->
+ <string name="adaptive_battery_main_switch_title" translatable="false">Use adaptive battery</string>
+ <!-- Do not translate. Title for adaptive brightness main switch preferences. [CHAR LIMIT=50] -->
+ <string name="adaptive_brightness_main_switch_title" translatable="false">Use adaptive brightness</string>
<!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
<string name="default_see_all_apps_title">See all apps</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 69fa93e..bed02c8 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -221,7 +221,6 @@
<item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings_light</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarDividerColor">@*android:color/ripple_material_light</item>
- <item name="android:navigationBarColor">@android:color/transparent</item>
</style>
<style name="Theme.Settings.ContextualCard" parent="Theme.Settings.Home">
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 36125b3..eff9e1d 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -29,15 +29,7 @@
<PreferenceCategory
android:key="screen_reader_category"
android:persistent="false"
- android:title="@string/screen_reader_category_title">
-
- <Preference
- android:fragment="com.android.settings.tts.TextToSpeechSettings"
- android:key="tts_settings_preference"
- android:persistent="false"
- android:title="@string/tts_settings_title"
- settings:controller="com.android.settings.language.TtsPreferenceController"/>
- </PreferenceCategory>
+ android:title="@string/screen_reader_category_title"/>
<PreferenceCategory
android:key="display_category"
@@ -129,6 +121,25 @@
</PreferenceCategory>
+ <!-- TODO(b/174829936): Add title for shortcuts settings category. -->
+ <PreferenceCategory android:persistent="false">
+
+ <Preference
+ android:fragment="com.android.settings.accessibility.ShortcutsSettingsFragment"
+ android:key="accessibility_shortcuts_preference_screen"
+ android:persistent="false"
+ android:title="@string/accessibility_shortcuts_settings_title"
+ settings:searchable="true"/>
+
+ <Preference
+ android:fragment="com.android.settings.tts.TextToSpeechSettings"
+ android:key="tts_settings_preference"
+ android:persistent="false"
+ android:title="@string/tts_settings_title"
+ settings:controller="com.android.settings.language.TtsPreferenceController"/>
+
+ </PreferenceCategory>
+
<PreferenceCategory
android:key="experimental_category"
android:persistent="false"
diff --git a/res/xml/accessibility_shortcuts_settings.xml b/res/xml/accessibility_shortcuts_settings.xml
new file mode 100644
index 0000000..35314e7
--- /dev/null
+++ b/res/xml/accessibility_shortcuts_settings.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="accessibility_shortcuts_settings"
+ android:persistent="false"
+ android:title="@string/accessibility_shortcuts_settings_title">
+
+ <SwitchPreference
+ android:key="accessibility_shortcut_preference"
+ android:persistent="false"
+ android:title="@string/accessibility_shortcut_service_on_lock_screen_title"
+ android:summary="@string/accessibility_shortcut_description"
+ settings:controller="com.android.settings.accessibility.AccessibilityShortcutPreferenceController"/>
+</PreferenceScreen>
diff --git a/res/xml/app_info_settings_v2.xml b/res/xml/app_info_settings_v2.xml
new file mode 100644
index 0000000..805df59
--- /dev/null
+++ b/res/xml/app_info_settings_v2.xml
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2021 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="installed_app_detail_settings_screen">
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="header_view"
+ android:layout="@layout/settings_entity_header"
+ android:selectable="false"
+ android:order="-10000"
+ settings:allowDividerBelow="true"/>
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="instant_app_buttons"
+ android:layout="@layout/instant_app_buttons"
+ android:selectable="false"
+ android:order="-9999"
+ settings:allowDividerAbove="true"
+ settings:allowDividerBelow="true"/>
+
+ <com.android.settingslib.widget.ActionButtonsPreference
+ android:key="action_buttons"
+ android:order="-9998" />
+
+ <!-- Add SpacePreference to draw divider -->
+ <com.android.settings.applications.SpacePreference
+ android:layout_height="0dp"
+ android:order="-9997"
+ settings:allowDividerAbove="true" />
+
+ <Preference
+ android:key="app_settings_link"
+ android:title="@string/app_settings_link"
+ settings:controller="com.android.settings.applications.appinfo.AppSettingPreferenceController" />
+
+ <Preference
+ android:key="notification_settings"
+ android:title="@string/notifications_label"
+ settings:controller="com.android.settings.applications.appinfo.AppNotificationPreferenceController" />
+
+ <com.android.settings.widget.FixedLineSummaryPreference
+ android:key="permission_settings"
+ android:title="@string/permissions_label"
+ android:summary="@string/summary_placeholder"
+ settings:summaryLineCount="1"
+ settings:controller="com.android.settings.applications.appinfo.AppPermissionPreferenceController" />
+
+ <Preference
+ android:key="storage_settings"
+ android:title="@string/storage_settings_for_app"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.appinfo.AppStoragePreferenceController" />
+
+ <com.android.settings.applications.AppDomainsPreference
+ android:key="instant_app_launch_supported_domain_urls"
+ android:title="@string/app_launch_supported_domain_urls_title"
+ android:selectable="true"
+ settings:controller="com.android.settings.applications.appinfo.InstantAppDomainsPreferenceController" />
+
+ <Preference
+ android:key="data_settings"
+ android:title="@string/data_usage_app_summary_title"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.appinfo.AppDataUsagePreferenceController" />
+
+ <Preference
+ android:key="time_spent_in_app"
+ android:title="@string/time_spent_in_app_pref_title"
+ settings:controller="com.android.settings.applications.appinfo.TimeSpentInAppPreferenceController" />
+
+ <Preference
+ android:key="battery"
+ android:title="@string/power_usage_summary_title"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="preferred_settings"
+ android:title="@string/launch_by_default"
+ android:summary="@string/summary_placeholder"
+ android:selectable="true"
+ settings:controller="com.android.settings.applications.appinfo.AppOpenByDefaultPreferenceController" />
+
+ <Preference
+ android:key="memory"
+ android:title="@string/memory_settings_title"
+ android:summary="@string/summary_placeholder"
+ android:enabled="false" />
+
+ <!-- Default apps shortcuts -->
+ <Preference
+ android:key="default_home"
+ android:title="@string/home_app"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_browser"
+ android:title="@string/default_browser_title"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_phone_app"
+ android:title="@string/default_phone_title"
+ android:summary="@string/default_phone_title" />
+
+ <Preference
+ android:key="default_emergency_app"
+ android:title="@string/default_emergency_app"
+ android:summary="@string/summary_placeholder" />
+
+ <Preference
+ android:key="default_sms_app"
+ android:title="@string/sms_application_title"
+ android:summary="@string/summary_placeholder" />
+
+ <!-- Advanced apps settings -->
+ <PreferenceCategory
+ android:key="advanced_app_info"
+ android:title="@string/advanced_apps"
+ settings:controller="com.android.settings.applications.appinfo.AdvancedAppInfoPreferenceCategoryController">
+
+ <Preference
+ android:key="system_alert_window"
+ android:title="@string/draw_overlay"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.appinfo.DrawOverlayDetailPreferenceController" />
+
+ <Preference
+ android:key="write_settings_apps"
+ android:title="@string/write_settings"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.appinfo.WriteSystemSettingsPreferenceController" />
+
+ <Preference
+ android:key="picture_in_picture"
+ android:title="@string/picture_in_picture_app_detail_title"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetailPreferenceController" />
+
+ <Preference
+ android:key="install_other_apps"
+ android:title="@string/install_other_apps"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.appinfo.ExternalSourceDetailPreferenceController" />
+
+ <Preference
+ android:key="interact_across_profiles"
+ android:title="@string/interact_across_profiles_title"
+ android:summary="@string/summary_placeholder"
+ settings:controller="com.android.settings.applications.specialaccess.interactacrossprofiles.InteractAcrossProfilesDetailsPreferenceController" />
+
+ </PreferenceCategory>
+
+ <!-- App installer info -->
+ <PreferenceCategory
+ android:key="app_installer"
+ android:title="@string/app_install_details_group_title"
+ settings:controller="com.android.settings.applications.appinfo.AppInstallerPreferenceCategoryController">
+
+ <Preference
+ android:key="app_info_store"
+ android:title="@string/app_install_details_title"
+ settings:controller="com.android.settings.applications.appinfo.AppInstallerInfoPreferenceController" />
+
+ </PreferenceCategory>
+
+ <Preference
+ android:key="app_version"
+ android:selectable="false"
+ android:order="9999"
+ settings:controller="com.android.settings.applications.appinfo.AppVersionPreferenceController"
+ settings:allowDividerAbove="true"
+ settings:enableCopying="true"/>
+
+</PreferenceScreen>
diff --git a/res/xml/app_storage_settings.xml b/res/xml/app_storage_settings.xml
index 376f09e..6092dbb 100644
--- a/res/xml/app_storage_settings.xml
+++ b/res/xml/app_storage_settings.xml
@@ -42,7 +42,7 @@
<PreferenceCategory
android:key="storage_category"
android:title="@string/app_info_storage_title"
- settings:allowDividerBelow="false">
+ settings:allowDividerAbove="true">
<Preference
android:key="app_size"
diff --git a/res/xml/auto_brightness_detail.xml b/res/xml/auto_brightness_detail.xml
index 6b304ef..ebcf174 100644
--- a/res/xml/auto_brightness_detail.xml
+++ b/res/xml/auto_brightness_detail.xml
@@ -20,6 +20,12 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/auto_brightness_title">
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="auto_brightness"
+ android:title="@string/adaptive_brightness_main_switch_title"
+ settings:keywords="@string/keywords_display_auto_brightness"
+ settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"/>
+
<com.android.settings.widget.VideoPreference
android:key="auto_brightness_video"
android:title="@string/summary_placeholder"
@@ -27,17 +33,6 @@
settings:preview="@drawable/aab_brightness"
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
- <!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="auto_brightness"
- android:title="@string/auto_brightness_title"
- android:summary="@string/auto_brightness_summary"
- settings:keywords="@string/keywords_display_auto_brightness"
- settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"
- settings:useAdminDisabledSummary="true"
- settings:userRestriction="no_config_brightness"
- settings:allowDividerAbove="true" />
-
<com.android.settingslib.widget.FooterPreference
android:key="auto_brightness_footer"
android:title="@string/auto_brightness_description"
diff --git a/res/xml/dark_mode_settings.xml b/res/xml/dark_mode_settings.xml
index 19279e0..5ac9e26 100644
--- a/res/xml/dark_mode_settings.xml
+++ b/res/xml/dark_mode_settings.xml
@@ -20,6 +20,11 @@
android:title="@string/dark_ui_mode"
settings:keywords="@string/keywords_dark_ui_mode">
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="dark_ui_activated"
+ android:title="@string/dark_theme_main_switch_title"
+ settings:controller="com.android.settings.display.darkmode.DarkModeActivationPreferenceController"/>
+
<com.android.settingslib.widget.BannerMessagePreference
android:key="dark_ui_location_off"
android:title="@string/twilight_mode_location_off_dialog_message"
@@ -50,12 +55,4 @@
android:title="@string/night_display_end_time_title"
settings:searchable="false"/>
- <com.android.settingslib.widget.LayoutPreference
- android:key="dark_ui_activated"
- android:title="@string/dark_ui_title"
- android:selectable="false"
- android:layout="@layout/dark_ui_activation_button"
- settings:allowDividerBelow="true"
- settings:controller="com.android.settings.display.darkmode.DarkModeActivationPreferenceController"/>
-
</PreferenceScreen>
diff --git a/res/xml/nfc_and_payment_settings.xml b/res/xml/nfc_and_payment_settings.xml
index 8ff4983..09ce277 100644
--- a/res/xml/nfc_and_payment_settings.xml
+++ b/res/xml/nfc_and_payment_settings.xml
@@ -19,6 +19,11 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/nfc_quick_toggle_title">
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="toggle_nfc"
+ android:title="@string/nfc_main_switch_title"
+ settings:controller="com.android.settings.nfc.NfcPreferenceController"/>
+
<com.android.settingslib.widget.LayoutPreference
android:key="nfc_detection_point"
android:selectable="false"
@@ -26,12 +31,6 @@
settings:controller="com.android.settings.nfc.NfcDetectionPointController"/>
<SwitchPreference
- android:key="toggle_nfc"
- android:title="@string/nfc_quick_toggle_title"
- android:summary="@string/nfc_quick_toggle_summary"
- settings:controller="com.android.settings.nfc.NfcPreferenceController"/>
-
- <SwitchPreference
android:key="nfc_secure_settings"
android:title="@string/nfc_secure_settings_title"
settings:controller="com.android.settings.nfc.SecureNfcPreferenceController"
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index 97f5dd2..23afccf 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -20,6 +20,11 @@
android:title="@string/night_display_title"
settings:keywords="@string/keywords_display_night_display">
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="night_display_activated"
+ android:title="@string/night_light_main_switch_title"
+ settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController"/>
+
<com.android.settingslib.widget.BannerMessagePreference
android:key="dark_ui_location_off"
android:title="@string/twilight_mode_location_off_dialog_message"
@@ -54,13 +59,4 @@
settings:controller="com.android.settings.display.NightDisplayIntensityPreferenceController"
settings:unavailableSliceSubtitle="@string/night_display_not_currently_on"/>
- <com.android.settingslib.widget.LayoutPreference
- android:key="night_display_activated"
- android:title="@string/night_display_title"
- android:selectable="false"
- android:layout="@layout/night_display_activation_button"
- settings:allowDividerBelow="true"
- settings:keywords="@string/keywords_display_night_display"
- settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController"/>
-
</PreferenceScreen>
diff --git a/res/xml/power_usage_detail.xml b/res/xml/power_usage_detail.xml
index 945ceed..95c1038 100644
--- a/res/xml/power_usage_detail.xml
+++ b/res/xml/power_usage_detail.xml
@@ -31,7 +31,8 @@
android:order="-9999"/>
<PreferenceCategory
- android:title="@string/battery_detail_manage_title">
+ android:title="@string/battery_detail_manage_title"
+ settings:allowDividerAbove="true">
<com.android.settingslib.RestrictedPreference
android:key="background_activity"
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index a9819fd..f683f3c 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -32,7 +32,6 @@
android:fragment="com.android.settings.fuelgauge.PowerUsageAdvanced"
android:key="battery_usage_summary"
android:title="@string/advanced_battery_preference_title"
- android:icon="@drawable/ic_chevron_right_24dp"
settings:searchable="false" />
<com.android.settings.widget.CardPreference
@@ -40,7 +39,7 @@
android:title="@string/summary_placeholder"
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />
- <Preference
+ <com.android.settings.widget.PrimarySwitchPreference
android:fragment="com.android.settings.fuelgauge.batterysaver.BatterySaverSettings"
android:key="battery_saver_summary"
android:title="@string/battery_saver"
diff --git a/res/xml/smart_battery_detail.xml b/res/xml/smart_battery_detail.xml
index 87eeb86..2d36119 100644
--- a/res/xml/smart_battery_detail.xml
+++ b/res/xml/smart_battery_detail.xml
@@ -22,6 +22,11 @@
android:title="@string/smart_battery_manager_title"
settings:searchable="false">
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="smart_battery"
+ android:title="@string/adaptive_battery_main_switch_title"
+ settings:controller="com.android.settings.fuelgauge.SmartBatteryPreferenceController"/>
+
<com.android.settings.widget.VideoPreference
android:key="auto_awesome_battery"
android:title="@string/summary_placeholder"
@@ -30,13 +35,6 @@
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
<SwitchPreference
- android:key="smart_battery"
- android:title="@string/smart_battery_title"
- android:summary="@string/smart_battery_summary"
- settings:controller="com.android.settings.fuelgauge.SmartBatteryPreferenceController"
- settings:allowDividerAbove="true"/>
-
- <SwitchPreference
android:key="auto_restriction"
android:title="@string/battery_auto_restriction_title"
android:summary="@string/battery_auto_restriction_summary"
@@ -51,4 +49,4 @@
android:title="@string/smart_battery_footer"
android:selectable="false"
settings:searchable="false"/>
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 6764e28..78dee02 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -21,12 +21,9 @@
android:title="@string/zen_mode_settings_title">
<!-- Turn on DND button -->
- <com.android.settingslib.widget.LayoutPreference
+ <com.android.settingslib.widget.MainSwitchPreference
android:key="zen_mode_toggle"
- android:title="@string/zen_mode_settings_title"
- android:selectable="false"
- android:layout="@layout/zen_mode_settings_button"
- settings:allowDividerBelow="true"
+ android:title="@string/do_not_disturb_main_switch_title"
settings:keywords="@string/keywords_zen_mode_settings"/>
<PreferenceCategory
diff --git a/src/com/android/settings/ProxySelector.java b/src/com/android/settings/ProxySelector.java
index 625369e..0b6f16a 100644
--- a/src/com/android/settings/ProxySelector.java
+++ b/src/com/android/settings/ProxySelector.java
@@ -41,6 +41,7 @@
import androidx.appcompat.app.AlertDialog;
+import com.android.net.module.util.ProxyUtils;
import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
import com.android.settings.core.InstrumentedFragment;
@@ -151,7 +152,7 @@
if (proxy != null) {
hostname = proxy.getHost();
port = proxy.getPort();
- exclList = proxy.getExclusionListAsString();
+ exclList = ProxyUtils.exclusionListAsString(proxy.getExclusionList());
}
if (hostname == null) {
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 4709c66..582111f 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -372,6 +372,9 @@
} else {
getPreferenceScreen().addPreference(downloadedServicesCategory);
}
+
+ // Hide screen reader category if it is empty.
+ updatePreferenceCategoryVisibility(CATEGORY_SCREEN_READER);
}
private List<RestrictedPreference> getInstalledAccessibilityList(Context context) {
@@ -453,6 +456,16 @@
}
/**
+ * Updates the visibility of a category according to its child preference count.
+ *
+ * @param categoryKey The key of the category which needs to check
+ */
+ private void updatePreferenceCategoryVisibility(String categoryKey) {
+ final PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
+ category.setVisible(category.getPreferenceCount() != 0);
+ }
+
+ /**
* Updates preferences related to system configurations.
*/
protected void updateSystemPreferences() {
diff --git a/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java b/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java
new file mode 100644
index 0000000..91e16f6
--- /dev/null
+++ b/src/com/android/settings/accessibility/ShortcutsSettingsFragment.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 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.accessibility;
+
+import android.app.settings.SettingsEnums;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+
+/** Accessibility settings for accessibility shortcuts. */
+public class ShortcutsSettingsFragment extends DashboardFragment {
+
+ private static final String TAG = "ShortcutsSettingsFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.ACCESSIBILITY_SHORTCUTS_SETTINGS;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.accessibility_shortcuts_settings;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.accessibility_shortcuts_settings);
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
index 6817bd6..f584408 100755
--- a/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
+++ b/src/com/android/settings/applications/appinfo/AppInfoDashboardFragment.java
@@ -35,6 +35,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
+import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -48,6 +49,7 @@
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.applications.specialaccess.interactacrossprofiles.InteractAcrossProfilesDetailsPreferenceController;
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetailPreferenceController;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -245,6 +247,9 @@
@Override
protected int getPreferenceScreenResId() {
+ if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
+ return R.xml.app_info_settings_v2;
+ }
return R.xml.app_info_settings;
}
diff --git a/src/com/android/settings/development/qstile/DevelopmentTiles.java b/src/com/android/settings/development/qstile/DevelopmentTiles.java
index 203a688..16084c0 100644
--- a/src/com/android/settings/development/qstile/DevelopmentTiles.java
+++ b/src/com/android/settings/development/qstile/DevelopmentTiles.java
@@ -265,6 +265,7 @@
@VisibleForTesting
boolean isImeTraceEnabled() {
try {
+ // TODO(b/175742251): Get rid of dependency on IInputMethodManager
final Completable.Boolean value = Completable.createBoolean();
mInputMethodManager.isImeTraceEnabled(ResultCallbacks.of(value));
return Completable.getResult(value);
@@ -327,13 +328,16 @@
}
}
- private void setImeTraceEnabled(boolean isEnabled) {
+ protected void setImeTraceEnabled(boolean isEnabled) {
try {
+ // TODO(b/175742251): Get rid of dependency on IInputMethodManager
+ final Completable.Void value = Completable.createVoid();
if (isEnabled) {
- mInputMethodManager.startImeTrace();
+ mInputMethodManager.startImeTrace(ResultCallbacks.of(value));
} else {
- mInputMethodManager.stopImeTrace();
+ mInputMethodManager.stopImeTrace(ResultCallbacks.of(value));
}
+ Completable.getResult(value);
} catch (RemoteException e) {
Log.e(TAG, "Could not set ime trace status." + e.toString());
}
diff --git a/src/com/android/settings/display/AutoBrightnessDetailPreferenceController.java b/src/com/android/settings/display/AutoBrightnessDetailPreferenceController.java
index 030c5b9..3138ae0 100644
--- a/src/com/android/settings/display/AutoBrightnessDetailPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessDetailPreferenceController.java
@@ -17,8 +17,18 @@
package com.android.settings.display;
import android.content.Context;
+import android.widget.Switch;
-public class AutoBrightnessDetailPreferenceController extends AutoBrightnessPreferenceController {
+import androidx.preference.PreferenceScreen;
+
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
+/**
+ * Controller that updates the adaptive brightness.
+ */
+public class AutoBrightnessDetailPreferenceController extends
+ AutoBrightnessPreferenceController implements OnMainSwitchChangeListener {
public AutoBrightnessDetailPreferenceController(Context context, String key) {
super(context, key);
@@ -36,4 +46,21 @@
public boolean isPublicSlice() {
return true;
}
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ MainSwitchPreference pref = (MainSwitchPreference) screen.findPreference(
+ getPreferenceKey());
+ pref.addOnSwitchChangeListener(this);
+ pref.updateStatus(isChecked());
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != isChecked()) {
+ setChecked(isChecked);
+ }
+ }
}
diff --git a/src/com/android/settings/display/NightDisplayActivationPreferenceController.java b/src/com/android/settings/display/NightDisplayActivationPreferenceController.java
index cf9332b..e6217ff 100644
--- a/src/com/android/settings/display/NightDisplayActivationPreferenceController.java
+++ b/src/com/android/settings/display/NightDisplayActivationPreferenceController.java
@@ -16,43 +16,30 @@
package com.android.settings.display;
-import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;
-
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.text.TextUtils;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
+import android.widget.Switch;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
-public class NightDisplayActivationPreferenceController extends TogglePreferenceController {
+/**
+ * Controller that updates the night display.
+ */
+public class NightDisplayActivationPreferenceController extends
+ TogglePreferenceController implements OnMainSwitchChangeListener {
private final MetricsFeatureProvider mMetricsFeatureProvider;
private ColorDisplayManager mColorDisplayManager;
private NightDisplayTimeFormatter mTimeFormatter;
- private LayoutPreference mPreference;
-
- private Button mTurnOffButton;
- private Button mTurnOnButton;
-
- private final OnClickListener mListener = new OnClickListener() {
- @Override
- public void onClick(View v) {
- mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
- mColorDisplayManager.setNightDisplayActivated(
- !mColorDisplayManager.isNightDisplayActivated());
- updateStateInternal(true);
- }
- };
+ private MainSwitchPreference mPreference;
public NightDisplayActivationPreferenceController(Context context, String key) {
super(context, key);
@@ -64,7 +51,7 @@
@Override
public int getAvailabilityStatus() {
- return ColorDisplayManager.isNightDisplayAvailable(mContext) ? AVAILABLE
+ return ColorDisplayManager.isNightDisplayAvailable(mContext) ? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE;
}
@@ -82,16 +69,24 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mPreference = screen.findPreference(getPreferenceKey());
- mTurnOnButton = mPreference.findViewById(R.id.night_display_turn_on_button);
- mTurnOnButton.setOnClickListener(mListener);
- mTurnOffButton = mPreference.findViewById(R.id.night_display_turn_off_button);
- mTurnOffButton.setOnClickListener(mListener);
+ mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
+ mPreference.addOnSwitchChangeListener(this);
+ mPreference.updateStatus(mColorDisplayManager.isNightDisplayActivated());
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ final boolean activated = mColorDisplayManager.isNightDisplayActivated();
+ if (isChecked != activated) {
+ // TODO(b/179017365): Create a controller which extends TogglePreferenceController to
+ // control the toggle preference.
+ setChecked(isChecked);
+ }
}
@Override
public final void updateState(Preference preference) {
- updateStateInternal(false);
+ updateStateInternal();
}
/** FOR SLICES */
@@ -111,46 +106,14 @@
return mTimeFormatter.getAutoModeSummary(mContext, mColorDisplayManager);
}
- private void updateStateInternal(boolean selfChanged) {
- if (mTurnOnButton == null || mTurnOffButton == null) {
- return;
- }
-
+ private void updateStateInternal() {
final boolean isActivated = mColorDisplayManager.isNightDisplayActivated();
final int autoMode = mColorDisplayManager.getNightDisplayAutoMode();
- String buttonText;
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
- buttonText = mContext.getString(isActivated
- ? R.string.night_display_activation_off_custom
- : R.string.night_display_activation_on_custom,
- mTimeFormatter.getFormattedTimeString(isActivated
- ? mColorDisplayManager.getNightDisplayCustomStartTime()
- : mColorDisplayManager.getNightDisplayCustomEndTime()));
- } else if (autoMode == ColorDisplayManager.AUTO_MODE_TWILIGHT) {
- buttonText = mContext.getString(isActivated
- ? R.string.night_display_activation_off_twilight
- : R.string.night_display_activation_on_twilight);
- } else {
- buttonText = mContext.getString(isActivated
- ? R.string.night_display_activation_off_manual
- : R.string.night_display_activation_on_manual);
- }
-
- if (isActivated) {
- mTurnOnButton.setVisibility(View.GONE);
- mTurnOffButton.setVisibility(View.VISIBLE);
- mTurnOffButton.setText(buttonText);
- if (selfChanged) {
- mTurnOffButton.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
- }
- } else {
- mTurnOnButton.setVisibility(View.VISIBLE);
- mTurnOffButton.setVisibility(View.GONE);
- mTurnOnButton.setText(buttonText);
- if (selfChanged) {
- mTurnOnButton.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
- }
+ mTimeFormatter.getFormattedTimeString(isActivated
+ ? mColorDisplayManager.getNightDisplayCustomStartTime()
+ : mColorDisplayManager.getNightDisplayCustomEndTime());
}
}
}
diff --git a/src/com/android/settings/display/ScreenTimeoutSettings.java b/src/com/android/settings/display/ScreenTimeoutSettings.java
index a90c886..b518646 100644
--- a/src/com/android/settings/display/ScreenTimeoutSettings.java
+++ b/src/com/android/settings/display/ScreenTimeoutSettings.java
@@ -158,7 +158,7 @@
screen.addPreference(pref);
}
- if (isScreenAttentionAvailable()) {
+ if (isScreenAttentionAvailable(getContext())) {
mAdaptiveSleepPermissionController.addToScreen(screen);
mAdaptiveSleepController.addToScreen(screen);
screen.addPreference(mPrivacyPreference);
@@ -199,11 +199,6 @@
return R.string.help_url_adaptive_sleep;
}
- private boolean isScreenAttentionAvailable() {
- return getResources().getBoolean(
- com.android.internal.R.bool.config_adaptive_sleep_available);
- }
-
private Long getMaxScreenTimeout(Context context) {
if (context == null) {
return Long.MAX_VALUE;
@@ -239,6 +234,11 @@
}
}
+ private static boolean isScreenAttentionAvailable(Context context) {
+ return context.getResources().getBoolean(
+ com.android.internal.R.bool.config_adaptive_sleep_available);
+ }
+
private static class TimeoutCandidateInfo extends CandidateInfo {
private final CharSequence mLabel;
private final String mKey;
@@ -269,11 +269,13 @@
new BaseSearchIndexProvider(R.xml.screen_timeout_settings) {
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
boolean enabled) {
+ if (!isScreenAttentionAvailable(context)) {
+ return null;
+ }
final Resources res = context.getResources();
final SearchIndexableRaw data = new SearchIndexableRaw(context);
data.title = res.getString(R.string.adaptive_sleep_title);
data.key = AdaptiveSleepPreferenceController.PREFERENCE_KEY;
- data.screenTitle = res.getString(R.string.screen_timeout_title);
data.keywords = res.getString(R.string.adaptive_sleep_title);
final List<SearchIndexableRaw> result = new ArrayList<>(1);
diff --git a/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceController.java b/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceController.java
index 1027dac..800e7e5 100644
--- a/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceController.java
+++ b/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceController.java
@@ -19,8 +19,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.os.PowerManager;
-import android.view.View;
-import android.widget.Button;
+import android.widget.Switch;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -29,22 +28,22 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
import java.time.LocalTime;
/**
* Controller for activate/deactivate night mode button
*/
-public class DarkModeActivationPreferenceController extends BasePreferenceController {
+public class DarkModeActivationPreferenceController extends BasePreferenceController implements
+ OnMainSwitchChangeListener {
private final UiModeManager mUiModeManager;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private PowerManager mPowerManager;
- private Button mTurnOffButton;
- private Button mTurnOnButton;
private TimeFormatter mFormat;
- private LayoutPreference mPreference;
+ private MainSwitchPreference mPreference;
public DarkModeActivationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
@@ -62,49 +61,9 @@
@Override
public final void updateState(Preference preference) {
-
- final boolean batterySaver = mPowerManager.isPowerSaveMode();
- if (batterySaver) {
- mTurnOnButton.setVisibility(View.GONE);
- mTurnOffButton.setVisibility(View.GONE);
- return;
- }
-
final boolean active = (mContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_YES) != 0;
- updateNightMode(active);
- }
-
- private void updateNightMode(boolean active) {
- final int mode = mUiModeManager.getNightMode();
- String buttonText;
-
- if (mode == UiModeManager.MODE_NIGHT_AUTO) {
- buttonText = mContext.getString(active
- ? R.string.dark_ui_activation_off_auto
- : R.string.dark_ui_activation_on_auto);
- } else if (mode == UiModeManager.MODE_NIGHT_CUSTOM) {
- final LocalTime time = active
- ? mUiModeManager.getCustomNightModeStart()
- : mUiModeManager.getCustomNightModeEnd();
- final String timeStr = mFormat.of(time);
- buttonText = mContext.getString(active
- ? R.string.dark_ui_activation_off_custom
- : R.string.dark_ui_activation_on_custom, timeStr);
- } else {
- buttonText = mContext.getString(active
- ? R.string.dark_ui_activation_off_manual
- : R.string.dark_ui_activation_on_manual);
- }
- if (active) {
- mTurnOnButton.setVisibility(View.GONE);
- mTurnOffButton.setVisibility(View.VISIBLE);
- mTurnOffButton.setText(buttonText);
- } else {
- mTurnOnButton.setVisibility(View.VISIBLE);
- mTurnOffButton.setVisibility(View.GONE);
- mTurnOnButton.setText(buttonText);
- }
+ mPreference.updateStatus(active);
}
@Override
@@ -132,26 +91,19 @@
}
}
- private final View.OnClickListener mListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
- final boolean active = (mContext.getResources().getConfiguration().uiMode
- & Configuration.UI_MODE_NIGHT_YES) != 0;
- mUiModeManager.setNightModeActivated(!active);
- updateNightMode(!active);
- }
- };
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
+ final boolean active = (mContext.getResources().getConfiguration().uiMode
+ & Configuration.UI_MODE_NIGHT_YES) != 0;
+ mUiModeManager.setNightModeActivated(!active);
+ }
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
-
- mPreference = screen.findPreference(getPreferenceKey());
- mTurnOnButton = mPreference.findViewById(R.id.dark_ui_turn_on_button);
- mTurnOnButton.setOnClickListener(mListener);
- mTurnOffButton = mPreference.findViewById(R.id.dark_ui_turn_off_button);
- mTurnOffButton.setOnClickListener(mListener);
+ mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
+ mPreference.addOnSwitchChangeListener(this);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatterySaverController.java b/src/com/android/settings/fuelgauge/BatterySaverController.java
index acb5e32..a91f85c 100644
--- a/src/com/android/settings/fuelgauge/BatterySaverController.java
+++ b/src/com/android/settings/fuelgauge/BatterySaverController.java
@@ -15,37 +15,35 @@
*/
package com.android.settings.fuelgauge;
-import android.content.ContentResolver;
import android.content.Context;
-import android.database.ContentObserver;
-import android.os.Handler;
-import android.os.Looper;
import android.os.PowerManager;
-import android.provider.Settings;
-import android.provider.Settings.Global;
-import androidx.preference.Preference;
+import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.widget.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
-public class BatterySaverController extends BasePreferenceController
+/**
+ * Controller to update the battery saver entry preference.
+ */
+public class BatterySaverController extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop, BatterySaverReceiver.BatterySaverListener {
private static final String KEY_BATTERY_SAVER = "battery_saver_summary";
private final BatterySaverReceiver mBatteryStateChangeReceiver;
private final PowerManager mPowerManager;
- private Preference mBatterySaverPref;
+
+ @VisibleForTesting
+ PrimarySwitchPreference mBatterySaverPref;
public BatterySaverController(Context context) {
super(context, KEY_BATTERY_SAVER);
- mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ mPowerManager = mContext.getSystemService(PowerManager.class);
mBatteryStateChangeReceiver = new BatterySaverReceiver(context);
mBatteryStateChangeReceiver.setBatterySaverListener(this);
BatterySaverUtils.revertScheduleToNoneIfNeeded(context);
@@ -69,60 +67,38 @@
@Override
public void onStart() {
- mContext.getContentResolver().registerContentObserver(
- Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL)
- , true, mObserver);
mBatteryStateChangeReceiver.setListening(true);
- updateSummary();
}
@Override
public void onStop() {
- mContext.getContentResolver().unregisterContentObserver(mObserver);
mBatteryStateChangeReceiver.setListening(false);
}
@Override
- public CharSequence getSummary() {
- final ContentResolver resolver = mContext.getContentResolver();
- final boolean isPowerSaveOn = mPowerManager.isPowerSaveMode();
- final int percent = Settings.Global.getInt(resolver,
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
- final int mode = Settings.Global.getInt(resolver,
- Global.AUTOMATIC_POWER_SAVE_MODE, PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
- if (isPowerSaveOn) {
- return mContext.getString(R.string.battery_saver_on_summary);
- } else if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
- if (percent != 0) {
- return mContext.getString(R.string.battery_saver_off_scheduled_summary,
- Utils.formatPercentage(percent));
- } else {
- return mContext.getString(R.string.battery_saver_off_summary);
- }
- } else {
- return mContext.getString(R.string.battery_saver_auto_routine);
- }
- }
-
- private void updateSummary() {
- mBatterySaverPref.setSummary(getSummary());
- }
-
- private final ContentObserver mObserver = new ContentObserver(
- new Handler(Looper.getMainLooper())) {
- @Override
- public void onChange(boolean selfChange) {
- updateSummary();
- }
- };
-
- @Override
public void onPowerSaveModeChanged() {
- updateSummary();
+ final boolean isChecked = isChecked();
+ if (mBatterySaverPref != null && mBatterySaverPref.isChecked() != isChecked) {
+ mBatterySaverPref.setChecked(isChecked);
+ }
}
@Override
public void onBatteryChanged(boolean pluggedIn) {
+ if (mBatterySaverPref != null) {
+ mBatterySaverPref.setSwitchEnabled(!pluggedIn);
+ }
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mPowerManager.isPowerSaveMode();
+ }
+
+ @Override
+ public boolean setChecked(boolean stateOn) {
+ return BatterySaverUtils.setPowerSaveMode(mContext, stateOn,
+ false /* needFirstTimeWarning */);
}
}
diff --git a/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java
index 040af9f..ea277a1 100644
--- a/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java
@@ -20,22 +20,27 @@
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
+import android.widget.Switch;
import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
/**
* Controller to change and update the smart battery toggle
*/
public class SmartBatteryPreferenceController extends BasePreferenceController implements
- Preference.OnPreferenceChangeListener {
+ OnMainSwitchChangeListener {
+
private static final String KEY_SMART_BATTERY = "smart_battery";
private static final int ON = 1;
private static final int OFF = 0;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
+ private MainSwitchPreference mPreference;
public SmartBatteryPreferenceController(Context context) {
super(context, KEY_SMART_BATTERY);
@@ -65,14 +70,19 @@
super.updateState(preference);
final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON;
- ((SwitchPreference) preference).setChecked(smartBatteryOn);
+ ((MainSwitchPreference) preference).updateStatus(smartBatteryOn);
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean smartBatteryOn = (Boolean) newValue;
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
+ mPreference.addOnSwitchChangeListener(this);
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, smartBatteryOn ? ON : OFF);
- return true;
+ Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, isChecked ? ON : OFF);
}
}
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 2259441..aa7b2d1 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -46,11 +46,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
setContentView(R.layout.settings_homepage_container);
- final View root = findViewById(R.id.settings_homepage_container);
- root.setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
final View appBar = findViewById(R.id.app_bar_container);
appBar.setMinimumHeight(getSearchBoxHeight());
diff --git a/src/com/android/settings/network/AirplaneSafeNetworksSlice.java b/src/com/android/settings/network/AirplaneSafeNetworksSlice.java
index fbef282..763e0c7 100644
--- a/src/com/android/settings/network/AirplaneSafeNetworksSlice.java
+++ b/src/com/android/settings/network/AirplaneSafeNetworksSlice.java
@@ -23,6 +23,7 @@
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.util.Log;
@@ -33,6 +34,7 @@
import androidx.slice.builders.ListBuilder;
import androidx.slice.builders.ListBuilder.RowBuilder;
import androidx.slice.builders.SliceAction;
+import androidx.slice.core.SliceHints;
import com.android.settings.AirplaneModeEnabler;
import com.android.settings.R;
@@ -41,7 +43,6 @@
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settings.slices.SliceBroadcastReceiver;
-import com.android.settingslib.WirelessUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -49,7 +50,6 @@
/**
* {@link CustomSliceable} for airplane-safe networks, used by generic clients.
*/
-// TODO(b/173413889): Need to update the slice to Button style.
public class AirplaneSafeNetworksSlice implements CustomSliceable,
AirplaneModeEnabler.OnAirplaneModeChangedListener {
@@ -60,26 +60,29 @@
/**
* Annotation for different action of the slice.
*
- * {@code VIEW_AIRPLANE_SAFE_NETWORKS} for action of turning on Wi-Fi.
- * {@code TURN_OFF_AIRPLANE_MODE} for action of turning off Airplane Mode.
+ * {@code TURN_ON_NETWORKS} for action of turning on Wi-Fi networks.
+ * {@code TURN_OFF_NETWORKS} for action of turning off Wi-Fi networks.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(value = {
- Action.VIEW_AIRPLANE_SAFE_NETWORKS,
- Action.TURN_OFF_AIRPLANE_MODE,
+ Action.TURN_ON_NETWORKS,
+ Action.TURN_OFF_NETWORKS,
})
public @interface Action {
- int VIEW_AIRPLANE_SAFE_NETWORKS = 1;
- int TURN_OFF_AIRPLANE_MODE = 2;
+ int TURN_ON_NETWORKS = 1;
+ int TURN_OFF_NETWORKS = 2;
}
private final Context mContext;
private final AirplaneModeEnabler mAirplaneModeEnabler;
private final WifiManager mWifiManager;
+ private boolean mIsAirplaneModeOn;
+
public AirplaneSafeNetworksSlice(Context context) {
mContext = context;
mAirplaneModeEnabler = new AirplaneModeEnabler(context, this);
+ mIsAirplaneModeOn = mAirplaneModeEnabler.isAirplaneModeOn();
mWifiManager = mContext.getSystemService(WifiManager.class);
}
@@ -89,15 +92,14 @@
@Override
public Slice getSlice() {
- if (!WirelessUtils.isAirplaneModeOn(mContext)) {
- return null;
+ final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY);
+ if (mIsAirplaneModeOn) {
+ listBuilder.addRow(new RowBuilder()
+ .setTitle(getTitle())
+ .addEndItem(getEndIcon(), SliceHints.ICON_IMAGE)
+ .setPrimaryAction(getSliceAction()));
}
-
- return new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
- .addRow(new RowBuilder()
- .setTitle(getTitle())
- .setPrimaryAction(getSliceAction()))
- .build();
+ return listBuilder.build();
}
@Override
@@ -108,21 +110,22 @@
@Override
public void onNotifyChange(Intent intent) {
final int action = intent.getIntExtra(ACTION_INTENT_EXTRA, 0);
- if (action == Action.VIEW_AIRPLANE_SAFE_NETWORKS) {
+ if (action == Action.TURN_ON_NETWORKS) {
if (!mWifiManager.isWifiEnabled()) {
- logd("Action: turn on WiFi");
+ logd("Action: turn on Wi-Fi networks");
mWifiManager.setWifiEnabled(true);
}
- } else if (action == Action.TURN_OFF_AIRPLANE_MODE) {
- if (WirelessUtils.isAirplaneModeOn(mContext)) {
- logd("Action: turn off Airplane mode");
- mAirplaneModeEnabler.setAirplaneMode(false);
+ } else if (action == Action.TURN_OFF_NETWORKS) {
+ if (mWifiManager.isWifiEnabled()) {
+ logd("Action: turn off Wi-Fi networks");
+ mWifiManager.setWifiEnabled(false);
}
}
}
@Override
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
+ mIsAirplaneModeOn = isAirplaneModeOn;
final AirplaneSafeNetworksWorker worker = SliceBackgroundWorker.getInstance(getUri());
if (worker != null) {
worker.updateSlice();
@@ -140,15 +143,26 @@
@Action
private int getAction() {
return mWifiManager.isWifiEnabled()
- ? Action.TURN_OFF_AIRPLANE_MODE
- : Action.VIEW_AIRPLANE_SAFE_NETWORKS;
+ ? Action.TURN_OFF_NETWORKS
+ : Action.TURN_ON_NETWORKS;
}
private String getTitle() {
return mContext.getText(
- (getAction() == Action.VIEW_AIRPLANE_SAFE_NETWORKS)
- ? R.string.view_airplane_safe_networks
- : R.string.turn_off_airplane_mode).toString();
+ (getAction() == Action.TURN_ON_NETWORKS)
+ ? R.string.turn_on_networks
+ : R.string.turn_off_networks).toString();
+ }
+
+ private IconCompat getEndIcon() {
+ final Drawable drawable = mContext.getDrawable(
+ (getAction() == Action.TURN_ON_NETWORKS) ? R.drawable.ic_airplane_safe_networks_24dp
+ : R.drawable.ic_airplanemode_active);
+ if (drawable == null) {
+ return Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
+ }
+ drawable.setTintList(Utils.getColorAttr(mContext, android.R.attr.colorAccent));
+ return Utils.createIconWithDrawable(drawable);
}
private SliceAction getSliceAction() {
@@ -156,8 +170,7 @@
0 /* requestCode */, getIntent(),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
final IconCompat icon = Utils.createIconWithDrawable(new ColorDrawable(Color.TRANSPARENT));
- return SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.ACTION_WITH_LABEL,
- getTitle());
+ return SliceAction.create(pendingIntent, icon, ListBuilder.ACTION_WITH_LABEL, getTitle());
}
@Override
diff --git a/src/com/android/settings/network/InternetPreferenceController.java b/src/com/android/settings/network/InternetPreferenceController.java
index 0e95e2d..25ec912 100644
--- a/src/com/android/settings/network/InternetPreferenceController.java
+++ b/src/com/android/settings/network/InternetPreferenceController.java
@@ -177,6 +177,7 @@
if (subInfo == null) {
return;
}
- mPreference.setSummary(subInfo.getDisplayName());
+ mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName(
+ subInfo, mContext));
}
}
diff --git a/src/com/android/settings/network/OWNERS b/src/com/android/settings/network/OWNERS
index 991ad43..4f17e3f 100644
--- a/src/com/android/settings/network/OWNERS
+++ b/src/com/android/settings/network/OWNERS
@@ -6,5 +6,6 @@
leechou@google.com
songferngwang@google.com
tomhsu@google.com
+zoeychen@google.com
# Emergency approvers in case the above are not available
diff --git a/src/com/android/settings/network/ProviderModelSlice.java b/src/com/android/settings/network/ProviderModelSlice.java
index 48c3dc0..24077dd 100644
--- a/src/com/android/settings/network/ProviderModelSlice.java
+++ b/src/com/android/settings/network/ProviderModelSlice.java
@@ -26,7 +26,6 @@
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
-import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.util.Log;
@@ -87,9 +86,6 @@
final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()) {
log("Airplane mode is enabled.");
- listBuilder.setHeader(mHelper.createHeader(Settings.ACTION_AIRPLANE_MODE_SETTINGS));
- listBuilder.addGridRow(mHelper.createMessageGridRow(R.string.condition_airplane_title,
- Settings.ACTION_AIRPLANE_MODE_SETTINGS));
return listBuilder.build();
}
@@ -182,8 +178,9 @@
}
final int defaultSubId = subscriptionManager.getDefaultDataSubscriptionId();
log("defaultSubId:" + defaultSubId);
- if (!SubscriptionManager.isUsableSubscriptionId(defaultSubId)) {
- return; // No subscription - do nothing.
+
+ if (!defaultSubscriptionIsUsable(defaultSubId)) {
+ return;
}
boolean isToggleAction = intent.hasExtra(EXTRA_TOGGLE_STATE);
@@ -194,10 +191,14 @@
MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
false /* disableOtherSubscriptions */);
}
- doCarrierNetworkAction(isToggleAction, newState);
+
+ final boolean isDataEnabled =
+ isToggleAction ? newState : MobileNetworkUtils.isMobileDataEnabled(mContext);
+ doCarrierNetworkAction(isToggleAction, isDataEnabled);
}
- private void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
+ @VisibleForTesting
+ void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
final NetworkProviderWorker worker = getWorker();
if (worker == null) {
return;
@@ -208,7 +209,7 @@
return;
}
- if (MobileNetworkUtils.isMobileDataEnabled(mContext)) {
+ if (isDataEnabled) {
worker.connectCarrierNetwork();
}
}
@@ -258,4 +259,12 @@
.setTitle(mContext.getText(R.string.ethernet))
.setSubtitle(mContext.getText(R.string.cannot_switch_networks_while_connected));
}
+
+ /**
+ * Wrap the subscriptionManager call for test mocking.
+ */
+ @VisibleForTesting
+ protected boolean defaultSubscriptionIsUsable(int defaultSubId) {
+ return SubscriptionManager.isUsableSubscriptionId(defaultSubId);
+ }
}
diff --git a/src/com/android/settings/network/SubscriptionUtil.java b/src/com/android/settings/network/SubscriptionUtil.java
index a0f2df4..aa70459 100644
--- a/src/com/android/settings/network/SubscriptionUtil.java
+++ b/src/com/android/settings/network/SubscriptionUtil.java
@@ -242,12 +242,14 @@
public CharSequence uniqueName;
}
- final SubscriptionManager subscriptionManager =
- context.getSystemService(SubscriptionManager.class);
// Map of SubscriptionId to DisplayName
final Supplier<Stream<DisplayInfo>> originalInfos =
- () -> getActiveSubscriptions(subscriptionManager)
+ () -> getAvailableSubscriptions(context)
.stream()
+ .filter(i -> {
+ // Filter out null values.
+ return (i != null && i.getDisplayName() != null);
+ })
.map(i -> {
DisplayInfo info = new DisplayInfo();
info.subscriptionInfo = i;
diff --git a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
index daa4670..2c6c963 100644
--- a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
@@ -30,6 +30,7 @@
import androidx.preference.SwitchPreference;
import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
import java.util.Objects;
@@ -119,7 +120,8 @@
private String getLatestSummary() {
SubscriptionInfo subInfo = getSubscriptionInfo();
- return Objects.toString((subInfo == null) ? null : subInfo.getDisplayName(), "");
+ return Objects.toString((subInfo == null) ? null
+ : SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext), "");
}
private void updateSummary(String displayName) {
diff --git a/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java
index 1cd0e8e..110c582 100644
--- a/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java
+++ b/src/com/android/settings/network/telephony/DataDuringCallsPreferenceController.java
@@ -96,7 +96,7 @@
@Override
public boolean setChecked(boolean isChecked) {
- mManager.setMobileDataPolicyEnabledStatus(
+ mManager.setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL,
isChecked);
return true;
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
index e3db5eb..85d6e73 100644
--- a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
+++ b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
@@ -88,7 +88,7 @@
@Override
public boolean setChecked(boolean isChecked) {
- mTelephonyManager.setMobileDataPolicyEnabledStatus(
+ mTelephonyManager.setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, isChecked);
return isChecked == mTelephonyManager.isMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED);
diff --git a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
index f6a7d93..b66cea6 100644
--- a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
@@ -104,7 +104,7 @@
}
SwitchPreference pref = new SwitchPreference(mContext);
prefCtrl.updateState(pref);
- pref.setTitle(subInfo.getDisplayName());
+ pref.setTitle(SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext));
return pref;
}
diff --git a/src/com/android/settings/nfc/NfcEnabler.java b/src/com/android/settings/nfc/NfcEnabler.java
index 777e7d1..88482d5 100644
--- a/src/com/android/settings/nfc/NfcEnabler.java
+++ b/src/com/android/settings/nfc/NfcEnabler.java
@@ -21,16 +21,17 @@
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
-import androidx.preference.SwitchPreference;
+
+import com.android.settingslib.widget.MainSwitchPreference;
/**
* NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It turns on/off Nfc
* and ensures the summary of the preference reflects the current state.
*/
public class NfcEnabler extends BaseNfcEnabler {
- private final SwitchPreference mPreference;
+ private final MainSwitchPreference mPreference;
- public NfcEnabler(Context context, SwitchPreference preference) {
+ public NfcEnabler(Context context, MainSwitchPreference preference) {
super(context);
mPreference = preference;
}
@@ -39,19 +40,19 @@
protected void handleNfcStateChanged(int newState) {
switch (newState) {
case NfcAdapter.STATE_OFF:
- mPreference.setChecked(false);
+ mPreference.updateStatus(false);
mPreference.setEnabled(isToggleable());
break;
case NfcAdapter.STATE_ON:
- mPreference.setChecked(true);
+ mPreference.updateStatus(true);
mPreference.setEnabled(true);
break;
case NfcAdapter.STATE_TURNING_ON:
- mPreference.setChecked(true);
+ mPreference.updateStatus(true);
mPreference.setEnabled(false);
break;
case NfcAdapter.STATE_TURNING_OFF:
- mPreference.setChecked(false);
+ mPreference.updateStatus(false);
mPreference.setEnabled(false);
break;
}
diff --git a/src/com/android/settings/nfc/NfcPreferenceController.java b/src/com/android/settings/nfc/NfcPreferenceController.java
index 9bf013c..b30e7c3f 100644
--- a/src/com/android/settings/nfc/NfcPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcPreferenceController.java
@@ -23,24 +23,27 @@
import android.nfc.NfcAdapter;
import android.provider.Settings;
import android.util.Log;
+import android.widget.Switch;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
import java.io.IOException;
public class NfcPreferenceController extends TogglePreferenceController
- implements LifecycleObserver, OnResume, OnPause {
+ implements LifecycleObserver, OnResume, OnPause, OnMainSwitchChangeListener {
public static final String KEY_TOGGLE_NFC = "toggle_nfc";
private final NfcAdapter mNfcAdapter;
private NfcEnabler mNfcEnabler;
+ private MainSwitchPreference mPreference;
public NfcPreferenceController(Context context, String key) {
super(context, key);
@@ -55,10 +58,16 @@
return;
}
- final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
+ mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
+ mPreference.addOnSwitchChangeListener(this);
+ mNfcEnabler = new NfcEnabler(mContext, mPreference);
+ }
- mNfcEnabler = new NfcEnabler(mContext, switchPreference);
-
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != mNfcAdapter.isEnabled()) {
+ setChecked(isChecked);
+ }
}
@Override
@@ -129,12 +138,12 @@
* Listener for background changes to NFC.
*
* <p>
- * Listen to broadcasts from {@link NfcAdapter}. The worker will call notify changed on the
- * NFC Slice only when the following extras are present in the broadcast:
- * <ul>
- * <li>{@link NfcAdapter#STATE_ON}</li>
- * <li>{@link NfcAdapter#STATE_OFF}</li>
- * </ul>
+ * Listen to broadcasts from {@link NfcAdapter}. The worker will call notify changed on the
+ * NFC Slice only when the following extras are present in the broadcast:
+ * <ul>
+ * <li>{@link NfcAdapter#STATE_ON}</li>
+ * <li>{@link NfcAdapter#STATE_OFF}</li>
+ * </ul>
*/
public static class NfcSliceWorker extends SliceBackgroundWorker<Void> {
@@ -185,7 +194,7 @@
NO_EXTRA);
// Do nothing if state change is empty, or an intermediate step.
- if ( (nfcStateExtra == NO_EXTRA)
+ if ((nfcStateExtra == NO_EXTRA)
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_ON)
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_OFF)) {
Log.d(TAG, "Transitional update, dropping broadcast");
diff --git a/src/com/android/settings/notification/app/BlockPreferenceController.java b/src/com/android/settings/notification/app/BlockPreferenceController.java
index e5a7e98..4df3e28 100644
--- a/src/com/android/settings/notification/app/BlockPreferenceController.java
+++ b/src/com/android/settings/notification/app/BlockPreferenceController.java
@@ -72,16 +72,16 @@
bar.setDisabledByAdmin(mAdmin);
if (mChannel != null && !isChannelBlockable()) {
- bar.setEnabled(false);
+ bar.setSwitchBarEnabled(false);
}
if (mChannelGroup != null && !isChannelGroupBlockable()) {
- bar.setEnabled(false);
+ bar.setSwitchBarEnabled(false);
}
if (mChannel == null && mAppRow.systemApp
&& (!mAppRow.banned || mAppRow.lockedImportance)) {
- bar.setEnabled(false);
+ bar.setSwitchBarEnabled(false);
}
if (mChannel != null) {
diff --git a/src/com/android/settings/notification/zen/ZenModeButtonPreferenceController.java b/src/com/android/settings/notification/zen/ZenModeButtonPreferenceController.java
index dc338bd..a431883 100644
--- a/src/com/android/settings/notification/zen/ZenModeButtonPreferenceController.java
+++ b/src/com/android/settings/notification/zen/ZenModeButtonPreferenceController.java
@@ -16,37 +16,33 @@
package com.android.settings.notification.zen;
-import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;
-
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.provider.Settings;
-import android.view.View;
-import android.widget.Button;
+import android.widget.Switch;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.notification.SettingsEnableZenModeDialog;
import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController
- implements PreferenceControllerMixin {
+ implements PreferenceControllerMixin, OnMainSwitchChangeListener {
+
+ private static final String TAG = "EnableZenModeButton";
public static final String KEY = "zen_mode_toggle";
- private static final String TAG = "EnableZenModeButton";
private final FragmentManager mFragment;
- // DND can also be toggled from QS. If DND wasn't toggled by this preference, don't
- // reroute focus.
- private boolean mRefocusButton = false;
- private Button mZenButtonOn;
- private Button mZenButtonOff;
+ // DND can also be toggled from QS.
+ private MainSwitchPreference mPreference;
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
fragment) {
@@ -65,25 +61,26 @@
}
@Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
+ mPreference.addOnSwitchChangeListener(this);
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked) {
+ updateZenModeState(mPreference);
+ } else {
+ writeMetrics(mPreference, false);
+ mBackend.setZenMode(Settings.Global.ZEN_MODE_OFF);
+ }
+ }
+
+ @Override
public void updateState(Preference preference) {
super.updateState(preference);
- if (null == mZenButtonOn) {
- mZenButtonOn = ((LayoutPreference) preference)
- .findViewById(R.id.zen_mode_settings_turn_on_button);
- updateZenButtonOnClickListener(preference);
- }
-
- if (null == mZenButtonOff) {
- mZenButtonOff = ((LayoutPreference) preference)
- .findViewById(R.id.zen_mode_settings_turn_off_button);
- mZenButtonOff.setOnClickListener(v -> {
- mRefocusButton = true;
- writeMetrics(preference, false);
- mBackend.setZenMode(Settings.Global.ZEN_MODE_OFF);
- });
- }
-
updatePreference(preference);
}
@@ -92,41 +89,27 @@
case Settings.Global.ZEN_MODE_ALARMS:
case Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
- mZenButtonOff.setVisibility(View.VISIBLE);
- mZenButtonOn.setVisibility(View.GONE);
- if (mRefocusButton) {
- mRefocusButton = false;
- mZenButtonOff.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
- }
+ mPreference.updateStatus(true);
break;
case Settings.Global.ZEN_MODE_OFF:
default:
- mZenButtonOff.setVisibility(View.GONE);
- updateZenButtonOnClickListener(preference);
- mZenButtonOn.setVisibility(View.VISIBLE);
- if (mRefocusButton) {
- mRefocusButton = false;
- mZenButtonOn.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
- }
+ mPreference.updateStatus(false);
}
}
- private void updateZenButtonOnClickListener(Preference preference) {
- mZenButtonOn.setOnClickListener(v -> {
- mRefocusButton = true;
- writeMetrics(preference, true);
- int zenDuration = getZenDuration();
- switch (zenDuration) {
- case Settings.Secure.ZEN_DURATION_PROMPT:
- new SettingsEnableZenModeDialog().show(mFragment, TAG);
- break;
- case Settings.Secure.ZEN_DURATION_FOREVER:
- mBackend.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- break;
- default:
- mBackend.setZenModeForDuration(zenDuration);
- }
- });
+ private void updateZenModeState(Preference preference) {
+ writeMetrics(preference, true);
+ int zenDuration = getZenDuration();
+ switch (zenDuration) {
+ case Settings.Secure.ZEN_DURATION_PROMPT:
+ new SettingsEnableZenModeDialog().show(mFragment, TAG);
+ break;
+ case Settings.Secure.ZEN_DURATION_FOREVER:
+ mBackend.setZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ break;
+ default:
+ mBackend.setZenModeForDuration(zenDuration);
+ }
}
private void writeMetrics(Preference preference, boolean buttonOn) {
@@ -135,4 +118,4 @@
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ZEN_TOGGLE_DND_BUTTON,
buttonOn);
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/panel/InternetConnectivityPanel.java b/src/com/android/settings/panel/InternetConnectivityPanel.java
index 7bafe97..c90d22b 100644
--- a/src/com/android/settings/panel/InternetConnectivityPanel.java
+++ b/src/com/android/settings/panel/InternetConnectivityPanel.java
@@ -19,6 +19,7 @@
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
+import static com.android.settings.network.InternetUpdater.INTERNET_APM;
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
import static com.android.settings.network.NetworkProviderSettings.ACTION_NETWORK_PROVIDER_SETTINGS;
@@ -83,6 +84,9 @@
mInternetUpdater.onPause();
}
+ /**
+ * @return a string for the title of the Panel.
+ */
@Override
public CharSequence getTitle() {
if (mIsProviderModelEnabled) {
@@ -93,10 +97,21 @@
return mContext.getText(R.string.internet_connectivity_panel_title);
}
+ /**
+ * @return a string for the subtitle of the Panel.
+ */
+ @Override
+ public CharSequence getSubTitle() {
+ if (mIsProviderModelEnabled && mInternetType == INTERNET_APM) {
+ return mContext.getText(R.string.condition_airplane_title);
+ }
+ return null;
+ }
+
@Override
public List<Uri> getSlices() {
final List<Uri> uris = new ArrayList<>();
- if (Utils.isProviderModelEnabled(mContext)) {
+ if (mIsProviderModelEnabled) {
uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
uris.add(CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
} else {
@@ -109,18 +124,21 @@
@Override
public Intent getSeeMoreIntent() {
- return new Intent(Utils.isProviderModelEnabled(mContext)
+ return new Intent(mIsProviderModelEnabled
? ACTION_NETWORK_PROVIDER_SETTINGS : Settings.ACTION_WIRELESS_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
@Override
public boolean isCustomizedButtonUsed() {
- return Utils.isProviderModelEnabled(mContext);
+ return mIsProviderModelEnabled;
}
@Override
public CharSequence getCustomizedButtonTitle() {
+ if (mInternetType == INTERNET_APM) {
+ return null;
+ }
return mContext.getText(R.string.settings_button);
}
@@ -145,18 +163,35 @@
* @param internetType the internet type
*/
public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
- final boolean needRefresh = internetType != mInternetType
- && (internetType == INTERNET_APM_NETWORKS
- || mInternetType == INTERNET_APM_NETWORKS);
- mInternetType = internetType;
- if (needRefresh) {
- refresh();
+ if (internetType == mInternetType) {
+ return;
}
- }
- private void refresh() {
+ final boolean changeToApm = (internetType == INTERNET_APM);
+ final boolean changeFromApm = (mInternetType == INTERNET_APM);
+ final boolean changeWithApmNetworks =
+ (internetType == INTERNET_APM_NETWORKS || mInternetType == INTERNET_APM_NETWORKS);
+ mInternetType = internetType;
+
if (mCallback != null) {
- mCallback.onTitleChanged();
+ if (changeToApm) {
+ // The internet type is changed to the airplane mode.
+ // Title: Internet
+ // Sub-Title: Airplane mode is on
+ // Settings button: Hide
+ mCallback.onHeaderChanged();
+ mCallback.onCustomizedButtonStateChanged();
+ } else if (changeFromApm) {
+ // The internet type is changed from the airplane mode.
+ // Title: Internet
+ // Settings button: Show
+ mCallback.onTitleChanged();
+ mCallback.onCustomizedButtonStateChanged();
+ } else if (changeWithApmNetworks) {
+ // The internet type is changed with the airplane mode networks.
+ // Title: Airplane mode networks / Internet
+ mCallback.onTitleChanged();
+ }
}
}
}
diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java
index 503b34a..e7c1bef 100644
--- a/src/com/android/settings/panel/PanelFragment.java
+++ b/src/com/android/settings/panel/PanelFragment.java
@@ -26,6 +26,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -94,6 +95,7 @@
private LinearLayout mPanelHeader;
private ImageView mTitleIcon;
private LinearLayout mTitleGroup;
+ private LinearLayout mHeaderLayout;
private TextView mHeaderTitle;
private TextView mHeaderSubtitle;
private int mMaxHeight;
@@ -202,6 +204,7 @@
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
mTitleGroup = mLayoutView.findViewById(R.id.title_group);
+ mHeaderLayout = mLayoutView.findViewById(R.id.header_layout);
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
@@ -239,13 +242,12 @@
final IconCompat icon = mPanel.getIcon();
final CharSequence title = mPanel.getTitle();
+ final CharSequence subtitle = mPanel.getSubTitle();
- if (icon != null) {
- enablePanelHeader(icon, title);
+ if (icon != null || (subtitle != null && subtitle.length() > 0)) {
+ enablePanelHeader(icon, title, subtitle);
} else {
- mTitleView.setVisibility(View.VISIBLE);
- mPanelHeader.setVisibility(View.GONE);
- mTitleView.setText(title);
+ enableTitle(title);
}
mFooterDivider.setVisibility(View.GONE);
@@ -254,13 +256,7 @@
mDoneButton.setOnClickListener(getCloseListener());
if (mPanel.isCustomizedButtonUsed()) {
- final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
- if (TextUtils.isEmpty(customTitle)) {
- mSeeMoreButton.setVisibility(View.GONE);
- } else {
- mSeeMoreButton.setVisibility(View.VISIBLE);
- mSeeMoreButton.setText(customTitle);
- }
+ enableCustomizedButton();
} else if (mPanel.getSeeMoreIntent() == null) {
// If getSeeMoreIntent() is null hide the mSeeMoreButton.
mSeeMoreButton.setVisibility(View.GONE);
@@ -275,14 +271,16 @@
0 /* value */);
}
- private void enablePanelHeader(IconCompat icon, CharSequence title) {
+ private void enablePanelHeader(IconCompat icon, CharSequence title, CharSequence subtitle) {
mTitleView.setVisibility(View.GONE);
mPanelHeader.setVisibility(View.VISIBLE);
mPanelHeader.setAccessibilityPaneTitle(title);
mHeaderTitle.setText(title);
- mHeaderSubtitle.setText(mPanel.getSubTitle());
+ mHeaderSubtitle.setText(subtitle);
+ mHeaderSubtitle.setAccessibilityPaneTitle(subtitle);
if (icon != null) {
mTitleGroup.setVisibility(View.VISIBLE);
+ mHeaderLayout.setGravity(Gravity.LEFT);
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
if (mPanel.getHeaderIconIntent() != null) {
mTitleIcon.setOnClickListener(getHeaderIconListener());
@@ -295,6 +293,24 @@
}
} else {
mTitleGroup.setVisibility(View.GONE);
+ mHeaderLayout.setGravity(Gravity.CENTER_HORIZONTAL);
+ }
+ }
+
+ private void enableTitle(CharSequence title) {
+ mPanelHeader.setVisibility(View.GONE);
+ mTitleView.setVisibility(View.VISIBLE);
+ mTitleView.setAccessibilityPaneTitle(title);
+ mTitleView.setText(title);
+ }
+
+ private void enableCustomizedButton() {
+ final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
+ if (TextUtils.isEmpty(customTitle)) {
+ mSeeMoreButton.setVisibility(View.GONE);
+ } else {
+ mSeeMoreButton.setVisibility(View.VISIBLE);
+ mSeeMoreButton.setText(customTitle);
}
}
@@ -487,24 +503,14 @@
@Override
public void onCustomizedButtonStateChanged() {
ThreadUtils.postOnMainThread(() -> {
- mSeeMoreButton.setVisibility(
- mPanel.isCustomizedButtonUsed() ? View.VISIBLE : View.GONE);
- mSeeMoreButton.setText(mPanel.getCustomizedButtonTitle());
+ enableCustomizedButton();
});
}
@Override
public void onHeaderChanged() {
ThreadUtils.postOnMainThread(() -> {
- final IconCompat icon = mPanel.getIcon();
- if (icon != null) {
- mTitleIcon.setImageIcon(icon.toIcon(getContext()));
- mTitleGroup.setVisibility(View.VISIBLE);
- } else {
- mTitleGroup.setVisibility(View.GONE);
- }
- mHeaderTitle.setText(mPanel.getTitle());
- mHeaderSubtitle.setText(mPanel.getSubTitle());
+ enablePanelHeader(mPanel.getIcon(), mPanel.getTitle(), mPanel.getSubTitle());
});
}
@@ -517,7 +523,7 @@
@Override
public void onTitleChanged() {
ThreadUtils.postOnMainThread(() -> {
- mTitleView.setText(mPanel.getTitle());
+ enableTitle(mPanel.getTitle());
});
}
diff --git a/src/com/android/settings/security/CredentialStorage.java b/src/com/android/settings/security/CredentialStorage.java
index 2e3e2ed..53a1a59 100644
--- a/src/com/android/settings/security/CredentialStorage.java
+++ b/src/com/android/settings/security/CredentialStorage.java
@@ -44,6 +44,7 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
+import com.android.settings.core.HideNonSystemOverlayMixin;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.vpn2.VpnUtils;
@@ -75,6 +76,7 @@
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
mUtils = new LockPatternUtils(this);
+ getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
}
@Override
diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java b/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
index 563b4ef..f2c7c65 100644
--- a/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
+++ b/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
@@ -52,10 +52,9 @@
ThreadUtils.postOnBackgroundThread(
() -> {
synchronized (mLock) {
- if (!shouldHandleSlotChange(context)) {
- return;
+ if (shouldHandleSlotChange(context)) {
+ mSlotChangeHandler.onSlotsStatusChange(context.getApplicationContext());
}
- mSlotChangeHandler.onSlotsStatusChange(context.getApplicationContext());
}
ThreadUtils.postOnMainThread(pendingResult::finish);
});
diff --git a/src/com/android/settings/widget/SettingsMainSwitchPreference.java b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
index 4597842..2a7aa73 100644
--- a/src/com/android/settings/widget/SettingsMainSwitchPreference.java
+++ b/src/com/android/settings/widget/SettingsMainSwitchPreference.java
@@ -17,8 +17,11 @@
package com.android.settings.widget;
import android.content.Context;
+import android.content.res.TypedArray;
+import android.text.TextUtils;
import android.util.AttributeSet;
+import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.TwoStatePreference;
@@ -47,23 +50,23 @@
public SettingsMainSwitchPreference(Context context) {
super(context);
- init();
+ init(context, null);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- init();
+ init(context, attrs);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- init();
+ init(context, attrs);
}
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
- init();
+ init(context, attrs);
}
@Override
@@ -79,8 +82,21 @@
registerListenerToSwitchBar();
}
- private void init() {
+ private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.preference_widget_main_switch);
+
+ if (attrs != null) {
+ TypedArray a = context.obtainStyledAttributes(attrs,
+ androidx.preference.R.styleable.Preference, 0/*defStyleAttr*/,
+ 0/*defStyleRes*/);
+ final CharSequence title = TypedArrayUtils.getText(a,
+ androidx.preference.R.styleable.Preference_title,
+ androidx.preference.R.styleable.Preference_android_title);
+ if (!TextUtils.isEmpty(title)) {
+ setTitle(title.toString());
+ }
+ a.recycle();
+ }
}
/**
@@ -153,7 +169,7 @@
/**
* Enable or disable the text and switch.
*/
- public void setEnabled(boolean enabled) {
+ public void setSwitchBarEnabled(boolean enabled) {
if (mMainSwitchBar != null) {
mMainSwitchBar.setEnabled(enabled);
}
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index cfee53c..65e45b7 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -67,6 +67,7 @@
import androidx.annotation.VisibleForTesting;
+import com.android.net.module.util.ProxyUtils;
import com.android.settings.ProxySelector;
import com.android.settings.R;
import com.android.settings.network.SubscriptionUtil;
@@ -1408,7 +1409,8 @@
if (proxyProperties != null) {
mProxyHostView.setText(proxyProperties.getHost());
mProxyPortView.setText(Integer.toString(proxyProperties.getPort()));
- mProxyExclusionListView.setText(proxyProperties.getExclusionListAsString());
+ mProxyExclusionListView.setText(
+ ProxyUtils.exclusionListAsString(proxyProperties.getExclusionList()));
}
}
} else if (mProxySettingsSpinner.getSelectedItemPosition() == PROXY_PAC) {
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 62f2352..49f1b21 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -65,6 +65,7 @@
import androidx.annotation.VisibleForTesting;
+import com.android.net.module.util.ProxyUtils;
import com.android.settings.ProxySelector;
import com.android.settings.R;
import com.android.settings.network.SubscriptionUtil;
@@ -1372,7 +1373,8 @@
if (proxyProperties != null) {
mProxyHostView.setText(proxyProperties.getHost());
mProxyPortView.setText(Integer.toString(proxyProperties.getPort()));
- mProxyExclusionListView.setText(proxyProperties.getExclusionListAsString());
+ mProxyExclusionListView.setText(
+ ProxyUtils.exclusionListAsString(proxyProperties.getExclusionList()));
}
}
} else if (mProxySettingsSpinner.getSelectedItemPosition() == PROXY_PAC) {
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index ada4c0e..89f8449 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -37,6 +37,7 @@
import com.android.settings.core.OnActivityResultListener;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
import org.junit.Test;
@@ -46,11 +47,13 @@
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowUserManager.class)
public class SettingsActivityTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/accessibility/ShortcutsSettingsFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ShortcutsSettingsFragmentTest.java
new file mode 100644
index 0000000..12b568f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/ShortcutsSettingsFragmentTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2021 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settings.testutils.XmlTestUtils;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.List;
+
+/** Tests for {@link ShortcutsSettingsFragment}. */
+@RunWith(RobolectricTestRunner.class)
+public class ShortcutsSettingsFragmentTest {
+
+ private Context mContext = ApplicationProvider.getApplicationContext();
+
+ @Test
+ public void getNonIndexableKeys_existInXmlLayout() {
+ final List<String> niks = ShortcutsSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(mContext);
+ final List<String> keys =
+ XmlTestUtils.getKeysFromPreferenceXml(mContext,
+ R.xml.accessibility_shortcuts_settings);
+
+ assertThat(keys).containsAtLeastElementsIn(niks);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
index 80f21fc..02b318f 100644
--- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
@@ -43,6 +43,7 @@
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
+import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
import org.junit.Test;
@@ -61,6 +62,7 @@
import org.robolectric.shadows.ShadowPackageManager;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowUserManager.class)
public class AvatarViewMixinTest {
private static final String FAKE_ACCOUNT = "test@domain.com";
private static final String FAKE_DOMAIN = "domain.com";
diff --git a/tests/robotests/src/com/android/settings/accounts/TopLevelAccountEntryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/TopLevelAccountEntryPreferenceControllerTest.java
index 1cd5fb1..3a67d7f 100644
--- a/tests/robotests/src/com/android/settings/accounts/TopLevelAccountEntryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/TopLevelAccountEntryPreferenceControllerTest.java
@@ -48,15 +48,12 @@
mController = new TopLevelAccountEntryPreferenceController(mContext, "test_key");
LABELS = ShadowAuthenticationHelper.getLabels();
TYPES = ShadowAuthenticationHelper.getTypes();
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@After
public void tearDown() {
ShadowAuthenticationHelper.reset();
-
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
}
@Test
diff --git a/tests/robotests/src/com/android/settings/backup/BackupSettingsHelperTest.java b/tests/robotests/src/com/android/settings/backup/BackupSettingsHelperTest.java
index b6ef32c..a662be8 100644
--- a/tests/robotests/src/com/android/settings/backup/BackupSettingsHelperTest.java
+++ b/tests/robotests/src/com/android/settings/backup/BackupSettingsHelperTest.java
@@ -35,8 +35,10 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.util.FeatureFlagUtils;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
import org.junit.Before;
import org.junit.Test;
@@ -81,6 +83,7 @@
when(mBackupManager.getCurrentTransport()).thenReturn("test_transport");
mBackupSettingsHelper = new BackupSettingsHelper(mContext);
mUserManager = Shadow.extract(mContext.getSystemService(Context.USER_SERVICE));
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/TopLevelConnectedDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/TopLevelConnectedDevicesPreferenceControllerTest.java
index 232bc16..b1f9ed1 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/TopLevelConnectedDevicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/TopLevelConnectedDevicesPreferenceControllerTest.java
@@ -27,7 +27,6 @@
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,13 +46,7 @@
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new TopLevelConnectedDevicesPreferenceController(mContext, "test_key");
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index a0024c0..1e6bc41 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -77,7 +77,6 @@
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -147,13 +146,7 @@
.thenReturn(new ResolveInfo());
mFeatureFactory = FakeFeatureFactory.setupForTest();
mImpl = new DashboardFeatureProviderImpl(mContext);
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java b/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java
index 88e2886..52ba7a7 100644
--- a/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java
+++ b/tests/robotests/src/com/android/settings/development/qstile/WinscopeTraceTest.java
@@ -24,8 +24,10 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@@ -72,6 +74,7 @@
// default ImeTraceEnabled value, prevent tests from actually calling into IMM and
// await the result forever.
doReturn(false).when(mWinscopeTrace).isImeTraceEnabled();
+ doNothing().when(mWinscopeTrace).setImeTraceEnabled(anyBoolean());
ReflectionHelpers.setField(mWinscopeTrace, "mWindowManager", mWindowManager);
ReflectionHelpers.setField(mWinscopeTrace, "mInputMethodManager", mInputMethodManager);
ReflectionHelpers.setField(mWinscopeTrace, "mSurfaceFlinger", mSurfaceFlinger);
@@ -182,7 +185,7 @@
@Test
public void setIsEnableTrue_shouldEnableImeTrace() throws RemoteException {
mWinscopeTrace.setIsEnabled(true);
- verify(mInputMethodManager).startImeTrace();
+ verify(mWinscopeTrace).setImeTraceEnabled(eq(true));
verifyNoMoreInteractions(mInputMethodManager);
}
@@ -210,7 +213,7 @@
@Config(shadows = ShadowParcel.class)
public void setIsEnableFalse_shouldDisableImeTrace() throws RemoteException {
mWinscopeTrace.setIsEnabled(false);
- verify(mInputMethodManager).stopImeTrace();
+ verify(mWinscopeTrace).setImeTraceEnabled(eq(false));
verifyNoMoreInteractions(mInputMethodManager);
verify(mToast).show();
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
index e19066a..7e6be9b 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/TopLevelStoragePreferenceControllerTest.java
@@ -36,7 +36,6 @@
import com.android.settings.core.FeatureFlags;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -69,13 +68,7 @@
when(mStorageManagerVolumeProvider.getVolumes()).thenReturn(mVolumes);
mController = new TopLevelStoragePreferenceController(mContext, "test_key");
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java
index 16c77a4..d20beab 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java
@@ -27,7 +27,6 @@
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,13 +43,7 @@
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new TopLevelAboutDevicePreferenceController(mContext, "test_key");
- }
-
- @After
- public void teardown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java
index bad112a..d084c51 100644
--- a/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java
@@ -21,13 +21,11 @@
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
-import android.view.View;
import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.After;
import org.junit.Before;
@@ -45,7 +43,7 @@
@Mock
private PreferenceScreen mScreen;
- private LayoutPreference mPreference;
+ private MainSwitchPreference mPreference;
private Context mContext;
private ColorDisplayManager mColorDisplayManager;
private NightDisplayActivationPreferenceController mPreferenceController;
@@ -55,7 +53,7 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
- mPreference = new LayoutPreference(mContext, R.layout.night_display_activation_button);
+ mPreference = new MainSwitchPreference(mContext);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mPreferenceController = new NightDisplayActivationPreferenceController(mContext,
"night_display_activation");
@@ -104,9 +102,9 @@
public void onClick_activates() {
mColorDisplayManager.setNightDisplayActivated(false);
- final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
- assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
- view.performClick();
+ final NightDisplayActivationPreferenceController controller =
+ new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
+ controller.onSwitchChanged(null, true);
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(true);
}
@@ -115,9 +113,9 @@
public void onClick_deactivates() {
mColorDisplayManager.setNightDisplayActivated(true);
- final View view = mPreference.findViewById(R.id.night_display_turn_off_button);
- assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
- view.performClick();
+ final NightDisplayActivationPreferenceController controller =
+ new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
+ controller.onSwitchChanged(null, false);
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(false);
}
diff --git a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
index 621ddfa..efc45e0 100644
--- a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java
@@ -87,6 +87,7 @@
com.android.internal.R.bool.config_adaptive_sleep_available);
doReturn(null).when(mContext).getSystemService(DevicePolicyManager.class);
+ doReturn(mResources).when(mContext).getResources();
doReturn(mResources).when(mSettings).getResources();
doReturn(mContext).when(mSettings).getContext();
diff --git a/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java
index a52ad71..864d2b9 100644
--- a/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java
@@ -36,7 +36,6 @@
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,13 +65,7 @@
when(mContext.getString(R.string.config_wallpaper_picker_class)).thenReturn("cls");
mController = new TopLevelDisplayPreferenceController(mContext, "test_key");
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java
index 33d0927c..0d4646e 100644
--- a/tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java
@@ -23,9 +23,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.UiModeManager;
@@ -33,13 +32,12 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.PowerManager;
-import android.view.View;
-import android.widget.Button;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settingslib.widget.LayoutPreference;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -47,6 +45,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import java.util.Locale;
@@ -54,25 +53,21 @@
public class DarkModeActivationPreferenceControllerTest {
private DarkModeActivationPreferenceController mController;
private String mPreferenceKey = "key";
+
@Mock
- private LayoutPreference mPreference;
+ private MainSwitchPreference mPreference;
@Mock
private PreferenceScreen mScreen;
@Mock
private Resources res;
@Mock
- private Context mContext;
- @Mock
private UiModeManager mService;
@Mock
- private Button mTurnOffButton;
- @Mock
- private Button mTurnOnButton;
- @Mock
private PowerManager mPM;
@Mock
private TimeFormatter mFormat;
+ private Context mContext;
private Configuration mConfigNightYes = new Configuration();
private Configuration mConfigNightNo = new Configuration();
private Locale mLocal = new Locale("ENG");
@@ -80,16 +75,14 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest();
+ mContext = spy(RuntimeEnvironment.application);
mService = mock(UiModeManager.class);
when(mContext.getResources()).thenReturn(res);
when(res.getConfiguration()).thenReturn(mConfigNightNo);
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService);
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- when(mPreference.findViewById(
- eq(R.id.dark_ui_turn_on_button))).thenReturn(mTurnOnButton);
- when(mPreference.findViewById(
- eq(R.id.dark_ui_turn_off_button))).thenReturn(mTurnOffButton);
when(mService.setNightModeActivated(anyBoolean())).thenReturn(true);
when(mFormat.of(any())).thenReturn("10:00 AM");
when(mContext.getString(
@@ -124,66 +117,55 @@
public void nightMode_toggleButton_offManual() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
when(res.getConfiguration()).thenReturn(mConfigNightYes);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
mController.updateState(mPreference);
- verify(mTurnOnButton).setVisibility(eq(View.GONE));
- verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
- verify(mTurnOffButton).setText(eq(mContext.getString(
- R.string.dark_ui_activation_off_manual)));
+ assertThat(preference.isChecked()).isFalse();
}
@Test
public void nightMode_toggleButton_offCustom() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
when(res.getConfiguration()).thenReturn(mConfigNightYes);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- verify(mTurnOnButton).setVisibility(eq(View.GONE));
- verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
- verify(mTurnOffButton).setText(eq(mContext.getString(
- R.string.dark_ui_activation_off_custom)));
+ assertThat(preference.isChecked()).isFalse();
}
@Test
public void nightMode_toggleButton_onCustom() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
when(res.getConfiguration()).thenReturn(mConfigNightYes);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- verify(mTurnOnButton).setVisibility(eq(View.GONE));
- verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
- verify(mTurnOffButton).setText(eq(mContext.getString(
- R.string.dark_ui_activation_on_custom)));
+ assertThat(preference.isChecked()).isFalse();
}
-
@Test
public void nightMode_toggleButton_onAutoWhenModeIsYes() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
when(res.getConfiguration()).thenReturn(mConfigNightNo);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext, null);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- verify(mTurnOffButton).setVisibility(eq(View.GONE));
- verify(mTurnOnButton).setVisibility(eq(View.VISIBLE));
- verify(mTurnOnButton).setText(eq(mContext.getString(
- R.string.dark_ui_activation_on_manual)));
+ assertThat(preference.isChecked()).isFalse();
}
@Test
public void nightMode_toggleButton_onAutoWhenModeIsAuto() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
when(res.getConfiguration()).thenReturn(mConfigNightNo);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- verify(mTurnOffButton).setVisibility(eq(View.GONE));
- verify(mTurnOnButton).setVisibility(eq(View.VISIBLE));
- verify(mTurnOnButton).setText(eq(mContext.getString(
- R.string.dark_ui_activation_on_auto)));
+ assertThat(preference.isChecked()).isFalse();
}
@Test
@@ -207,9 +189,10 @@
@Test
public void buttonVisisbility_hideButton_offWhenInPowerSaveMode() {
when(mPM.isPowerSaveMode()).thenReturn(true);
- mController.updateState(mPreference);
- verify(mTurnOffButton).setVisibility(eq(View.GONE));
- verify(mTurnOnButton).setVisibility(eq(View.GONE));
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
+
+ mController.updateState(preference);
+ assertThat(preference.isChecked()).isFalse();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
index db9ffa5..4d2910e 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySaverControllerTest.java
@@ -17,15 +17,20 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.PowerManager;
-import android.provider.Settings;
+import android.view.LayoutInflater;
+import android.widget.LinearLayout;
-import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+
+import com.android.settings.R;
+import com.android.settings.widget.PrimarySwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -34,64 +39,108 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class BatterySaverControllerTest {
@Mock
- private Preference mBatterySaverPref;
- @Mock
private PowerManager mPowerManager;
private BatterySaverController mBatterySaverController;
- private Context mContext;
+ private PrimarySwitchPreference mBatterySaverPref;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ final Context mContext = spy(RuntimeEnvironment.application);
- mContext = RuntimeEnvironment.application;
- mBatterySaverController = spy(new BatterySaverController(mContext));
- ReflectionHelpers.setField(mBatterySaverController, "mPowerManager", mPowerManager);
- ReflectionHelpers.setField(mBatterySaverController, "mBatterySaverPref", mBatterySaverPref);
+ mBatterySaverPref = new PrimarySwitchPreference(mContext);
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final PreferenceViewHolder mHolder =
+ PreferenceViewHolder.createInstanceForTests(inflater.inflate(
+ com.android.settingslib.R.layout.preference_two_target, null));
+ final LinearLayout mWidgetView = mHolder.itemView.findViewById(android.R.id.widget_frame);
+ inflater.inflate(R.layout.restricted_preference_widget_primary_switch, mWidgetView, true);
+ mBatterySaverPref.onBindViewHolder(mHolder);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
+ doReturn(mPowerManager).when(mContext).getSystemService(Context.POWER_SERVICE);
+
+ mBatterySaverController = new BatterySaverController(mContext);
+ mBatterySaverController.mBatterySaverPref = mBatterySaverPref;
}
@Test
- public void onPreferenceChange_onStart() {
- mBatterySaverController.onStart();
- verify(mBatterySaverPref).setSummary("Off");
+ public void onBatteryChanged_true_switchEnabled() {
+ mBatterySaverController.onBatteryChanged(true);
+
+ assertThat(mBatterySaverPref.getSwitch().isEnabled()).isFalse();
}
@Test
- public void onPreferenceChange_onPowerSaveModeChanged() {
- mBatterySaverController.onPowerSaveModeChanged();
- verify(mBatterySaverPref).setSummary("Off");
+ public void onBatteryChanged_false_switchDisabled() {
+ mBatterySaverController.onBatteryChanged(false);
+
+ assertThat(mBatterySaverPref.getSwitch().isEnabled()).isTrue();
}
@Test
- public void getSummary_batterySaverOn_showSummaryOn() {
+ public void onPowerSaveModeChanged_differentState_updateToIsChecked() {
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
- assertThat(mBatterySaverController.getSummary()).isEqualTo("On");
+ assertThat(mBatterySaverPref.isChecked()).isFalse();
+
+ mBatterySaverController.onPowerSaveModeChanged();
+
+ assertThat(mBatterySaverPref.isChecked()).isTrue();
}
@Test
- public void getSummary_batterySaverOffButScheduled_showSummaryScheduled() {
- when(mPowerManager.isPowerSaveMode()).thenReturn(false);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 15);
+ public void onPowerSaveModeChanged_differentState_updateToUnChecked() {
+ mBatterySaverPref.setChecked(true);
- assertThat(mBatterySaverController.getSummary()).isEqualTo("Will turn on at 15%");
+ when(mPowerManager.isPowerSaveMode()).thenReturn(false);
+ assertThat(mBatterySaverPref.isChecked()).isTrue();
+
+ mBatterySaverController.onPowerSaveModeChanged();
+
+ assertThat(mBatterySaverPref.isChecked()).isFalse();
}
@Test
- public void getSummary_batterySaverOff_showSummaryOff() {
+ public void onPowerSaveModeChanged_sameState_noUpdate() {
+ when(mPowerManager.isPowerSaveMode()).thenReturn(false);
+ assertThat(mBatterySaverPref.isChecked()).isFalse();
+
+ mBatterySaverController.onPowerSaveModeChanged();
+
+ assertThat(mBatterySaverPref.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setChecked_on_setPowerSaveMode() {
+ mBatterySaverController.setChecked(true);
+
+ verify(mPowerManager).setPowerSaveModeEnabled(true);
+ }
+
+ @Test
+ public void setChecked_off_unsetPowerSaveMode() {
+ mBatterySaverController.setChecked(false);
+
+ verify(mPowerManager).setPowerSaveModeEnabled(false);
+ }
+
+ @Test
+ public void isChecked_on_powerSaveModeOn() {
+ when(mPowerManager.isPowerSaveMode()).thenReturn(true);
+
+ assertThat(mBatterySaverController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void isChecked_off_powerSaveModeOff() {
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
- assertThat(mBatterySaverController.getSummary()).isEqualTo("Off");
+ assertThat(mBatterySaverController.isChecked()).isFalse();
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java
index 91e7b04..a1f3bda 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java
@@ -21,12 +21,12 @@
import static org.mockito.Mockito.doReturn;
import android.content.ContentResolver;
+import android.content.Context;
import android.provider.Settings;
-import androidx.preference.SwitchPreference;
-
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -42,48 +42,50 @@
private static final int OFF = 0;
private SmartBatteryPreferenceController mController;
- private SwitchPreference mPreference;
private ContentResolver mContentResolver;
private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application);
- mPreference = new SwitchPreference(RuntimeEnvironment.application);
}
@Test
public void testUpdateState_smartBatteryOn_preferenceChecked() {
putSmartBatteryValue(ON);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- assertThat(mPreference.isChecked()).isTrue();
+ assertThat(preference.isChecked()).isTrue();
}
@Test
public void testUpdateState_smartBatteryOff_preferenceUnchecked() {
putSmartBatteryValue(OFF);
+ final MainSwitchPreference preference = new MainSwitchPreference(mContext);
- mController.updateState(mPreference);
+ mController.updateState(preference);
- assertThat(mPreference.isChecked()).isFalse();
+ assertThat(preference.isChecked()).isFalse();
}
@Test
public void testUpdateState_checkPreference_smartBatteryOn() {
- mController.onPreferenceChange(mPreference, true);
+ mController.onSwitchChanged(null, true);
assertThat(getSmartBatteryValue()).isEqualTo(ON);
}
@Test
public void testUpdateState_unCheckPreference_smartBatteryOff() {
- mController.onPreferenceChange(mPreference, false);
+ mController.onSwitchChanged(null, false);
assertThat(getSmartBatteryValue()).isEqualTo(OFF);
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java
index 6d2298b..f2677ce 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceControllerTest.java
@@ -27,7 +27,6 @@
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,13 +43,7 @@
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new TopLevelBatteryPreferenceController(mContext, "test_key");
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
index 1e84207..df1dfd0 100644
--- a/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/GesturesSettingsPreferenceControllerTest.java
@@ -28,10 +28,12 @@
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
+import android.util.FeatureFlagUtils;
import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -65,6 +67,7 @@
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
mController = new GesturesSettingPreferenceController(mActivity);
+ FeatureFlagUtils.setEnabled(RuntimeEnvironment.application, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
index bae4432..40315d2 100644
--- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
@@ -26,11 +26,13 @@
import static org.mockito.Mockito.when;
import android.os.Build;
+import android.util.FeatureFlagUtils;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.core.HideNonSystemOverlayMixin;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest;
@@ -41,6 +43,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@@ -51,6 +54,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FeatureFlagUtils.setEnabled(RuntimeEnvironment.application, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/TopLevelLocationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/TopLevelLocationPreferenceControllerTest.java
index 2fa7413..f5bc961 100644
--- a/tests/robotests/src/com/android/settings/location/TopLevelLocationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/TopLevelLocationPreferenceControllerTest.java
@@ -25,7 +25,6 @@
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,13 +43,7 @@
mContext = RuntimeEnvironment.application;
mController = new TopLevelLocationPreferenceController(mContext, PREFERENCE_KEY);
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
index 6de83a6..097ebaf 100644
--- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java
@@ -104,6 +104,7 @@
@After
public void tearDown() {
+ SubscriptionUtil.setActiveSubscriptionsForTesting(null);
SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
}
@@ -269,7 +270,8 @@
when(sub1.getDisplayName()).thenReturn("sub1");
when(sub2.getDisplayName()).thenReturn("sub2");
- SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(sub1));
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
diff --git a/tests/robotests/src/com/android/settings/network/TopLevelNetworkEntryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TopLevelNetworkEntryPreferenceControllerTest.java
index 857b3eb..fc01c68 100644
--- a/tests/robotests/src/com/android/settings/network/TopLevelNetworkEntryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TopLevelNetworkEntryPreferenceControllerTest.java
@@ -74,15 +74,12 @@
mMobileNetworkPreferenceController);
ReflectionHelpers.setField(mController, "mTetherPreferenceController",
mTetherPreferenceController);
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@After
public void tearDown() {
ShadowUtils.reset();
-
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
index 4526886..d0df92e 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -45,8 +45,10 @@
import androidx.fragment.app.FragmentActivity;
import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -109,8 +111,15 @@
mSubscriptionInfoList.add(mSubscriptionInfo);
when(mSubscriptionMgr.getAvailableSubscriptionInfoList()).thenReturn(
mSubscriptionInfoList);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(mSubscriptionInfoList);
}
+ @After
+ public void tearDown() {
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(null);
+ }
+
+
@Test
@Ignore
public void dialog_subscriptionMissing_noCrash() {
diff --git a/tests/robotests/src/com/android/settings/nfc/NfcEnablerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcEnablerTest.java
index c3dfe48..cc45190 100644
--- a/tests/robotests/src/com/android/settings/nfc/NfcEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcEnablerTest.java
@@ -26,7 +26,7 @@
import android.nfc.NfcAdapter;
import android.provider.Settings;
-import androidx.preference.SwitchPreference;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -40,7 +40,7 @@
public class NfcEnablerTest {
@Mock
- private SwitchPreference mNfcPreference;
+ private MainSwitchPreference mNfcPreference;
private Context mContext;
private NfcEnabler mNfcEnabler;
diff --git a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
index 1d05162..3ca553b 100644
--- a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
@@ -31,11 +31,11 @@
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -63,7 +63,7 @@
private PreferenceScreen mScreen;
private Context mContext;
- private SwitchPreference mNfcPreference;
+ private MainSwitchPreference mNfcPreference;
private NfcPreferenceController mNfcController;
private ShadowNfcAdapter mShadowNfcAdapter;
private NfcAdapter mNfcAdapter;
@@ -81,7 +81,7 @@
mNfcController = new NfcPreferenceController(mContext,
NfcPreferenceController.KEY_TOGGLE_NFC);
- mNfcPreference = new SwitchPreference(RuntimeEnvironment.application);
+ mNfcPreference = new MainSwitchPreference(RuntimeEnvironment.application);
when(mScreen.findPreference(mNfcController.getPreferenceKey())).thenReturn(mNfcPreference);
}
diff --git a/tests/robotests/src/com/android/settings/notification/zen/ZenModeButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/zen/ZenModeButtonPreferenceControllerTest.java
index 1200402..9daef1a 100644
--- a/tests/robotests/src/com/android/settings/notification/zen/ZenModeButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/zen/ZenModeButtonPreferenceControllerTest.java
@@ -22,24 +22,21 @@
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
import static android.provider.Settings.Global.ZEN_MODE_OFF;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
-import android.view.View;
-import android.widget.Button;
import androidx.fragment.app.FragmentManager;
-import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import com.android.settings.notification.zen.ZenModeBackend;
-import com.android.settings.notification.zen.ZenModeButtonPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
import org.junit.Test;
@@ -61,14 +58,10 @@
@Mock
private NotificationManager mNotificationManager;
@Mock
- private Preference mockPref;
+ private MainSwitchPreference mMockPref;
@Mock
private NotificationManager.Policy mPolicy;
@Mock
- private Button mZenButtonOn;
- @Mock
- private Button mZenButtonOff;
- @Mock
private PreferenceScreen mPreferenceScreen;
private ContentResolver mContentResolver;
private Context mContext;
@@ -85,67 +78,65 @@
mock(FragmentManager.class));
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
- ReflectionHelpers.setField(mController, "mZenButtonOn", mZenButtonOn);
- ReflectionHelpers.setField(mController, "mZenButtonOff", mZenButtonOff);
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mMockPref);
mController.displayPreference(mPreferenceScreen);
}
@Test
public void updateState_TotalSilence() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
+ final MainSwitchPreference pref = new MainSwitchPreference(mContext);
- verify(mZenButtonOn).setVisibility(View.GONE);
- verify(mZenButtonOff).setVisibility(View.VISIBLE);
+ mController.updateState(pref);
+
+ assertThat(pref.isChecked()).isFalse();
}
@Test
public void updateState_AlarmsOnly() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
+ final MainSwitchPreference pref = new MainSwitchPreference(mContext);
- verify(mZenButtonOn).setVisibility(View.GONE);
- verify(mZenButtonOff).setVisibility(View.VISIBLE);
+ mController.updateState(pref);
+
+ assertThat(pref.isChecked()).isFalse();
}
@Test
public void updateState_Priority() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
+ final MainSwitchPreference pref = new MainSwitchPreference(mContext);
- verify(mZenButtonOn).setVisibility(View.GONE);
- verify(mZenButtonOff).setVisibility(View.VISIBLE);
+ mController.updateState(pref);
+
+ assertThat(pref.isChecked()).isFalse();
}
@Test
public void updateState_ZenOff() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
+ final MainSwitchPreference pref = new MainSwitchPreference(mContext);
- verify(mZenButtonOn).setVisibility(View.VISIBLE);
- verify(mZenButtonOff).setVisibility(View.GONE);
+ mController.updateState(pref);
+
+ assertThat(pref.isChecked()).isFalse();
}
@Test
public void updateState_otherUserChangedZen() {
- final Preference mockPref = mock(Preference.class);
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
- mController.updateState(mockPref);
- verify(mZenButtonOn).setVisibility(View.VISIBLE);
- verify(mZenButtonOff).setVisibility(View.GONE);
+ final MainSwitchPreference pref = new MainSwitchPreference(mContext);
+ mController.updateState(pref);
+
+ assertThat(pref.isChecked()).isFalse();
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
final int GUEST_USER_ID = 10;
mController.mSettingObserver.onChange(false,
Settings.Global.getUriFor(Settings.Global.ZEN_MODE), GUEST_USER_ID);
- verify(mZenButtonOn).setVisibility(View.GONE);
- verify(mZenButtonOff).setVisibility(View.VISIBLE);
+ assertThat(pref.isChecked()).isFalse();
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java
deleted file mode 100644
index eb82d31..0000000
--- a/tests/robotests/src/com/android/settings/panel/InternetConnectivityPanelTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.android.settings.panel;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.net.Uri;
-import android.os.SystemProperties;
-
-import com.android.settings.network.AirplaneModePreferenceController;
-import com.android.settings.slices.CustomSliceRegistry;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-
-public class InternetConnectivityPanelTest {
-
- private InternetConnectivityPanel mPanel;
- private static final String SETTINGS_PROVIDER_MODEL =
- "persist.sys.fflag.override.settings_provider_model";
- private boolean mSettingsProviderModelState;
-
- @Before
- public void setUp() {
- mPanel = InternetConnectivityPanel.create(RuntimeEnvironment.application);
- mSettingsProviderModelState = SystemProperties.getBoolean(SETTINGS_PROVIDER_MODEL, false);
- }
-
- @After
- public void tearDown() {
- SystemProperties.set(SETTINGS_PROVIDER_MODEL,
- mSettingsProviderModelState ? "true" : "false");
- }
-
- @Test
- public void getSlices_providerModelDisabled_containsNecessarySlices() {
- SystemProperties.set(SETTINGS_PROVIDER_MODEL, "false");
- final List<Uri> uris = mPanel.getSlices();
-
- assertThat(uris).containsExactly(
- AirplaneModePreferenceController.SLICE_URI,
- CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
- CustomSliceRegistry.WIFI_SLICE_URI);
- }
-
- @Test
- public void getSlices_providerModelEnabled_containsNecessarySlices() {
- SystemProperties.set(SETTINGS_PROVIDER_MODEL, "true");
- final List<Uri> uris = mPanel.getSlices();
-
- assertThat(uris).containsExactly(
- CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
- CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
- }
-
- @Test
- public void getSeeMoreIntent_notNull() {
- assertThat(mPanel.getSeeMoreIntent()).isNotNull();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
index 03ce25a..634b9a8 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericTest.java
@@ -45,6 +45,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings.Global;
+import android.util.FeatureFlagUtils;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
@@ -53,6 +54,7 @@
import com.android.internal.widget.LockscreenCredential;
import com.android.settings.R;
import com.android.settings.biometrics.BiometricEnrollBase;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
@@ -68,6 +70,7 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowPersistentDataBlockManager;
@@ -90,6 +93,7 @@
public void setUp() {
Global.putInt(application.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
mFragment = new ChooseLockGenericFragment();
+ FeatureFlagUtils.setEnabled(RuntimeEnvironment.application, FeatureFlags.SILKY_HOME, false);
}
@After
diff --git a/tests/robotests/src/com/android/settings/security/TopLevelSecurityEntryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/TopLevelSecurityEntryPreferenceControllerTest.java
index 33d22d4..05abc40 100644
--- a/tests/robotests/src/com/android/settings/security/TopLevelSecurityEntryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/TopLevelSecurityEntryPreferenceControllerTest.java
@@ -30,7 +30,6 @@
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,13 +57,7 @@
when(mContext.getSystemService(Context.FACE_SERVICE))
.thenReturn(mFaceManager);
mController = new TopLevelSecurityEntryPreferenceController(mContext, "test_key");
- }
-
- @After
- public void tearDown() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.SILKY_HOME)) {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
- }
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/sim/PreferredSimDialogFragmentTest.java b/tests/robotests/src/com/android/settings/sim/PreferredSimDialogFragmentTest.java
index 62c2fc5..9bdbbcf 100644
--- a/tests/robotests/src/com/android/settings/sim/PreferredSimDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/sim/PreferredSimDialogFragmentTest.java
@@ -75,6 +75,7 @@
@Test
public void onCreateDialog_twoSimsSelectFirst_correctMessage() {
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
mIntent.putExtra(PREFERRED_SIM, 0);
@@ -87,6 +88,7 @@
@Test
public void onCreateDialog_twoSimsSelectSecond_correctMessage() {
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
mIntent.putExtra(PREFERRED_SIM, 1);
@@ -99,6 +101,7 @@
@Test
public void onClick_yesClicked_callsOnSubscriptionSelected() {
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
mIntent.putExtra(PREFERRED_SIM, 0);
final AlertDialog alertDialog = startDialog();
@@ -113,6 +116,7 @@
@Test
public void onClick_noClicked_doesNotCallOnSubscriptionSelected() {
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSim1, mSim2));
mIntent.putExtra(PREFERRED_SIM, 0);
final AlertDialog alertDialog = startDialog();
diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
index d6a1326..a6d3354 100644
--- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
+++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
@@ -130,6 +130,7 @@
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubInfo));
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(mSubInfo));
when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
when(mSubscriptionManager.getActiveSubscriptionInfo(mSubId)).thenReturn(mSubInfo);
diff --git a/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java
index 0d34a76..e80e77a 100644
--- a/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/system/ResetPreferenceControllerTest.java
@@ -21,8 +21,10 @@
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.provider.Settings;
+import android.util.FeatureFlagUtils;
import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
@@ -47,6 +49,7 @@
mContext = RuntimeEnvironment.application;
mController = new ResetPreferenceController(mContext, KEY_RESET_DASHBOARD);
mShadowUserManager = ShadowUserManager.getShadow();
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.SILKY_HOME, false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index 80091e6..22e18bb 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -49,6 +49,7 @@
import android.widget.TextView;
import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
import com.android.wifitrackerlib.WifiEntry;
@@ -834,6 +835,7 @@
when(subscriptionInfo.getDisplayName()).thenReturn("FAKE-CARRIER");
when(subscriptionInfo.getCarrierId()).thenReturn(carrierId);
when(subscriptionInfo.getCarrierName()).thenReturn("FAKE-CARRIER");
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(subscriptionInfo));
mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(subscriptionInfo));
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index 305f41d..455e9f1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -49,6 +49,7 @@
import android.widget.TextView;
import com.android.settings.R;
+import com.android.settings.network.SubscriptionUtil;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settingslib.wifi.AccessPoint;
@@ -629,6 +630,7 @@
when(subscriptionInfo.getDisplayName()).thenReturn("FAKE-CARRIER");
when(subscriptionInfo.getCarrierId()).thenReturn(carrierId);
when(subscriptionInfo.getCarrierName()).thenReturn("FAKE-CARRIER");
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(subscriptionInfo));
mShadowSubscriptionManager.setActiveSubscriptionInfoList(Arrays.asList(subscriptionInfo));
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
index 0159f49..d7f75e1 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsTest.java
@@ -125,6 +125,8 @@
when(info1.getDisplayName()).thenReturn(DISPLAY_NAME1);
when(info2.getDisplayName()).thenReturn(DISPLAY_NAME2);
+ SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>(
+ Arrays.asList(info1, info2)));
SubscriptionUtil.setActiveSubscriptionsForTesting(new ArrayList<>(
Arrays.asList(info1, info2)));
diff --git a/tests/unit/src/com/android/settings/network/AirplaneSafeNetworksSliceTest.java b/tests/unit/src/com/android/settings/network/AirplaneSafeNetworksSliceTest.java
index a344ab6..a90b89d 100644
--- a/tests/unit/src/com/android/settings/network/AirplaneSafeNetworksSliceTest.java
+++ b/tests/unit/src/com/android/settings/network/AirplaneSafeNetworksSliceTest.java
@@ -34,7 +34,6 @@
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import com.android.settings.testutils.AirplaneModeRule;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
@@ -50,8 +49,6 @@
@Rule
public MockitoRule mMocks = MockitoJUnit.rule();
- @Rule
- public AirplaneModeRule mAirplaneModeRule = new AirplaneModeRule();
@Mock
private WifiManager mWifiManager;
@@ -67,18 +64,18 @@
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
mAirplaneSafeNetworksSlice = new AirplaneSafeNetworksSlice(mContext);
+ mAirplaneSafeNetworksSlice.onAirplaneModeChanged(true);
}
@Test
- public void getSlice_airplaneModeOff_shouldBeNull() {
- mAirplaneModeRule.setAirplaneMode(false);
+ public void getSlice_airplaneModeOff_shouldBeNotNull() {
+ mAirplaneSafeNetworksSlice.onAirplaneModeChanged(false);
- assertThat(mAirplaneSafeNetworksSlice.getSlice()).isNull();
+ assertThat(mAirplaneSafeNetworksSlice.getSlice()).isNotNull();
}
@Test
- public void getSlice_wifiDisabled_shouldShowViewAirplaneSafeNetworks() {
- mAirplaneModeRule.setAirplaneMode(true);
+ public void getSlice_wifiDisabled_shouldShowTurnOnNetworks() {
when(mWifiManager.isWifiEnabled()).thenReturn(false);
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
@@ -87,12 +84,11 @@
final SliceItem sliceTitle =
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
assertThat(sliceTitle.getText()).isEqualTo(
- ResourcesUtils.getResourcesString(mContext, "view_airplane_safe_networks"));
+ ResourcesUtils.getResourcesString(mContext, "turn_on_networks"));
}
@Test
- public void getSlice_wifiEnabled_shouldShowTurnOffAirplaneMode() {
- mAirplaneModeRule.setAirplaneMode(true);
+ public void getSlice_wifiEnabled_shouldShowTurnOffNetworks() {
when(mWifiManager.isWifiEnabled()).thenReturn(true);
final Slice slice = mAirplaneSafeNetworksSlice.getSlice();
@@ -101,12 +97,11 @@
final SliceItem sliceTitle =
SliceMetadata.from(mContext, slice).getListContent().getHeader().getTitleItem();
assertThat(sliceTitle.getText()).isEqualTo(
- ResourcesUtils.getResourcesString(mContext, "turn_off_airplane_mode"));
+ ResourcesUtils.getResourcesString(mContext, "turn_off_networks"));
}
@Test
- public void onNotifyChange_viewAirplaneSafeNetworks_shouldSetWifiEnabled() {
- mAirplaneModeRule.setAirplaneMode(true);
+ public void onNotifyChange_turnOnNetworks_shouldSetWifiEnabled() {
when(mWifiManager.isWifiEnabled()).thenReturn(false);
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
@@ -116,13 +111,12 @@
}
@Test
- public void onNotifyChange_turnOffAirplaneMode_shouldSetAirplaneModeOff() {
- mAirplaneModeRule.setAirplaneMode(true);
+ public void onNotifyChange_turnOffNetworks_shouldSetWifiDisabled() {
when(mWifiManager.isWifiEnabled()).thenReturn(true);
Intent intent = mAirplaneSafeNetworksSlice.getIntent();
mAirplaneSafeNetworksSlice.onNotifyChange(intent);
- assertThat(mAirplaneModeRule.isAirplaneModeOn()).isFalse();
+ verify(mWifiManager).setWifiEnabled(false);
}
}
diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
index 8444f11..16433c3 100644
--- a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
@@ -17,9 +17,13 @@
package com.android.settings.network;
import static androidx.lifecycle.Lifecycle.Event;
+
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
@@ -27,19 +31,17 @@
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
-import com.android.settings.testutils.ResourcesUtils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.RestrictedPreference;
-
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
-import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.InstrumentationRegistry;
+
+import com.android.settings.testutils.ResourcesUtils;
+import com.android.settingslib.RestrictedPreference;
+import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -50,9 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
@RunWith(AndroidJUnit4.class)
public class NetworkProviderCallsSmsControllerTest {
@@ -156,6 +155,7 @@
@UiThreadTest
public void getSummary_noSim_returnNoSim() {
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(new ArrayList<>());
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(new ArrayList<>());
displayPreferenceWithLifecycle();
assertTrue(TextUtils.equals(mController.getSummary(),
@@ -169,6 +169,8 @@
mSubscriptionInfo1);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
@@ -188,6 +190,8 @@
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
@@ -209,6 +213,8 @@
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1));
displayPreferenceWithLifecycle();
assertThat(mPreference.getSummary()).isEqualTo(DISPLAY_NAME_1);
@@ -221,6 +227,8 @@
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
@@ -240,6 +248,8 @@
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
@@ -267,6 +277,8 @@
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
@@ -294,6 +306,8 @@
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
displayPreferenceWithLifecycle();
final StringBuilder summary = new StringBuilder();
diff --git a/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java b/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java
index bee48d1..72e9be4 100644
--- a/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java
+++ b/tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java
@@ -177,7 +177,7 @@
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
- when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(mDefaultDataSubscriptionInfo));
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
@@ -207,7 +207,7 @@
when(mDefaultDataSubscriptionInfo.getDisplayName()).thenReturn(expectDisplayName);
when(mSubscriptionManager.getActiveSubscriptionInfo(defaultDataSubId)).thenReturn(
mDefaultDataSubscriptionInfo);
- when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
+ when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(mDefaultDataSubscriptionInfo));
when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE);
mBundle.putBoolean(CarrierConfigManager.KEY_INFLATE_SIGNAL_STRENGTH_BOOL, false);
diff --git a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
index 9f70bcf..476d854 100644
--- a/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
+++ b/tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java
@@ -16,8 +16,6 @@
package com.android.settings.network;
-import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
-
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -25,6 +23,7 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -132,7 +131,8 @@
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
mMockNetworkProviderWorker = spy(new MockNetworkProviderWorker(mContext,
PROVIDER_MODEL_SLICE_URI));
- mMockProviderModelSlice = new MockProviderModelSlice(mContext, mMockNetworkProviderWorker);
+ mMockProviderModelSlice = spy(new MockProviderModelSlice(
+ mContext, mMockNetworkProviderWorker));
mListBuilder = spy(new ListBuilder(mContext, PROVIDER_MODEL_SLICE_URI,
ListBuilder.INFINITY).setAccentColor(-1));
when(mProviderModelSliceHelper.createListBuilder(PROVIDER_MODEL_SLICE_URI)).thenReturn(
@@ -386,32 +386,34 @@
}
@Test
- public void onNotifyChange_intentToggleActionOn_shouldSetCarrierNetworkEnabledTrue() {
- Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
- intent.putExtra(EXTRA_TOGGLE_STATE, true);
-
- mMockProviderModelSlice.onNotifyChange(intent);
+ public void doCarrierNetworkAction_toggleActionSetDataEnabled_setCarrierNetworkEnabledTrue() {
+ mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
+ true /* isDataEnabled */);
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(true);
}
@Test
- public void onNotifyChange_intentToggleActionOff_shouldSetCarrierNetworkEnabledFalse() {
- Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
- intent.putExtra(EXTRA_TOGGLE_STATE, false);
-
- mMockProviderModelSlice.onNotifyChange(intent);
+ public void doCarrierNetworkAction_toggleActionSetDataDisabled_setCarrierNetworkEnabledFalse() {
+ mMockProviderModelSlice.doCarrierNetworkAction(true /* isToggleAction */,
+ false /* isDataEnabled */);
verify(mMockNetworkProviderWorker).setCarrierNetworkEnabled(false);
}
@Test
- public void onNotifyChange_intentPrimaryAction_shouldConnectCarrierNetwork() {
- when(mTelephonyManager.isDataEnabled()).thenReturn(true);
- Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent();
-
- mMockProviderModelSlice.onNotifyChange(intent);
+ public void doCarrierNetworkAction_primaryActionAndDataEnabled_connectCarrierNetwork() {
+ mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
+ true /* isDataEnabled */);
verify(mMockNetworkProviderWorker).connectCarrierNetwork();
}
+
+ @Test
+ public void doCarrierNetworkAction_primaryActionAndDataDisabled_notConnectCarrierNetwork() {
+ mMockProviderModelSlice.doCarrierNetworkAction(false /* isToggleAction */,
+ false /* isDataEnabled */);
+
+ verify(mMockNetworkProviderWorker, never()).connectCarrierNetwork();
+ }
}
diff --git a/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java b/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
index 8c99b40..c0e5205 100644
--- a/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
+++ b/tests/unit/src/com/android/settings/network/SubscriptionUtilTest.java
@@ -48,7 +48,7 @@
private static final int SUBID_1 = 1;
private static final int SUBID_2 = 2;
private static final int SUBID_3 = 3;
- private static final CharSequence CARRIER_1 = "carrier1";
+ private static final CharSequence CARRIER_1 = "carrier1111111";
private static final CharSequence CARRIER_2 = "carrier2";
private Context mContext;
@@ -94,6 +94,8 @@
final SubscriptionInfo info2 = mock(SubscriptionInfo.class);
when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));
+ // // TODO remove this line.
+ // when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));
final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(mContext);
assertThat(subs).isNotNull();
@@ -143,8 +145,9 @@
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_2);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(info1, info2));
+ // Arrays.asList(info2));
// Each subscription has a unique last 4 digits of the phone number.
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
@@ -172,7 +175,7 @@
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(info1, info2));
// Each subscription has a unique last 4 digits of the phone number.
@@ -201,8 +204,7 @@
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1, info2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));
// The subscriptions' phone numbers cannot be revealed to the user.
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
@@ -234,7 +236,7 @@
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_1);
when(info3.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
Arrays.asList(info1, info2, info3));
// Subscription 1 has a unique phone number, but subscriptions 2 and 3 share the same
@@ -265,8 +267,7 @@
final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(SUBID_1);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1));
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
when(sub1Telmgr.getLine1Number()).thenReturn("1112223333");
@@ -288,8 +289,7 @@
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1, info2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));
// Each subscription has a unique last 4 digits of the phone number.
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
@@ -318,8 +318,7 @@
when(info2.getSubscriptionId()).thenReturn(SUBID_2);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
when(info2.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1, info2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));
// Both subscriptions have a the same 4 digits of the phone number.
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
@@ -345,8 +344,7 @@
final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(SUBID_1);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1));
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
when(sub1Telmgr.getLine1Number()).thenReturn("1112223333");
@@ -366,8 +364,7 @@
final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
when(info1.getSubscriptionId()).thenReturn(SUBID_1);
when(info1.getDisplayName()).thenReturn(CARRIER_1);
- when(mSubMgr.getActiveSubscriptionInfoList()).thenReturn(
- Arrays.asList(info1));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(info1));
TelephonyManager sub1Telmgr = mock(TelephonyManager.class);
when(sub1Telmgr.getLine1Number()).thenReturn("1112223333");
diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
index f3e084c..ef3f130 100644
--- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
@@ -272,6 +272,7 @@
@UiThreadTest
public void onSubscriptionsChanged_subscriptionReplaced_preferencesChanged() {
final List<SubscriptionInfo> subs = setupMockSubscriptions(3);
+ doReturn(subs).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
// Start out with only sub1 and sub2.
SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 2));
@@ -388,6 +389,7 @@
final List<SubscriptionInfo> sub = setupMockSubscriptions(1);
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
mController.onResume();
mController.displayPreference(mPreferenceScreen);
@@ -402,6 +404,7 @@
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
mController.onResume();
mController.displayPreference(mPreferenceScreen);
@@ -530,6 +533,7 @@
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
Intent intent = new Intent(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
mController.onResume();
@@ -548,6 +552,7 @@
final int subId = sub.get(0).getSubscriptionId();
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
Intent intent = new Intent(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
mController.onResume();
diff --git a/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
index 282704d..93621d9 100644
--- a/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/DefaultSubscriptionControllerTest.java
@@ -54,7 +54,7 @@
@RunWith(AndroidJUnit4.class)
public class DefaultSubscriptionControllerTest {
@Mock
- private SubscriptionManager mManager;
+ private SubscriptionManager mSubMgr;
@Mock
private TelecomManager mTelecomManager;
@@ -68,7 +68,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mManager);
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubMgr);
when(mContext.getSystemService(TelecomManager.class)).thenReturn(mTelecomManager);
final String key = "prefkey";
@@ -123,6 +123,7 @@
final SubscriptionInfo sub1 = createMockSub(111, "sub1");
final SubscriptionInfo sub2 = createMockSub(222, "sub2");
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -152,6 +153,7 @@
final SubscriptionInfo sub1 = createMockSub(111, "sub1");
final SubscriptionInfo sub2 = createMockSub(222, "sub2");
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
mController.setDefaultSubscription(sub2.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -186,6 +188,8 @@
when(sub2.isOpportunistic()).thenReturn(true);
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2, sub3));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(sub1, sub2, sub3));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -240,6 +244,7 @@
// Start with only one sub active, so the pref is not available
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -261,6 +266,7 @@
final SubscriptionInfo sub1 = createMockSub(111, "sub1");
final SubscriptionInfo sub2 = createMockSub(222, "sub2");
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -296,6 +302,7 @@
final SubscriptionInfo sub1 = createMockSub(111, "sub1");
final SubscriptionInfo sub2 = createMockSub(222, "sub2");
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
@@ -303,6 +310,7 @@
assertThat(mListPreference.isVisible()).isFalse();
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isTrue();
@@ -315,12 +323,15 @@
final SubscriptionInfo sub2 = createMockSub(222, "sub2");
final SubscriptionInfo sub3 = createMockSub(333, "sub3");
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
mController.setDefaultSubscription(sub1.getSubscriptionId());
mController.displayPreference(mScreen);
assertThat(mListPreference.getEntries().length).isEqualTo(3);
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2, sub3));
+ when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(
+ Arrays.asList(sub1, sub2, sub3));
mController.onSubscriptionsChanged();
assertThat(mController.isAvailable()).isTrue();
diff --git a/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
index 67f5f1a..a0219a0 100644
--- a/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
@@ -111,11 +111,11 @@
@Test
public void setChecked_setDataIntoSubscriptionManager() {
mController.setChecked(true);
- verify(mTelephonyManager).setMobileDataPolicyEnabledStatus(
+ verify(mTelephonyManager).setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, true);
mController.setChecked(false);
- verify(mTelephonyManager).setMobileDataPolicyEnabledStatus(
+ verify(mTelephonyManager).setMobileDataPolicyEnabled(
TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, false);
}
}
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroupTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroupTest.java
index ed6f161..660772e 100644
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroupTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroupTest.java
@@ -39,15 +39,15 @@
import android.telephony.TelephonyManager;
import android.util.FeatureFlagUtils;
-import com.android.settings.network.ims.MockWfcQueryImsState;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.network.ims.MockWfcQueryImsState;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -132,10 +132,8 @@
@Test
public void shouldShowWifiCallingForSub_invalidSubId_returnFalse() {
- when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID)).thenReturn(null);
-
- assertThat(mNetworkProviderWifiCallingGroup.shouldShowWifiCallingForSub(SUB_ID))
- .isEqualTo(false);
+ assertThat(mNetworkProviderWifiCallingGroup.shouldShowWifiCallingForSub(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
similarity index 74%
rename from tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
rename to tests/unit/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
index dbfd3b2..5827516 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/WifiCallingPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2021 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.
@@ -19,8 +19,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNull;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -35,11 +33,16 @@
import android.telephony.ims.ImsMmTelManager;
import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.ims.MockWifiCallingQueryImsState;
+import com.android.settings.network.ims.WifiCallingQueryImsState;
import org.junit.Before;
import org.junit.Ignore;
@@ -47,62 +50,57 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-@RunWith(RobolectricTestRunner.class)
+@RunWith(AndroidJUnit4.class)
public class WifiCallingPreferenceControllerTest {
private static final int SUB_ID = 2;
-
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
@Mock
private CarrierConfigManager mCarrierConfigManager;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private ImsMmTelManager mImsMmTelManager;
- @Mock
- private PreferenceScreen mPreferenceScreen;
+
+ private PreferenceScreen mScreen;
+ private PreferenceManager mPreferenceManager;
private MockWifiCallingQueryImsState mQueryImsState;
- private WifiCallingPreferenceController mController;
+ private TestWifiCallingPreferenceController mController;
private Preference mPreference;
private Context mContext;
private PersistableBundle mCarrierConfig;
@Before
+ @UiThreadTest
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
mQueryImsState = new MockWifiCallingQueryImsState(mContext, SUB_ID);
mQueryImsState.setIsEnabledByUser(true);
mQueryImsState.setIsProvisionedOnDevice(true);
- mPreference = new Preference(mContext);
- mController = spy(new WifiCallingPreferenceController(mContext, "wifi_calling") {
- @Override
- protected ImsMmTelManager getImsMmTelManager(int subId) {
- return mImsMmTelManager;
- }
- });
+ mController = new TestWifiCallingPreferenceController(mContext, "wifi_calling");
mController.mCarrierConfigManager = mCarrierConfigManager;
mController.init(SUB_ID);
mController.mCallState = TelephonyManager.CALL_STATE_IDLE;
- doReturn(mQueryImsState).when(mController).queryImsState(anyInt());
- mPreference.setKey(mController.getPreferenceKey());
-
- when(mController.getTelephonyManager(mContext, SUB_ID)).thenReturn(mTelephonyManager);
-
mCarrierConfig = new PersistableBundle();
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
- mPreference);
+ mPreferenceManager = new PreferenceManager(mContext);
+ mScreen = mPreferenceManager.createPreferenceScreen(mContext);
+ mPreference = new Preference(mContext);
+ mPreference.setKey(mController.getPreferenceKey());
+ mScreen.addPreference(mPreference);
}
@Test
+ @UiThreadTest
public void updateState_noSimCallManager_setCorrectSummary() {
mController.mSimCallManager = null;
mQueryImsState.setIsEnabledByUser(true);
@@ -118,6 +116,7 @@
}
@Test
+ @UiThreadTest
public void updateState_notCallIdle_disable() {
mController.mCallState = TelephonyManager.CALL_STATE_RINGING;
@@ -127,6 +126,7 @@
}
@Test
+ @UiThreadTest
public void updateState_invalidPhoneAccountHandle_shouldNotCrash() {
mController.mSimCallManager = new PhoneAccountHandle(null /* invalid */, "");
@@ -135,6 +135,7 @@
}
@Test
+ @UiThreadTest
public void updateState_wfcNonRoamingByConfig() {
assertNull(mController.mSimCallManager);
mCarrierConfig.putBoolean(
@@ -154,6 +155,7 @@
}
@Test
+ @UiThreadTest
public void updateState_wfcRoamingByConfig() {
assertNull(mController.mSimCallManager);
// useWfcHomeModeForRoaming is false by default. In order to check wfc in roaming mode. We
@@ -171,12 +173,15 @@
}
@Test
+ @UiThreadTest
public void displayPreference_notAvailable_setPreferenceInvisible() {
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
- mController.displayPreference(mPreferenceScreen);
+ mController.displayPreference(mScreen);
- assertThat(mPreferenceScreen.isVisible()).isFalse();
+ assertThat(mController.getPreferenceKey()).isEqualTo("wifi_calling");
+ assertThat(mScreen.findPreference(mController.getPreferenceKey()).isVisible()).isFalse();
}
@Test
@@ -184,16 +189,39 @@
public void displayPreference_available_setsSubscriptionIdOnIntent() {
final Intent intent = new Intent();
mPreference.setIntent(intent);
- mController.displayPreference(mPreferenceScreen);
+ mController.displayPreference(mScreen);
assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(SUB_ID);
}
@Test
+ @UiThreadTest
public void getAvailabilityStatus_noWiFiCalling_shouldReturnUnsupported() {
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
+
+ private class TestWifiCallingPreferenceController extends WifiCallingPreferenceController {
+ TestWifiCallingPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ protected ImsMmTelManager getImsMmTelManager(int subId) {
+ return mImsMmTelManager;
+ }
+
+ @Override
+ protected TelephonyManager getTelephonyManager(Context context, int subId) {
+ return mTelephonyManager;
+ }
+
+ @Override
+ protected WifiCallingQueryImsState queryImsState(int subId) {
+ return mQueryImsState;
+ }
+ }
}
diff --git a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
index e8f694b..a4d4ad1 100644
--- a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
+++ b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
@@ -18,6 +18,9 @@
import static com.android.settings.network.InternetUpdater.INTERNET_APM;
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
+import static com.android.settings.network.InternetUpdater.INTERNET_CELLULAR;
+import static com.android.settings.network.InternetUpdater.INTERNET_ETHERNET;
+import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
import static com.google.common.truth.Truth.assertThat;
@@ -26,10 +29,13 @@
import static org.mockito.Mockito.verify;
import android.content.Context;
+import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
+import com.android.settings.network.AirplaneModePreferenceController;
+import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
@@ -40,6 +46,8 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
+import java.util.List;
+
@RunWith(AndroidJUnit4.class)
public class InternetConnectivityPanelTest {
@@ -47,6 +55,10 @@
ApplicationProvider.getApplicationContext(), "provider_internet_settings");
public static final String TITLE_APM_NETWORKS = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "airplane_mode_network_panel_title");
+ public static final String SUBTITLE_APM_IS_ON = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "condition_airplane_title");
+ public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "settings_button");
@Rule
public final MockitoRule mMocks = MockitoJUnit.rule();
@@ -66,30 +78,147 @@
}
@Test
- public void getTitle_internetTypeChangedFromApmToApmNetworks_verifyTitleChanged() {
+ public void getTitle_internetApmNetworks_shouldBeApmNetworks() {
+ mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
+
+ assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
+ }
+
+ @Test
+ public void getTitle_notInternetApmNetworks_shouldBeInternet() {
mPanel.onInternetTypeChanged(INTERNET_APM);
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
+ mPanel.onInternetTypeChanged(INTERNET_WIFI);
+
+ assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
+
+ mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
+
+ assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
+
+ mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
+
+ assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
+ }
+
+ @Test
+ public void getSubTitle_internetApm_shouldBeApmIsOn() {
+ mPanel.onInternetTypeChanged(INTERNET_APM);
+
+ assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_APM_IS_ON);
+ }
+
+ @Test
+ public void getSubTitle_notinternetApm_shouldBeNull() {
+ mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
+
+ assertThat(mPanel.getSubTitle()).isNull();
+
+ mPanel.onInternetTypeChanged(INTERNET_WIFI);
+
+ assertThat(mPanel.getSubTitle()).isNull();
+
+ mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
+
+ assertThat(mPanel.getSubTitle()).isNull();
+
+ mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
+
+ assertThat(mPanel.getSubTitle()).isNull();
+ }
+
+ @Test
+ public void getCustomizedButtonTitle_internetApm_shouldBeNull() {
+ mPanel.onInternetTypeChanged(INTERNET_APM);
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isNull();
+ }
+
+ @Test
+ public void getCustomizedButtonTitle_notInternetApm_shouldBeSettings() {
+ mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
+
+ mPanel.onInternetTypeChanged(INTERNET_WIFI);
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
+
+ mPanel.onInternetTypeChanged(INTERNET_CELLULAR);
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
+
+ mPanel.onInternetTypeChanged(INTERNET_ETHERNET);
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
+ }
+
+ @Test
+ public void getSlices_providerModelDisabled_containsNecessarySlices() {
+ mPanel.mIsProviderModelEnabled = false;
+ final List<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris).containsExactly(
+ AirplaneModePreferenceController.SLICE_URI,
+ CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
+ CustomSliceRegistry.WIFI_SLICE_URI);
+ }
+
+ @Test
+ public void getSlices_providerModelEnabled_containsNecessarySlices() {
+ final List<Uri> uris = mPanel.getSlices();
+
+ assertThat(uris).containsExactly(
+ CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
+ CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
+ }
+
+ @Test
+ public void getSeeMoreIntent_notNull() {
+ assertThat(mPanel.getSeeMoreIntent()).isNotNull();
+ }
+
+ @Test
+ public void onInternetTypeChanged_internetTypeChangedToApm_changeHeaderAndHideSettings() {
+ mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onInternetTypeChanged(INTERNET_APM);
+
+ verify(mPanelContentCallback).onHeaderChanged();
+ verify(mPanelContentCallback).onCustomizedButtonStateChanged();
+ }
+
+ @Test
+ public void onInternetTypeChanged_internetTypeChangedFomApm_changeTitleAndShowSettings() {
+ mPanel.onInternetTypeChanged(INTERNET_APM);
clearInvocations(mPanelContentCallback);
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
+ verify(mPanelContentCallback).onTitleChanged();
+ verify(mPanelContentCallback).onCustomizedButtonStateChanged();
+ }
+
+ @Test
+ public void onInternetTypeChanged_internetTypeChangedToApmNetworks_changeTitle() {
+ mPanel.onInternetTypeChanged(INTERNET_WIFI);
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
+
verify(mPanelContentCallback).onTitleChanged();
}
@Test
- public void getTitle_internetTypeChangedFromApmNetworksToApm_verifyTitleChanged() {
+ public void onInternetTypeChanged_internetTypeChangedFromApmNetworks_changeTitle() {
mPanel.onInternetTypeChanged(INTERNET_APM_NETWORKS);
-
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
-
clearInvocations(mPanelContentCallback);
- mPanel.onInternetTypeChanged(INTERNET_APM);
+ mPanel.onInternetTypeChanged(INTERNET_WIFI);
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
verify(mPanelContentCallback).onTitleChanged();
}
}