Merge "Updates magnification settings string" into sc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6ac1ac9..30f181a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2820,8 +2820,13 @@
</activity>
<!-- Show channel-level notification settings (channel passed in as extras) -->
- <activity android:name="Settings$ChannelNotificationSettingsActivity"
+ <activity android:name=".notification.app.ChannelPanelActivity"
android:label="@string/notification_channel_title"
+ android:theme="@style/Theme.Panel"
+ android:launchMode="singleInstance"
+ android:excludeFromRecents="true"
+ android:noHistory="true"
+ android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true">
<intent-filter android:priority="1">
<action android:name="android.settings.CHANNEL_NOTIFICATION_SETTINGS" />
@@ -2902,6 +2907,12 @@
android:grantUriPermissions="true"
android:exported="false"/>
+ <provider
+ android:name=".emergency.EmergencyActionContentProvider"
+ android:authorities="com.android.settings.emergency"
+ android:permission="android.permission.CALL_PRIVILEGED"
+ android:exported="true"/>
+
<activity
android:name=".wifi.RequestToggleWiFiActivity"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert"
@@ -3751,6 +3762,25 @@
android:launchMode="singleTask">
</activity>
+ <activity android:name="Settings$FactoryResetActivity"
+ android:permission="android.permission.BACKUP"
+ android:label="@string/main_clear_title"
+ android:exported="true"
+ android:theme="@style/SudThemeGlif.Light">
+ <intent-filter>
+ <action android:name="com.android.settings.action.FACTORY_RESET"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.MainClear"/>
+ </activity>
+
+ <activity android:name="Settings$FactoryResetConfirmActivity"
+ android:label="@string/main_clear_confirm_title"
+ android:exported="false"
+ android:theme="@style/SudThemeGlif.Light">
+ </activity>
+
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index b94da0d..9c79bab 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -4013,4 +4013,36 @@
column="5"/>
</issue>
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item android:offset="0" android:color="#FF4285F4"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/one_handed_guideline.xml"
+ line="34"
+ column="36"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <item android:offset="1" android:color="#004385F5"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/one_handed_guideline.xml"
+ line="35"
+ column="36"/>
+ </issue>
+
</issues>
diff --git a/res/drawable/ic_battery_low.xml b/res/drawable/ic_battery_low.xml
new file mode 100644
index 0000000..82f9546
--- /dev/null
+++ b/res/drawable/ic_battery_low.xml
@@ -0,0 +1,28 @@
+<!--
+ 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
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="?android:attr/colorAccent"
+ android:pathData="M12,19m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0"/>
+ <path
+ android:fillColor="?android:attr/colorAccent"
+ android:pathData="M10,3h4v12h-4z"/>
+</vector>
diff --git a/res/layout/view_airplane_mode_networks_button.xml b/res/layout/airplane_mode_message_preference.xml
similarity index 62%
rename from res/layout/view_airplane_mode_networks_button.xml
rename to res/layout/airplane_mode_message_preference.xml
index 0599274..032161b 100644
--- a/res/layout/view_airplane_mode_networks_button.xml
+++ b/res/layout/airplane_mode_message_preference.xml
@@ -22,7 +22,6 @@
android:orientation="vertical">
<TextView
- android:id="@+id/airplane_mode_text"
android:text="@string/condition_airplane_title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
@@ -30,17 +29,6 @@
android:layout_gravity="center_horizontal"
android:layout_marginStart="@dimen/content_margin_left"
android:layout_marginEnd="@dimen/content_margin_left"
- android:layout_marginTop="@dimen/view_airplane_mode_networks_button_margin_vertical"
- android:layout_marginBottom="@dimen/view_airplane_mode_networks_button_margin_vertical"/>
-
- <Button
- android:id="@+id/view_airplane_mode_networks_button"
- android:text="@string/view_airplane_safe_networks"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:layout_marginStart="@dimen/content_margin_left"
- android:layout_marginEnd="@dimen/content_margin_left"
- android:layout_marginBottom="@dimen/view_airplane_mode_networks_button_margin_vertical"
- style="@style/ActionPrimaryButton"/>
+ android:layout_marginTop="@dimen/airplane_mode_message_margin_vertical"
+ android:layout_marginBottom="@dimen/airplane_mode_message_margin_vertical"/>
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/manage_applications_apps_v2.xml b/res/layout/manage_applications_apps_v2.xml
index ecc764a..72c8ee8 100644
--- a/res/layout/manage_applications_apps_v2.xml
+++ b/res/layout/manage_applications_apps_v2.xml
@@ -48,7 +48,7 @@
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:gravity="center"
+ android:gravity="bottom|center_horizontal"
android:layout_gravity="center"
android:text="@string/no_applications"
android:textAppearance="?android:attr/textAppearanceLarge"
diff --git a/res/layout/notification_channel_panel.xml b/res/layout/notification_channel_panel.xml
new file mode 100644
index 0000000..49cd95c
--- /dev/null
+++ b/res/layout/notification_channel_panel.xml
@@ -0,0 +1,66 @@
+<?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.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/main_content"
+ android:layout_height="@dimen/output_switcher_slice_max_height"
+ android:background="@drawable/settings_panel_background"
+ android:orientation="vertical"
+ android:layout_width="match_parent">
+
+ <FrameLayout
+ android:id="@android:id/list_container"
+ android:layout_height="0px"
+ android:layout_weight="1"
+ android:layout_width="match_parent"/>
+
+ <View
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/footer_divider"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/horizontal_divider_height"
+ android:background="?android:attr/dividerHorizontal"/>
+
+ <LinearLayout
+ android:id="@+id/footer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp">
+
+ <Button
+ android:id="@+id/see_more"
+ style="@android:style/Widget.DeviceDefault.Button.Borderless.Colored"
+ android:layout_width="wrap_content"
+ android:layout_height="48dp"
+ android:layout_marginStart="12dp"
+ android:text="@string/see_more"/>
+
+ <Space
+ android:layout_weight="1"
+ android:layout_width="0dp"
+ android:layout_height="match_parent" />
+
+ <Button
+ android:id="@+id/done"
+ style="@android:style/Widget.DeviceDefault.Button.Borderless.Colored"
+ android:layout_width="wrap_content"
+ android:layout_height="48dp"
+ android:layout_marginEnd="12dp"
+ android:text="@string/done"/>
+ </LinearLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/settings_collapsing_base_layout.xml b/res/layout/settings_collapsing_base_layout.xml
index ba9e625..7ebf433 100644
--- a/res/layout/settings_collapsing_base_layout.xml
+++ b/res/layout/settings_collapsing_base_layout.xml
@@ -39,7 +39,7 @@
app:statusBarScrim="?android:attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="18dp"
- app:expandedTitleMarginEnd="18dp"
+ app:expandedTitleMarginEnd="16dp"
app:toolbarId="@id/action_bar">
<Toolbar
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index f78120c..bde5288 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -170,6 +170,7 @@
<declare-styleable name="LabeledSeekBarPreference">
<attr name="textStart" format="reference" />
<attr name="textEnd" format="reference" />
+ <attr name="tickMark" format="reference" />
</declare-styleable>
<declare-styleable name="TintDrawable">
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 16db908..4fef726 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -213,7 +213,7 @@
<dimen name="wifi_detail_page_header_image_size">32dp</dimen>
<!-- Internet Preferences -->
- <dimen name="view_airplane_mode_networks_button_margin_vertical">24dp</dimen>
+ <dimen name="airplane_mode_message_margin_vertical">24dp</dimen>
<dimen name="reset_internet_ring_progress_right_margin">4dp</dimen>
<!-- Color picker -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 03f1e01..db3cf40 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2836,7 +2836,9 @@
<!-- adaptive_sleep settings screen, title about the required permission is missing [CHAR LIMIT=NONE]-->
<string name="adaptive_sleep_title_no_permission">Camera access needed</string>
<!-- adaptive_sleep settings screen, subtitle when permission is missing [CHAR LIMIT=NONE]-->
- <string name="adaptive_sleep_summary_no_permission">Tap to manage permissions for Device Personalization Services</string>
+ <string name="adaptive_sleep_summary_no_permission">Camera access is required for screen attention. Tap to manage permissions for Device Personalization Services</string>
+ <!-- adaptive_sleep settings screen, text for the camera permission button [CHAR LIMIT=NONE]-->
+ <string name="adaptive_sleep_manage_permission_button">Manage permissions</string>
<!-- Description about the feature adaptive sleep [CHAR LIMIT=NONE]-->
<string name="adaptive_sleep_description">Prevents your screen from turning off if you\u2019re looking at it</string>
<!-- Description feature's privacy sensitive details to make sure users understand what feature users, what it saves/sends etc [CHAR LIMIT=NONE]-->
@@ -3186,6 +3188,10 @@
<string name="status_prl_version">PRL version</string>
<!-- About phone screen, title for MEID for multi-sim devices -->
<string name="meid_multi_sim">MEID (sim slot %1$d)</string>
+ <!-- The status text when (Wi-Fi or Bluetooth) scanning is on. [CHAR LIMIT=100] -->
+ <string name="scanning_status_text_on">On</string>
+ <!-- The status text when (Wi-Fi or Bluetooth) scanning is off. [CHAR LIMIT=100] -->
+ <string name="scanning_status_text_off">Off</string>
<!-- The status text when both Wi-Fi scanning and Bluetooth scanning are on. [CHAR LIMIT=100] -->
<string name="scanning_status_text_wifi_on_ble_on">Both Wi\u2011Fi and Bluetooth scanning are on</string>
<!-- The status text when Wi-Fi scanning is on and Bluetooth scanning are off. [CHAR LIMIT=100] -->
@@ -4059,18 +4065,8 @@
<!-- [CHAR LIMIT=50] Location settings screen, sub category for location services for managed profile -->
<string name="managed_profile_location_services">Location services for work</string>
- <!-- [CHAR LIMIT=60] Location settings screen, screen title -->
- <string name="location_time_zone_detection_screen_title">Use location to set time zone</string>
- <!-- [CHAR LIMIT=50] Location settings screen, title for the setting that control whether the
- device can use its location for time zone detection. -->
- <string name="location_time_zone_detection_enabled_title">Location time zone detection</string>
- <!-- [CHAR LIMIT=NONE] Preference description text for location time zone detection -->
- <string name="location_time_zone_detection_enabled_description">Allows the device\u2019s location to be used to detect the current time zone. Other location settings such as Wi\u2011Fi scanning can affect the accuracy of time zone detection.</string>
-
- <!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is on -->
- <string name="location_time_zone_detection_on">On</string>
- <!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is off -->
- <string name="location_time_zone_detection_off">Off</string>
+ <!-- [CHAR LIMIT=60] Date&Time settings screen, toggle button title -->
+ <string name="location_time_zone_detection_toggle_title">Use location to set time zone</string>
<!-- [CHAR LIMIT=NONE] Location settings screen, summary when location time zone detection is not
applicable due to other settings like the "automatic time zone detection enabled" setting
being set to "off". -->
@@ -7841,10 +7837,10 @@
<string name="keywords_display_auto_brightness">dim screen, touchscreen, battery, smart brightness, dynamic brightness, Auto brightness</string>
<!-- Search keywords for adaptive sleep setting [CHAR LIMIT=NONE]-->
- <string name="keywords_display_adaptive_sleep">dim screen, sleep, battery, timeout, attention, display, screen, inactivity</string>
+ <string name="keywords_display_adaptive_sleep">smart, dim screen, sleep, battery, timeout, attention, display, screen, inactivity</string>
<!-- List of synonyms for the auto rotate (rotate the virtual display when the device rotates) setting, used to match in settings search [CHAR LIMIT=NONE] -->
- <string name="keywords_auto_rotate">rotate, flip, rotation, portrait, landscape, orientation, vertical, horizontal</string>
+ <string name="keywords_auto_rotate">camera, smart, auto rotate, auto-rotate, rotate, flip, rotation, portrait, landscape, orientation, vertical, horizontal</string>
<!-- List of synonyms for the System Update (update the operating system) setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_system_update_settings">upgrade, android</string>
@@ -12735,12 +12731,10 @@
<string name="resetting_internet_text">Resetting your internet\u2026</string>
<!-- Menu option for data connectivity recovery for all requested technologies. [CHAR_LIMIT=NONE] -->
<string name="fix_connectivity">Fix connectivity</string>
- <!-- Summary for airplane mode networks available. [CHAR LIMIT=60] -->
- <string name="airplane_mode_network_available">Airplane mode networks available</string>
<!-- Summary for warning to disconnect ethernet first then switch to other networks. [CHAR LIMIT=60] -->
<string name="to_switch_networks_disconnect_ethernet">To switch networks, disconnect ethernet</string>
- <!-- Title for airplane mode network panel. [CHAR LIMIT=60] -->
- <string name="airplane_mode_network_panel_title">Airplane mode networks</string>
+ <!-- Panel subtitle for Wi-Fi turned on. [CHAR LIMIT=60] -->
+ <string name="wifi_is_turned_on_subtitle">Wi\u2011Fi is turned on</string>
<!-- Summary text separator for preferences including a short description
(eg. "Connected / 5G"). [CHAR LIMIT=50] -->
@@ -12790,13 +12784,15 @@
<string name="category_name_others">Others</string>
<!-- General category name [CHAR LIMIT=none] -->
<string name="category_name_general">General</string>
+ <!-- Title for Dark theme main switch preferences. [CHAR LIMIT=50] -->
+ <string name="dark_theme_main_switch_title">Use Dark theme</string>
+ <!-- Title for bluetooth main switch. [CHAR LIMIT=50] -->
+ <string name="bluetooth_main_switch_title">Use Bluetooth</string>
<!-- Do not translate. Title for prevent ringing main switch. [CHAR LIMIT=50] -->
<string name="prevent_ringing_main_switch_title" translatable="false">Use prevent ringing</string>
<!-- Do not translate. Title for use wifi hotspot main switch [CHAR LIMIT=50]-->
<string name="use_wifi_hotsopt_main_switch_title" translatable="false">Use Wi\u2011Fi hotspot</string>
- <!-- Do not translate. Title for bluetooth main switch. [CHAR LIMIT=50] -->
- <string name="bluetooth_main_switch_title" translatable="false">Use bluetooth</string>
<!-- Do not translate. Title for app pinning main switch. [CHAR LIMIT=50] -->
<string name="app_pinning_main_switch_title" translatable="false">Use app pinning</string>
<!-- Do not translate. Title for developer options main switch. [CHAR LIMIT=50] -->
@@ -12813,8 +12809,6 @@
<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] -->
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index 707cae9..95f7944 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -65,56 +65,56 @@
android:summary="@string/promote_conversation_summary"
settings:allowDividerAbove="true"/>
- <!-- Default ringtone -->
- <com.android.settings.notification.app.NotificationSoundPreference
- android:key="ringtone"
- android:title="@string/notification_channel_sound_title"
- android:dialogTitle="@string/notification_channel_sound_title"
- android:order="11"
- android:showSilent="true"
- android:showDefault="true"/>
+ <!-- Default ringtone -->
+ <com.android.settings.notification.app.NotificationSoundPreference
+ android:key="ringtone"
+ android:title="@string/notification_channel_sound_title"
+ android:dialogTitle="@string/notification_channel_sound_title"
+ android:order="11"
+ android:showSilent="true"
+ android:showDefault="true"/>
- <!-- Vibration -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="vibrate"
- android:order="12"
- android:title="@string/notification_vibrate_title"
- settings:useAdditionalSummary="true" />
+ <!-- Vibration -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="vibrate"
+ android:order="12"
+ android:title="@string/notification_vibrate_title"
+ settings:useAdditionalSummary="true" />
- <!-- Visibility Override -->
- <com.android.settings.RestrictedListPreference
- android:key="visibility_override"
- android:order="13"
- android:title="@string/app_notification_visibility_override_title"/>
+ <!-- Visibility Override -->
+ <com.android.settings.RestrictedListPreference
+ android:key="visibility_override"
+ android:order="13"
+ android:title="@string/app_notification_visibility_override_title"/>
- <!-- Lights -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="lights"
- android:order="14"
- android:title="@string/notification_show_lights_title"
- settings:useAdditionalSummary="true"/>
+ <!-- Lights -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="lights"
+ android:order="14"
+ android:title="@string/notification_show_lights_title"
+ settings:useAdditionalSummary="true"/>
- <!-- Show badge -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="badge"
- android:order="15"
- android:title="@string/notification_channel_badge_title"
- settings:useAdditionalSummary="true"
- settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
+ <!-- Show badge -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="badge"
+ android:order="15"
+ android:title="@string/notification_channel_badge_title"
+ settings:useAdditionalSummary="true"
+ settings:restrictedSwitchSummary="@string/enabled_by_admin"/>
- <!-- Bypass DND -->
- <com.android.settingslib.RestrictedSwitchPreference
- android:key="bypass_dnd"
- android:order="17"
- android:title="@string/app_notification_override_dnd_title"
- android:summary="@string/app_notification_override_dnd_summary"
- settings:useAdditionalSummary="true"/>
+ <!-- Bypass DND -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="bypass_dnd"
+ android:order="17"
+ android:title="@string/app_notification_override_dnd_title"
+ android:summary="@string/app_notification_override_dnd_summary"
+ settings:useAdditionalSummary="true"/>
- <Preference
- android:key="app_link"
- android:order="18"
- android:title="@string/app_settings_link"
- settings:allowDividerAbove="true"/>
+ <Preference
+ android:key="app_link"
+ android:order="18"
+ android:title="@string/app_settings_link"
+ settings:allowDividerAbove="true"/>
<com.android.settings.notification.app.NotificationFooterPreference
android:key="desc"
diff --git a/res/xml/conversation_notification_settings.xml b/res/xml/conversation_notification_settings.xml
index 65fdee5..ea555c2 100644
--- a/res/xml/conversation_notification_settings.xml
+++ b/res/xml/conversation_notification_settings.xml
@@ -62,10 +62,6 @@
android:key="block_desc"
settings:allowDividerAbove="false"/>
- <PreferenceCategory
- android:key="channel_advanced"
- android:order="50"
- settings:initialExpandedChildrenCount="0">
<!-- peeking -->
<com.android.settingslib.RestrictedSwitchPreference
@@ -107,6 +103,5 @@
android:icon="@drawable/ic_volume_ringer_vibrate"
android:title="@string/notification_vibrate_title"
settings:useAdditionalSummary="true" />
- </PreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index 43a797a..6fc0b25 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -53,12 +53,12 @@
settings:keywords="@string/keywords_time_zone"/>
<!-- This preference gets removed if location-based time zone detection is not supported -->
- <com.android.settingslib.RestrictedPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="location_time_zone_detection"
- android:title="@string/location_time_zone_detection_screen_title"
+ android:title="@string/location_time_zone_detection_toggle_title"
settings:controller="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceController"
- android:fragment="com.android.settings.datetime.locationtimezone.TimeZoneDetectionSettings"
- settings:userRestriction="no_config_date_time"/>
+ settings:userRestriction="no_config_date_time"
+ />
<PreferenceCategory
android:key="time_format_preference_category"
diff --git a/res/xml/location_services.xml b/res/xml/location_services.xml
index ef94886..516491c 100644
--- a/res/xml/location_services.xml
+++ b/res/xml/location_services.xml
@@ -18,21 +18,21 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/location_services_screen_title">
- <SwitchPreference
- android:title="@string/location_scanning_wifi_always_scanning_title"
- android:summary="@string/location_scanning_wifi_always_scanning_description"
- android:defaultValue="true"
- android:key="wifi_always_scanning" />
-
- <SwitchPreference
- android:title="@string/location_scanning_bluetooth_always_scanning_title"
- android:summary="@string/location_scanning_bluetooth_always_scanning_description"
- android:defaultValue="true"
- android:key="bluetooth_always_scanning" />
-
<PreferenceCategory
android:key="location_services"
android:layout="@layout/preference_category_no_label"
settings:controller="com.android.settings.location.LocationInjectedServicesPreferenceController"/>
+ <Preference
+ android:fragment="com.android.settings.location.WifiScanningFragment"
+ android:key="location_services_wifi_scanning"
+ android:title="@string/location_scanning_wifi_always_scanning_title"
+ settings:controller="com.android.settings.location.LocationServicesWifiScanningPreferenceController"/>
+
+ <Preference
+ android:fragment="com.android.settings.location.BluetoothScanningFragment"
+ android:key="location_services_bluetooth_scanning"
+ android:title="@string/location_scanning_bluetooth_always_scanning_title"
+ settings:controller="com.android.settings.location.LocationServicesBluetoothScanningPreferenceController"/>
+
</PreferenceScreen>
diff --git a/res/xml/location_services_bluetooth_scanning.xml b/res/xml/location_services_bluetooth_scanning.xml
new file mode 100644
index 0000000..fb522f0
--- /dev/null
+++ b/res/xml/location_services_bluetooth_scanning.xml
@@ -0,0 +1,32 @@
+<?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:title="@string/location_scanning_bluetooth_always_scanning_title">
+
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="bluetooth_always_scanning_switch"
+ android:title="@string/location_scanning_bluetooth_always_scanning_title"
+ settings:controller="com.android.settings.location.BluetoothScanningMainSwitchPreferenceController"/>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="bluetooth_always_scanning_footer"
+ android:title="@string/location_scanning_bluetooth_always_scanning_description"
+ android:selectable="false"
+ settings:searchable="false"/>
+
+</PreferenceScreen>
diff --git a/res/xml/location_services_wifi_scanning.xml b/res/xml/location_services_wifi_scanning.xml
new file mode 100644
index 0000000..a436fac
--- /dev/null
+++ b/res/xml/location_services_wifi_scanning.xml
@@ -0,0 +1,32 @@
+<?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:title="@string/location_scanning_wifi_always_scanning_title">
+
+ <com.android.settingslib.widget.MainSwitchPreference
+ android:key="wifi_always_scanning_switch"
+ android:title="@string/location_scanning_wifi_always_scanning_title"
+ settings:controller="com.android.settings.location.WifiScanningMainSwitchPreferenceController"/>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="wifi_always_scanning_footer"
+ android:title="@string/location_scanning_wifi_always_scanning_description"
+ android:selectable="false"
+ settings:searchable="false"/>
+
+</PreferenceScreen>
diff --git a/res/xml/location_time_zone_detection.xml b/res/xml/location_time_zone_detection.xml
deleted file mode 100644
index 9f5e775..0000000
--- a/res/xml/location_time_zone_detection.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 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:title="@string/location_time_zone_detection_screen_title">
-
- <SwitchPreference
- android:title="@string/location_time_zone_detection_enabled_title"
- android:summary="@string/location_time_zone_detection_enabled_description"
- settings:controller="com.android.settings.datetime.locationtimezone.TimeZoneDetectionTogglePreferenceController"
- android:key="location_time_zone_detection_enabled" />
-
-</PreferenceScreen>
diff --git a/res/xml/network_provider_settings.xml b/res/xml/network_provider_settings.xml
index a824b34..30fe6fe 100644
--- a/res/xml/network_provider_settings.xml
+++ b/res/xml/network_provider_settings.xml
@@ -28,12 +28,12 @@
android:layout="@layout/resetting_internet"
settings:allowDividerBelow="true"/>
- <!-- View airplane mode networks button -->
+ <!-- Airplane mode message -->
<com.android.settingslib.widget.LayoutPreference
- android:key="view_airplane_mode_netwokrs_button"
+ android:key="airplane_mode_message"
android:title="@string/condition_airplane_title"
android:selectable="false"
- android:layout="@layout/view_airplane_mode_networks_button"
+ android:layout="@layout/airplane_mode_message_preference"
settings:allowDividerBelow="true"/>
<Preference
diff --git a/src/com/android/settings/ActivityPicker.java b/src/com/android/settings/ActivityPicker.java
index ae61944..f75ce37 100644
--- a/src/com/android/settings/ActivityPicker.java
+++ b/src/com/android/settings/ActivityPicker.java
@@ -16,6 +16,8 @@
package com.android.settings;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
@@ -71,6 +73,8 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ getWindow().addPrivateFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
final Intent intent = getIntent();
diff --git a/src/com/android/settings/applications/AppDashboardFragment.java b/src/com/android/settings/applications/AppDashboardFragment.java
index fc4bcd0..3b1a977 100644
--- a/src/com/android/settings/applications/AppDashboardFragment.java
+++ b/src/com/android/settings/applications/AppDashboardFragment.java
@@ -48,7 +48,7 @@
@Override
public int getMetricsCategory() {
- return SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY;
+ return SettingsEnums.MANAGE_APPLICATIONS;
}
@Override
diff --git a/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java b/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
index 83b4241..307ceb1 100644
--- a/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
@@ -230,7 +230,7 @@
@Override
@NonNull
public Loader<BatteryUsageStats> onCreateLoader(int id, Bundle args) {
- return new BatteryUsageStatsLoader(mContext);
+ return new BatteryUsageStatsLoader(mContext, /* includeBatteryHistory */ false);
}
@Override
diff --git a/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java b/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java
index e5953db..d4ea4a9 100644
--- a/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java
+++ b/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java
@@ -24,7 +24,6 @@
import android.provider.Settings;
import android.text.TextUtils;
-import com.android.internal.app.AssistUtils;
import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
import com.android.settingslib.applications.DefaultAppInfo;
@@ -35,8 +34,6 @@
public class DefaultVoiceInputPicker extends DefaultAppPickerFragment {
private VoiceInputHelper mHelper;
- private AssistUtils mAssistUtils;
- private String mAssistRestrict;
@Override
public int getMetricsCategory() {
@@ -46,13 +43,8 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
- mAssistUtils = new AssistUtils(context);
mHelper = new VoiceInputHelper(context);
mHelper.buildUi();
- final ComponentName assist = getCurrentAssist();
- if (isCurrentAssistVoiceService(assist, getCurrentService(mHelper))) {
- mAssistRestrict = assist.flattenToShortString();
- }
}
@Override
@@ -64,16 +56,9 @@
protected List<VoiceInputDefaultAppInfo> getCandidates() {
final List<VoiceInputDefaultAppInfo> candidates = new ArrayList<>();
final Context context = getContext();
- boolean hasEnabled = true;
- for (VoiceInputHelper.InteractionInfo info : mHelper.mAvailableInteractionInfos) {
- final boolean enabled = TextUtils.equals(info.key, mAssistRestrict);
- hasEnabled |= enabled;
- candidates.add(new VoiceInputDefaultAppInfo(context, mPm, mUserId, info, enabled));
- }
- final boolean assistIsService = !hasEnabled;
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
- final boolean enabled = !assistIsService;
+ final boolean enabled = true;
candidates.add(new VoiceInputDefaultAppInfo(context, mPm, mUserId, info, enabled));
}
return candidates;
@@ -90,24 +75,9 @@
@Override
protected boolean setDefaultKey(String value) {
- for (VoiceInputHelper.InteractionInfo info : mHelper.mAvailableInteractionInfos) {
- if (TextUtils.equals(value, info.key)) {
- Settings.Secure.putString(getContext().getContentResolver(),
- Settings.Secure.VOICE_INTERACTION_SERVICE, value);
- Settings.Secure.putString(getContext().getContentResolver(),
- Settings.Secure.VOICE_RECOGNITION_SERVICE,
- new ComponentName(info.service.packageName,
- info.serviceInfo.getRecognitionService())
- .flattenToShortString());
- return true;
- }
- }
-
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
if (TextUtils.equals(value, info.key)) {
Settings.Secure.putString(getContext().getContentResolver(),
- Settings.Secure.VOICE_INTERACTION_SERVICE, "");
- Settings.Secure.putString(getContext().getContentResolver(),
Settings.Secure.VOICE_RECOGNITION_SERVICE, value);
return true;
}
@@ -116,23 +86,7 @@
}
public static ComponentName getCurrentService(VoiceInputHelper helper) {
- if (helper.mCurrentVoiceInteraction != null) {
- return helper.mCurrentVoiceInteraction;
- } else if (helper.mCurrentRecognizer != null) {
- return helper.mCurrentRecognizer;
- } else {
- return null;
- }
- }
-
- private ComponentName getCurrentAssist() {
- return mAssistUtils.getAssistComponentForUser(mUserId);
- }
-
- public static boolean isCurrentAssistVoiceService(ComponentName currentAssist,
- ComponentName currentVoiceService) {
- return currentAssist == null && currentVoiceService == null ||
- currentAssist != null && currentAssist.equals(currentVoiceService);
+ return helper.mCurrentRecognizer;
}
public static class VoiceInputDefaultAppInfo extends DefaultAppInfo {
@@ -152,11 +106,7 @@
@Override
public CharSequence loadLabel() {
- if (mInfo instanceof VoiceInputHelper.InteractionInfo) {
- return mInfo.appLabel;
- } else {
- return mInfo.label;
- }
+ return mInfo.label;
}
public Intent getSettingIntent() {
diff --git a/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java b/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java
index e53334d..59f5731 100644
--- a/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java
+++ b/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java
@@ -26,7 +26,6 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
-import com.android.internal.app.AssistUtils;
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
import com.android.settingslib.applications.DefaultAppInfo;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -42,17 +41,13 @@
private static final String KEY_VOICE_INPUT = "voice_input_settings";
private VoiceInputHelper mHelper;
- private AssistUtils mAssistUtils;
private PreferenceScreen mScreen;
private Preference mPreference;
- private SettingObserver mSettingObserver;
private Context mContext;
public DefaultVoiceInputPreferenceController(Context context, Lifecycle lifecycle) {
super(context);
mContext = context;
- mSettingObserver = new SettingObserver();
- mAssistUtils = new AssistUtils(context);
mHelper = new VoiceInputHelper(context);
mHelper.buildUi();
if (lifecycle != null) {
@@ -80,7 +75,6 @@
@Override
public void onResume() {
- mSettingObserver.register(mContext.getContentResolver(), true);
updatePreference();
}
@@ -91,9 +85,7 @@
}
@Override
- public void onPause() {
- mSettingObserver.register(mContext.getContentResolver(), false);
- }
+ public void onPause() {}
@Override
protected DefaultAppInfo getDefaultAppInfo() {
@@ -101,12 +93,6 @@
if (defaultKey == null) {
return null;
}
- for (VoiceInputHelper.InteractionInfo info : mHelper.mAvailableInteractionInfos) {
- if (TextUtils.equals(defaultKey, info.key)) {
- return new DefaultVoiceInputPicker.VoiceInputDefaultAppInfo(mContext,
- mPackageManager, mUserId, info, true /* enabled */);
- }
- }
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
if (TextUtils.equals(defaultKey, info.key)) {
@@ -149,16 +135,4 @@
}
return currentService.flattenToShortString();
}
-
- class SettingObserver extends AssistSettingObserver {
- @Override
- protected List<Uri> getSettingUris() {
- return null;
- }
-
- @Override
- public void onSettingChange() {
- updatePreference();
- }
- }
}
diff --git a/src/com/android/settings/applications/assist/VoiceInputHelper.java b/src/com/android/settings/applications/assist/VoiceInputHelper.java
index fb60090..285f4f7 100644
--- a/src/com/android/settings/applications/assist/VoiceInputHelper.java
+++ b/src/com/android/settings/applications/assist/VoiceInputHelper.java
@@ -26,10 +26,7 @@
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.provider.Settings;
-import android.service.voice.VoiceInteractionService;
-import android.service.voice.VoiceInteractionServiceInfo;
import android.speech.RecognitionService;
-import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
@@ -46,9 +43,9 @@
static final String TAG = "VoiceInputHelper";
final Context mContext;
- final List<ResolveInfo> mAvailableVoiceInteractions;
final List<ResolveInfo> mAvailableRecognition;
+ // TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
static public class BaseInfo implements Comparable {
public final ServiceInfo service;
public final ComponentName componentName;
@@ -75,15 +72,6 @@
}
}
- static public class InteractionInfo extends BaseInfo {
- public final VoiceInteractionServiceInfo serviceInfo;
-
- public InteractionInfo(PackageManager pm, VoiceInteractionServiceInfo _service) {
- super(pm, _service.getServiceInfo(), _service.getSettingsActivity());
- serviceInfo = _service;
- }
- }
-
static public class RecognizerInfo extends BaseInfo {
public final boolean mSelectableAsDefault;
@@ -96,56 +84,21 @@
}
}
- final ArrayList<InteractionInfo> mAvailableInteractionInfos = new ArrayList<>();
final ArrayList<RecognizerInfo> mAvailableRecognizerInfos = new ArrayList<>();
- ComponentName mCurrentVoiceInteraction;
ComponentName mCurrentRecognizer;
public VoiceInputHelper(Context context) {
mContext = context;
- mAvailableVoiceInteractions = mContext.getPackageManager().queryIntentServices(
- new Intent(VoiceInteractionService.SERVICE_INTERFACE),
- PackageManager.GET_META_DATA);
mAvailableRecognition = mContext.getPackageManager().queryIntentServices(
new Intent(RecognitionService.SERVICE_INTERFACE),
PackageManager.GET_META_DATA);
}
public void buildUi() {
- // Get the currently selected interactor from the secure setting.
- String currentSetting = Settings.Secure.getString(
- mContext.getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE);
- if (currentSetting != null && !currentSetting.isEmpty()) {
- mCurrentVoiceInteraction = ComponentName.unflattenFromString(currentSetting);
- } else {
- mCurrentVoiceInteraction = null;
- }
-
- ArraySet<ComponentName> interactorRecognizers = new ArraySet<>();
-
- // Iterate through all the available interactors and load up their info to show
- // in the preference.
- int size = mAvailableVoiceInteractions.size();
- for (int i = 0; i < size; i++) {
- ResolveInfo resolveInfo = mAvailableVoiceInteractions.get(i);
- VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(
- mContext.getPackageManager(), resolveInfo.serviceInfo);
- if (info.getParseError() != null) {
- Log.w("VoiceInteractionService", "Error in VoiceInteractionService "
- + resolveInfo.serviceInfo.packageName + "/"
- + resolveInfo.serviceInfo.name + ": " + info.getParseError());
- continue;
- }
- mAvailableInteractionInfos.add(new InteractionInfo(mContext.getPackageManager(), info));
- interactorRecognizers.add(new ComponentName(resolveInfo.serviceInfo.packageName,
- info.getRecognitionService()));
- }
- Collections.sort(mAvailableInteractionInfos);
-
// Get the currently selected recognizer from the secure setting.
- currentSetting = Settings.Secure.getString(
+ String currentSetting = Settings.Secure.getString(
mContext.getContentResolver(), Settings.Secure.VOICE_RECOGNITION_SERVICE);
if (currentSetting != null && !currentSetting.isEmpty()) {
mCurrentRecognizer = ComponentName.unflattenFromString(currentSetting);
@@ -155,14 +108,11 @@
// Iterate through all the available recognizers and load up their info to show
// in the preference.
- size = mAvailableRecognition.size();
+ int size = mAvailableRecognition.size();
for (int i = 0; i < size; i++) {
ResolveInfo resolveInfo = mAvailableRecognition.get(i);
ComponentName comp = new ComponentName(resolveInfo.serviceInfo.packageName,
resolveInfo.serviceInfo.name);
- if (interactorRecognizers.contains(comp)) {
- //continue;
- }
ServiceInfo si = resolveInfo.serviceInfo;
String settingsActivity = null;
// Always show in voice input settings unless specifically set to False.
diff --git a/src/com/android/settings/applications/autofill/PasswordsPreferenceController.java b/src/com/android/settings/applications/autofill/PasswordsPreferenceController.java
index 792f2ee..f27530e 100644
--- a/src/com/android/settings/applications/autofill/PasswordsPreferenceController.java
+++ b/src/com/android/settings/applications/autofill/PasswordsPreferenceController.java
@@ -31,6 +31,7 @@
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
@@ -47,16 +48,23 @@
private final List<AutofillServiceInfo> mServices;
public PasswordsPreferenceController(Context context, String preferenceKey) {
+ this(context, preferenceKey,
+ AutofillServiceInfo.getAvailableServices(context, UserHandle.myUserId()));
+ }
+
+ @VisibleForTesting
+ public PasswordsPreferenceController(
+ Context context, String preferenceKey, List<AutofillServiceInfo> availableServices) {
super(context, preferenceKey);
mPm = context.getPackageManager();
mIconFactory = IconDrawableFactory.newInstance(mContext);
- mServices = AutofillServiceInfo.getAvailableServices(mContext, UserHandle.myUserId());
- for (int i = mServices.size() - 1; i >= 0; i--) {
- final String passwordsActivity = mServices.get(i).getPasswordsActivity();
+ for (int i = availableServices.size() - 1; i >= 0; i--) {
+ final String passwordsActivity = availableServices.get(i).getPasswordsActivity();
if (TextUtils.isEmpty(passwordsActivity)) {
- mServices.remove(i);
+ availableServices.remove(i);
}
}
+ mServices = availableServices;
}
@Override
diff --git a/src/com/android/settings/biometrics/BiometricEnrollBase.java b/src/com/android/settings/biometrics/BiometricEnrollBase.java
index 3fb8941..67148d1 100644
--- a/src/com/android/settings/biometrics/BiometricEnrollBase.java
+++ b/src/com/android/settings/biometrics/BiometricEnrollBase.java
@@ -48,6 +48,8 @@
public static final String EXTRA_KEY_LAUNCHED_CONFIRM = "launched_confirm_lock";
public static final String EXTRA_KEY_REQUIRE_VISION = "accessibility_vision";
public static final String EXTRA_KEY_REQUIRE_DIVERSITY = "accessibility_diversity";
+ public static final String EXTRA_KEY_SENSOR_ID = "sensor_id";
+ public static final String EXTRA_KEY_CHALLENGE = "challenge";
/**
* Used by the choose fingerprint wizard to indicate the wizard is
@@ -90,12 +92,16 @@
protected boolean mLaunchedConfirmLock;
protected byte[] mToken;
protected int mUserId;
+ protected int mSensorId;
+ protected long mChallenge;
protected boolean mFromSettingsSummary;
protected FooterBarMixin mFooterBarMixin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mChallenge = getIntent().getLongExtra(EXTRA_KEY_CHALLENGE, -1L);
+ mSensorId = getIntent().getIntExtra(EXTRA_KEY_SENSOR_ID, -1);
// Don't need to retrieve the HAT if it already exists. In some cases, the extras do not
// contain EXTRA_KEY_CHALLENGE_TOKEN but contain EXTRA_KEY_GK_PW, in which case enrollment
// classes may request a HAT to be created (as opposed to being passed in)
@@ -110,6 +116,8 @@
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
mFromSettingsSummary =
savedInstanceState.getBoolean(EXTRA_FROM_SETTINGS_SUMMARY, false);
+ mChallenge = savedInstanceState.getLong(EXTRA_KEY_CHALLENGE);
+ mSensorId = savedInstanceState.getInt(EXTRA_KEY_SENSOR_ID);
}
mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
}
@@ -127,6 +135,8 @@
outState.putBoolean(EXTRA_KEY_LAUNCHED_CONFIRM, mLaunchedConfirmLock);
outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
outState.putBoolean(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
+ outState.putLong(EXTRA_KEY_CHALLENGE, mChallenge);
+ outState.putInt(EXTRA_KEY_SENSOR_ID, mSensorId);
}
@Override
@@ -173,10 +183,18 @@
setHeaderText(resId, false /* force */);
}
+ protected void setHeaderText(CharSequence title) {
+ getLayout().setHeaderText(title);
+ }
+
protected void setDescriptionText(int resId) {
getLayout().setDescriptionText(resId);
}
+ protected void setDescriptionText(CharSequence descriptionText) {
+ getLayout().setDescriptionText(descriptionText);
+ }
+
protected FooterButton getNextButton() {
if (mFooterBarMixin != null) {
return mFooterBarMixin.getPrimaryButton();
@@ -192,6 +210,8 @@
intent.setClassName(SETTINGS_PACKAGE_NAME, FingerprintEnrollEnrolling.class.getName());
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
+ intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
+ intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
if (mUserId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
}
diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
index 09344b0..b44c2c9 100644
--- a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
@@ -243,6 +243,8 @@
}
BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
+ intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
+ intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST);
}
@@ -262,6 +264,8 @@
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
getNextButton().setEnabled(false);
getChallenge(((sensorId, challenge) -> {
+ mSensorId = sensorId;
+ mChallenge = challenge;
mToken = BiometricUtils.requestGatekeeperHat(this, data, mUserId, challenge);
BiometricUtils.removeGatekeeperPasswordHandle(this, data);
getNextButton().setEnabled(true);
@@ -276,6 +280,8 @@
overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
getNextButton().setEnabled(false);
getChallenge(((sensorId, challenge) -> {
+ mSensorId = sensorId;
+ mChallenge = challenge;
mToken = BiometricUtils.requestGatekeeperHat(this, data, mUserId, challenge);
BiometricUtils.removeGatekeeperPasswordHandle(this, data);
getNextButton().setEnabled(true);
diff --git a/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java b/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java
index 9b86e78..0bfe56e 100644
--- a/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java
@@ -121,6 +121,8 @@
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
+ intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, mSensorId);
+ intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
if (mUserId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
diff --git a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java
index 1ea6b08..84128e2 100644
--- a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java
+++ b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java
@@ -72,6 +72,8 @@
mGkPwHandle, mUserId, challenge);
final Intent faceIntent = BiometricUtils.getFaceIntroIntent(mActivity,
mActivity.getIntent());
+ faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId);
+ faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);
if (mRequestEnrollFingerprint) {
// Give FaceEnroll a pendingIntent pointing to fingerprint enrollment, so that it
@@ -97,6 +99,8 @@
mGkPwHandle, mUserId, challenge);
final Intent intent = BiometricUtils.getFingerprintIntroIntent(mActivity,
mActivity.getIntent());
+ intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId);
+ intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);
BiometricUtils.launchEnrollForResult(mActivity, intent, REQUEST_FINGERPRINT_ENROLL,
hardwareAuthToken, mGkPwHandle, mUserId);
}));
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
index 3e9fba2..6c5a4b4 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
@@ -183,6 +183,8 @@
if (mUserId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
}
+ intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
+ intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
final String flattenedString = getString(R.string.config_face_enroll);
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
index 3bffbbf..9110292 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
@@ -112,6 +112,8 @@
// the challenge is ready. Let's just do this for now.
mFaceManager.generateChallenge((sensorId, challenge) -> {
mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge);
+ mSensorId = sensorId;
+ mChallenge = challenge;
if (BiometricUtils.isMultiBiometricEnrollmentFlow(this)) {
BiometricUtils.removeGatekeeperPasswordHandle(this, getIntent());
}
diff --git a/src/com/android/settings/biometrics/face/FaceSettings.java b/src/com/android/settings/biometrics/face/FaceSettings.java
index 7751485..038d448 100644
--- a/src/com/android/settings/biometrics/face/FaceSettings.java
+++ b/src/com/android/settings/biometrics/face/FaceSettings.java
@@ -37,6 +37,7 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
+import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
@@ -67,6 +68,8 @@
private UserManager mUserManager;
private FaceManager mFaceManager;
private int mUserId;
+ private int mSensorId;
+ private long mChallenge;
private byte[] mToken;
private FaceSettingsAttentionPreferenceController mAttentionController;
private FaceSettingsRemoveButtonPreferenceController mRemoveController;
@@ -147,6 +150,8 @@
mUserManager = context.getSystemService(UserManager.class);
mFaceManager = context.getSystemService(FaceManager.class);
mToken = getIntent().getByteArrayExtra(KEY_TOKEN);
+ mSensorId = getIntent().getIntExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, -1);
+ mChallenge = getIntent().getLongExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, 0L);
mUserId = getActivity().getIntent().getIntExtra(
Intent.EXTRA_USER_ID, UserHandle.myUserId());
@@ -247,6 +252,8 @@
mFaceManager.generateChallenge((sensorId, challenge) -> {
mToken = BiometricUtils.requestGatekeeperHat(getPrefContext(), data, mUserId,
challenge);
+ mSensorId = sensorId;
+ mChallenge = challenge;
BiometricUtils.removeGatekeeperPasswordHandle(getPrefContext(), data);
mAttentionController.setToken(mToken);
mEnrollController.setToken(mToken);
@@ -269,7 +276,7 @@
&& !mConfirmingPassword) {
// Revoke challenge and finish
if (mToken != null) {
- mFaceManager.revokeChallenge();
+ mFaceManager.revokeChallenge(mSensorId, mUserId, mChallenge);
mToken = null;
}
finish();
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index b403e42..10b31e3 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -324,7 +324,9 @@
@Override
public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
if (!TextUtils.isEmpty(helpString)) {
- mErrorText.removeCallbacks(mTouchAgainRunnable);
+ if (!mCanAssumeUdfps) {
+ mErrorText.removeCallbacks(mTouchAgainRunnable);
+ }
showError(helpString);
}
}
@@ -345,7 +347,9 @@
}
showErrorDialog(getText(msgId), errMsgId);
stopIconAnimation();
- mErrorText.removeCallbacks(mTouchAgainRunnable);
+ if (!mCanAssumeUdfps) {
+ mErrorText.removeCallbacks(mTouchAgainRunnable);
+ }
}
@Override
@@ -354,8 +358,10 @@
updateTitleAndDescription();
clearError();
animateFlash();
- mErrorText.removeCallbacks(mTouchAgainRunnable);
- mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION);
+ if (!mCanAssumeUdfps) {
+ mErrorText.removeCallbacks(mTouchAgainRunnable);
+ mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION);
+ }
}
private void updateProgress(boolean animate) {
@@ -397,22 +403,28 @@
}
private void showError(CharSequence error) {
- mErrorText.setText(error);
- if (mErrorText.getVisibility() == View.INVISIBLE) {
- mErrorText.setVisibility(View.VISIBLE);
- mErrorText.setTranslationY(getResources().getDimensionPixelSize(
- R.dimen.fingerprint_error_text_appear_distance));
- mErrorText.setAlpha(0f);
- mErrorText.animate()
- .alpha(1f)
- .translationY(0f)
- .setDuration(200)
- .setInterpolator(mLinearOutSlowInInterpolator)
- .start();
+ if (mCanAssumeUdfps) {
+ setHeaderText(error);
+ // Show nothing for subtitle when getting an error message.
+ setDescriptionText("");
} else {
- mErrorText.animate().cancel();
- mErrorText.setAlpha(1f);
- mErrorText.setTranslationY(0f);
+ mErrorText.setText(error);
+ if (mErrorText.getVisibility() == View.INVISIBLE) {
+ mErrorText.setVisibility(View.VISIBLE);
+ mErrorText.setTranslationY(getResources().getDimensionPixelSize(
+ R.dimen.fingerprint_error_text_appear_distance));
+ mErrorText.setAlpha(0f);
+ mErrorText.animate()
+ .alpha(1f)
+ .translationY(0f)
+ .setDuration(200)
+ .setInterpolator(mLinearOutSlowInInterpolator)
+ .start();
+ } else {
+ mErrorText.animate().cancel();
+ mErrorText.setAlpha(1f);
+ mErrorText.setTranslationY(0f);
+ }
}
if (isResumed()) {
mVibrator.vibrate(VIBRATE_EFFECT_ERROR, FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES);
@@ -420,7 +432,7 @@
}
private void clearError() {
- if (mErrorText.getVisibility() == View.VISIBLE) {
+ if (!mCanAssumeUdfps && mErrorText.getVisibility() == View.VISIBLE) {
mErrorText.animate()
.alpha(0f)
.translationY(getResources().getDimensionPixelSize(
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
index 094336a..94eb278 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
@@ -81,6 +81,8 @@
if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
final FingerprintManager fpm = getSystemService(FingerprintManager.class);
fpm.generateChallenge(mUserId, (sensorId, challenge) -> {
+ mChallenge = challenge;
+ mSensorId = sensorId;
mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge);
BiometricUtils.removeGatekeeperPasswordHandle(this, getIntent());
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java
index 481da1b..a989eef 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java
@@ -141,7 +141,7 @@
private void postEnroll() {
final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this);
if (fpm != null) {
- fpm.revokeChallenge(mUserId);
+ fpm.revokeChallenge(mUserId, mChallenge);
}
}
@@ -151,6 +151,7 @@
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
+ intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge);
startActivity(intent);
}
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
index 1d2793a..3e0591f 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
@@ -138,6 +138,8 @@
private CharSequence mFooterTitle;
private boolean mEnrollClicked;
+ private long mChallenge;
+
private static final String TAG_AUTHENTICATE_SIDECAR = "authenticate_sidecar";
private static final String TAG_REMOVAL_SIDECAR = "removal_sidecar";
private FingerprintAuthenticateSidecar mAuthenticateSidecar;
@@ -287,6 +289,8 @@
mToken = getIntent().getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
+ mChallenge = activity.getIntent()
+ .getLongExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, -1L);
mAuthenticateSidecar = (FingerprintAuthenticateSidecar)
getFragmentManager().findFragmentByTag(TAG_AUTHENTICATE_SIDECAR);
@@ -577,6 +581,7 @@
mFingerprintManager.generateChallenge(mUserId, (sensorId, challenge) -> {
mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data,
mUserId, challenge);
+ mChallenge = challenge;
BiometricUtils.removeGatekeeperPasswordHandle(getActivity(), data);
updateAddPreference();
});
@@ -602,7 +607,7 @@
public void onDestroy() {
super.onDestroy();
if (getActivity().isFinishing()) {
- mFingerprintManager.revokeChallenge(mUserId);
+ mFingerprintManager.revokeChallenge(mUserId, mChallenge);
}
}
diff --git a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
index 394b673..5f2fbb5 100644
--- a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
@@ -40,6 +40,8 @@
protected Intent getFingerprintEnrollingIntent() {
Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
+ intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
+ intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
if (mUserId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
}
diff --git a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
index bbfbb19..1a45640 100644
--- a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
+++ b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
@@ -31,7 +31,7 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -43,7 +43,7 @@
* screen.
*/
public class LocationTimeZoneDetectionPreferenceController
- extends BasePreferenceController
+ extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop, TimeManager.TimeZoneDetectorListener {
private final TimeManager mTimeManager;
@@ -58,6 +58,22 @@
}
@Override
+ public boolean isChecked() {
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
+ mTimeManager.getTimeZoneCapabilitiesAndConfig();
+ TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
+ return configuration.isGeoDetectionEnabled();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(isChecked)
+ .build();
+ return mTimeManager.updateTimeZoneConfiguration(configuration);
+ }
+
+ @Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
@@ -126,10 +142,10 @@
summaryResId = R.string.location_time_zone_detection_not_applicable;
}
} else if (configureGeoDetectionEnabledCapability == CAPABILITY_POSSESSED) {
- boolean isGeoDetectionEnabled = configuration.isGeoDetectionEnabled();
- summaryResId = isGeoDetectionEnabled
- ? R.string.location_time_zone_detection_on
- : R.string.location_time_zone_detection_off;
+ // If capability is possessed, toggle status already tells all the information needed.
+ // Returning null will make previous text stick on toggling.
+ // See AbstractPreferenceController#refreshSummary.
+ return "";
} else {
// This is unexpected: getAvailabilityStatus() should ensure that the UI element isn't
// even shown for known cases, or the capability is unknown.
diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java
deleted file mode 100644
index db6ffc4..0000000
--- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2020 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.datetime.locationtimezone;
-
-import android.app.settings.SettingsEnums;
-
-import com.android.settings.R;
-import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.search.SearchIndexable;
-
-/**
- * The controller for the "location time zone detection" screen.
- */
-@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
-public class TimeZoneDetectionSettings extends DashboardFragment {
- private static final String TAG = "LTZDetectionSettings";
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.LOCATION_TIME_ZONE_DETECTION;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.location_time_zone_detection;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- /**
- * For Search.
- */
- public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.location_time_zone_detection);
-}
diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java
deleted file mode 100644
index c91be7f..0000000
--- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2020 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.datetime.locationtimezone;
-
-import android.app.time.TimeManager;
-import android.app.time.TimeZoneCapabilitiesAndConfig;
-import android.app.time.TimeZoneConfiguration;
-import android.content.Context;
-
-import com.android.settings.core.TogglePreferenceController;
-
-/**
- * The controller for the "location time zone detection" switch on the location time zone detection
- * screen.
- */
-public class TimeZoneDetectionTogglePreferenceController extends TogglePreferenceController {
-
- private final TimeManager mTimeManager;
-
- public TimeZoneDetectionTogglePreferenceController(Context context, String key) {
- super(context, key);
- mTimeManager = context.getSystemService(TimeManager.class);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
- mTimeManager.getTimeZoneCapabilitiesAndConfig();
- TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
- return configuration.isGeoDetectionEnabled();
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(isChecked)
- .build();
- return mTimeManager.updateTimeZoneConfiguration(configuration);
- }
-}
diff --git a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java
index 1110ad2..0d21e9c 100644
--- a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java
+++ b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java
@@ -23,11 +23,11 @@
import android.content.pm.PackageManager;
import android.net.Uri;
-import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
+import com.android.settingslib.widget.BannerMessagePreference;
/**
* The controller of Screen attention's permission warning preference. The preference appears when
@@ -35,8 +35,8 @@
*/
public class AdaptiveSleepPermissionPreferenceController {
@VisibleForTesting
- Preference mPreference;
- private PackageManager mPackageManager;
+ BannerMessagePreference mPreference;
+ private final PackageManager mPackageManager;
public AdaptiveSleepPermissionPreferenceController(Context context) {
final String packageName = context.getPackageManager().getAttentionServicePackageName();
@@ -44,13 +44,12 @@
final Intent intent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
- mPreference = new Preference(context);
+ mPreference = new BannerMessagePreference(context);
mPreference.setTitle(R.string.adaptive_sleep_title_no_permission);
mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission);
- mPreference.setIcon(R.drawable.ic_info_outline_24);
- mPreference.setOnPreferenceClickListener(p -> {
+ mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button);
+ mPreference.setPositiveButtonOnClickListener(p -> {
context.startActivity(intent);
- return true;
});
}
diff --git a/src/com/android/settings/display/ScreenTimeoutSettings.java b/src/com/android/settings/display/ScreenTimeoutSettings.java
index f9bb99e..3b0d333 100644
--- a/src/com/android/settings/display/ScreenTimeoutSettings.java
+++ b/src/com/android/settings/display/ScreenTimeoutSettings.java
@@ -23,7 +23,6 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
-import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.SpannableString;
@@ -39,8 +38,6 @@
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.actionbar.SearchMenuController;
-import com.android.settings.support.actionbar.HelpMenuController;
import com.android.settings.support.actionbar.HelpResourceProvider;
import com.android.settings.widget.RadioButtonPickerFragment;
import com.android.settingslib.RestrictedLockUtils;
@@ -92,13 +89,6 @@
}
@Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- SearchMenuController.init(this /* host */);
- HelpMenuController.init(this /* host */);
- }
-
- @Override
public void onAttach(Context context) {
super.onAttach(context);
mInitialEntries = getResources().getStringArray(R.array.screen_timeout_entries);
diff --git a/src/com/android/settings/emergency/EmergencyActionContentProvider.java b/src/com/android/settings/emergency/EmergencyActionContentProvider.java
new file mode 100644
index 0000000..03f0faf
--- /dev/null
+++ b/src/com/android/settings/emergency/EmergencyActionContentProvider.java
@@ -0,0 +1,112 @@
+/*
+ * 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.emergency;
+
+import static android.telecom.TelecomManager.EXTRA_CALL_SOURCE;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.telecom.PhoneAccount;
+import android.telecom.TelecomManager;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settingslib.emergencynumber.EmergencyNumberUtils;
+
+/**
+ * ContentProvider to delegate emergency action work
+ */
+public class EmergencyActionContentProvider extends ContentProvider {
+ private static final String TAG = "EmergencyActionContentP";
+
+ private static final String ACTION_START_EMERGENCY_CALL =
+ "com.android.settings.emergency.MAKE_EMERGENCY_CALL";
+
+ @Override
+ public Bundle call(String authority, String method, String arg, Bundle extras) {
+ int uid = Binder.getCallingUid();
+ Log.d(TAG, "calling pid/uid" + Binder.getCallingPid() + "/" + uid);
+ if (!isEmergencyInfo(getContext())) {
+ throw new SecurityException("Uid is not allowed: " + uid);
+ }
+ if (!TextUtils.equals(method, ACTION_START_EMERGENCY_CALL)) {
+ throw new IllegalArgumentException("Unsupported operation");
+ }
+ placeEmergencyCall(getContext());
+ return new Bundle();
+ }
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ String sortOrder) {
+ return null;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ return null;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ return null;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ return 0;
+ }
+
+ private static boolean isEmergencyInfo(Context context) {
+ final int callingUid = Binder.getCallingUid();
+ final String callingPackage = context.getPackageManager().getPackagesForUid(callingUid)[0];
+ return TextUtils.equals(callingPackage,
+ context.getString(R.string.config_aosp_emergency_package_name));
+ }
+
+ private static void placeEmergencyCall(Context context) {
+ if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+ Log.i(TAG, "Telephony is not supported, skipping.");
+ return;
+ }
+ Bundle extras = new Bundle();
+ extras.putBoolean(TelecomManager.EXTRA_IS_USER_INTENT_EMERGENCY_CALL, true);
+ extras.putInt(EXTRA_CALL_SOURCE, TelecomManager.CALL_SOURCE_EMERGENCY_SHORTCUT);
+ TelecomManager telecomManager = context.getSystemService(TelecomManager.class);
+ EmergencyNumberUtils emergencyNumberUtils = new EmergencyNumberUtils(context);
+ telecomManager.placeCall(
+ Uri.fromParts(PhoneAccount.SCHEME_TEL, emergencyNumberUtils.getPoliceNumber(),
+ /* fragment= */ null), extras);
+ }
+}
diff --git a/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceController.java b/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceController.java
index 43ff215..ab2c473 100644
--- a/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceController.java
+++ b/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceController.java
@@ -49,11 +49,11 @@
final String emergencyGestureSettingsPackageName = context.getResources().getString(
R.string.emergency_gesture_settings_package);
if (!TextUtils.isEmpty(emergencyGestureSettingsPackageName)) {
- mUseCustomIntent = true;
- // Use custom intent if it's configured and system can resolve it.
final Intent intent = new Intent(ACTION_EMERGENCY_GESTURE_SETTINGS)
.setPackage(emergencyGestureSettingsPackageName);
if (canResolveIntent(intent)) {
+ // Use custom intent if it's configured and system can resolve it.
+ mUseCustomIntent = true;
mIntent = intent;
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
index 4415e71..51d74d5 100644
--- a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
@@ -21,10 +21,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.graphics.ColorFilter;
import android.icu.text.NumberFormat;
import android.os.BatteryManager;
import android.os.PowerManager;
import android.text.TextUtils;
+import android.widget.ImageView;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceFragmentCompat;
@@ -60,6 +62,7 @@
private Activity mActivity;
private PreferenceFragmentCompat mHost;
private Lifecycle mLifecycle;
+ private ColorFilter mAccentColorFilter;
private final PowerManager mPowerManager;
public BatteryHeaderPreferenceController(Context context, String key) {
@@ -85,6 +88,9 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mBatteryUsageProgressBarPref = screen.findPreference(getPreferenceKey());
+ mAccentColorFilter = com.android.settings.Utils.getAlphaInvariantColorFilterForColor(
+ com.android.settings.Utils.getColorAttrDefaultColor(
+ mContext, android.R.attr.colorAccent));
if (com.android.settings.Utils.isBatteryPresent(mContext)) {
quickUpdateHeaderPreference();
@@ -116,13 +122,12 @@
}
public void updateHeaderPreference(BatteryInfo info) {
-
- //TODO(b/179237746): Make progress bar widget support battery state icon
-
mBatteryUsageProgressBarPref.setUsageSummary(
formatBatteryPercentageText(info.batteryLevel));
mBatteryUsageProgressBarPref.setTotalSummary(generateLabel(info));
mBatteryUsageProgressBarPref.setPercent(info.batteryLevel, BATTERY_MAX_LEVEL);
+ mBatteryUsageProgressBarPref.setCustomContent(
+ getBatteryIcon(!info.discharging, info.batteryLevel));
}
/**
@@ -139,14 +144,30 @@
final boolean discharging =
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
- //TODO(b/179237746): Make progress bar widget support battery state icon
-
mBatteryUsageProgressBarPref.setUsageSummary(formatBatteryPercentageText(batteryLevel));
mBatteryUsageProgressBarPref.setPercent(batteryLevel, BATTERY_MAX_LEVEL);
+ mBatteryUsageProgressBarPref.setCustomContent(getBatteryIcon(!discharging, batteryLevel));
}
private CharSequence formatBatteryPercentageText(int batteryLevel) {
return TextUtils.expandTemplate(mContext.getText(R.string.battery_header_title_alternate),
NumberFormat.getIntegerInstance().format(batteryLevel));
}
+
+ //TODO(b/179237746): Update the battery icon after receiving final asset
+ private ImageView getBatteryIcon(boolean isCharging, int batteryLevel) {
+ ImageView batteryIcon = new ImageView(mContext);
+
+ if (batteryLevel <= (mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel))) {
+ batteryIcon.setImageResource(R.drawable.ic_battery_low);
+ } else if (isCharging) {
+ batteryIcon.setColorFilter(mAccentColorFilter);
+ batteryIcon.setImageResource(R.drawable.ic_battery_charging_full);
+ } else {
+ batteryIcon = null;
+ }
+
+ return batteryIcon;
+ }
}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index faca9fb..4d3b9cd 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -17,15 +17,16 @@
package com.android.settings.fuelgauge;
import android.content.Context;
+import android.os.BatteryUsageStats;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
-import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.R;
import com.android.settings.widget.UsageView;
@@ -50,11 +51,11 @@
setSelectable(false);
}
- public void setStats(BatteryStatsHelper batteryStats) {
+ void setBatteryUsageStats(@NonNull BatteryUsageStats batteryUsageStats) {
BatteryInfo.getBatteryInfo(getContext(), info -> {
mBatteryInfo = info;
notifyChanged();
- }, batteryStats, false);
+ }, batteryUsageStats, false);
}
public void setBottomSummary(CharSequence text) {
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 5d7b325..a4dd86c 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -20,16 +20,18 @@
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.BatteryManager;
-import android.os.BatteryStats;
import android.os.BatteryStats.HistoryItem;
-import android.os.Bundle;
+import android.os.BatteryStatsManager;
+import android.os.BatteryUsageStats;
import android.os.SystemClock;
import android.text.format.Formatter;
import android.util.SparseIntArray;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
-import com.android.internal.os.BatteryStatsHelper;
+import com.android.internal.os.BatteryStatsHistoryIterator;
import com.android.settings.Utils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.UsageView;
@@ -52,7 +54,7 @@
public String statusLabel;
public String suggestionLabel;
private boolean mCharging;
- private BatteryStats mStats;
+ private BatteryUsageStats mBatteryUsageStats;
private static final String LOG_TAG = "BatteryInfo";
private long timePeriod;
@@ -126,7 +128,7 @@
parserList[i] = parsers[i];
}
parserList[parsers.length] = parser;
- parse(mStats, parserList);
+ parseBatteryHistory(parserList);
String timeString = context.getString(R.string.charge_length_format,
Formatter.formatShortElapsedTime(context, timePeriod));
String remaining = "";
@@ -137,22 +139,25 @@
view.setBottomLabels(new CharSequence[]{timeString, remaining});
}
- public static void getBatteryInfo(final Context context, final Callback callback) {
- BatteryInfo.getBatteryInfo(context, callback, null /* statsHelper */,
- false /* shortString */);
- }
-
public static void getBatteryInfo(final Context context, final Callback callback,
boolean shortString) {
- BatteryInfo.getBatteryInfo(context, callback, null /* statsHelper */, shortString);
+ BatteryInfo.getBatteryInfo(context, callback, /* batteryUsageStats */ null, shortString);
}
public static void getBatteryInfo(final Context context, final Callback callback,
- final BatteryStatsHelper statsHelper, boolean shortString) {
+ @Nullable final BatteryUsageStats batteryUsageStats,
+ boolean shortString) {
new AsyncTask<Void, Void, BatteryInfo>() {
@Override
protected BatteryInfo doInBackground(Void... params) {
- return getBatteryInfo(context, statsHelper, shortString);
+ BatteryUsageStats stats;
+ if (batteryUsageStats != null) {
+ stats = batteryUsageStats;
+ } else {
+ stats = context.getSystemService(BatteryStatsManager.class)
+ .getBatteryUsageStats();
+ }
+ return getBatteryInfo(context, stats, shortString);
}
@Override
@@ -164,18 +169,13 @@
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
+ /**
+ * Creates a BatteryInfo based on BatteryUsageStats
+ */
+ @WorkerThread
public static BatteryInfo getBatteryInfo(final Context context,
- final BatteryStatsHelper statsHelper, boolean shortString) {
- final BatteryStats stats;
+ @NonNull final BatteryUsageStats batteryUsageStats, boolean shortString) {
final long batteryStatsTime = System.currentTimeMillis();
- if (statsHelper == null) {
- final BatteryStatsHelper localStatsHelper = new BatteryStatsHelper(context,
- true);
- localStatsHelper.create((Bundle) null);
- stats = localStatsHelper.getStats();
- } else {
- stats = statsHelper.getStats();
- }
BatteryUtils.logRuntime(LOG_TAG, "time for getStats", batteryStatsTime);
final long startTime = System.currentTimeMillis();
@@ -197,38 +197,38 @@
Estimate.storeCachedEstimate(context, estimate);
BatteryUtils
.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
- return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
+ return BatteryInfo.getBatteryInfo(context, batteryBroadcast, batteryUsageStats,
estimate, elapsedRealtimeUs, shortString);
}
}
- final long prediction = discharging
- ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
+ final long prediction = discharging ? batteryUsageStats.getBatteryTimeRemainingMs() : 0;
final Estimate estimate = new Estimate(
PowerUtil.convertUsToMs(prediction),
false, /* isBasedOnUsage */
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
- return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
+ return BatteryInfo.getBatteryInfo(context, batteryBroadcast, batteryUsageStats,
estimate, elapsedRealtimeUs, shortString);
}
@WorkerThread
public static BatteryInfo getBatteryInfoOld(Context context, Intent batteryBroadcast,
- BatteryStats stats, long elapsedRealtimeUs, boolean shortString) {
+ BatteryUsageStats batteryUsageStats, long elapsedRealtimeUs, boolean shortString) {
Estimate estimate = new Estimate(
- PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
+ batteryUsageStats.getBatteryTimeRemainingMs(),
false,
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
- return getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs,
- shortString);
+ return getBatteryInfo(context, batteryBroadcast, batteryUsageStats, estimate,
+ elapsedRealtimeUs, shortString);
}
@WorkerThread
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
- BatteryStats stats, Estimate estimate, long elapsedRealtimeUs, boolean shortString) {
+ @NonNull BatteryUsageStats batteryUsageStats, Estimate estimate,
+ long elapsedRealtimeUs, boolean shortString) {
final long startTime = System.currentTimeMillis();
BatteryInfo info = new BatteryInfo();
- info.mStats = stats;
+ info.mBatteryUsageStats = batteryUsageStats;
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
@@ -241,16 +241,17 @@
if (!info.mCharging) {
updateBatteryInfoDischarging(context, shortString, estimate, info);
} else {
- updateBatteryInfoCharging(context, batteryBroadcast, stats, elapsedRealtimeUs, info);
+ updateBatteryInfoCharging(context, batteryBroadcast, batteryUsageStats,
+ info);
}
BatteryUtils.logRuntime(LOG_TAG, "time for getBatteryInfo", startTime);
return info;
}
private static void updateBatteryInfoCharging(Context context, Intent batteryBroadcast,
- BatteryStats stats, long elapsedRealtimeUs, BatteryInfo info) {
+ BatteryUsageStats stats, BatteryInfo info) {
final Resources resources = context.getResources();
- final long chargeTime = stats.computeChargeTimeRemaining(elapsedRealtimeUs);
+ final long chargeTimeMs = stats.getChargeTimeRemainingMs();
final int status = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
info.discharging = false;
@@ -260,8 +261,8 @@
int chargingLimitedResId = R.string.power_charging_limited;
info.chargeLabel =
context.getString(chargingLimitedResId, info.batteryPercentString);
- } else if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
- info.remainingTimeUs = chargeTime;
+ } else if (chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
+ info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
CharSequence timeString = StringUtil.formatElapsedTime(context,
PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */);
int resId = R.string.power_charging_duration;
@@ -313,7 +314,11 @@
void onParsingDone();
}
- public static void parse(BatteryStats stats, BatteryDataParser... parsers) {
+ /**
+ * Iterates over battery history included in the BatteryUsageStats that this object
+ * was initialized with.
+ */
+ public void parseBatteryHistory(BatteryDataParser... parsers) {
long startWalltime = 0;
long endWalltime = 0;
long historyStart = 0;
@@ -324,41 +329,41 @@
int lastInteresting = 0;
int pos = 0;
boolean first = true;
- if (stats.startIteratingHistoryLocked()) {
- final HistoryItem rec = new HistoryItem();
- while (stats.getNextHistoryLocked(rec)) {
- pos++;
- if (first) {
- first = false;
- historyStart = rec.time;
+ final BatteryStatsHistoryIterator iterator1 =
+ mBatteryUsageStats.iterateBatteryStatsHistory();
+ final HistoryItem rec = new HistoryItem();
+ while (iterator1.next(rec)) {
+ pos++;
+ if (first) {
+ first = false;
+ historyStart = rec.time;
+ }
+ if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
+ || rec.cmd == HistoryItem.CMD_RESET) {
+ // If there is a ridiculously large jump in time, then we won't be
+ // able to create a good chart with that data, so just ignore the
+ // times we got before and pretend like our data extends back from
+ // the time we have now.
+ // Also, if we are getting a time change and we are less than 5 minutes
+ // since the start of the history real time, then also use this new
+ // time to compute the base time, since whatever time we had before is
+ // pretty much just noise.
+ if (rec.currentTime > (lastWallTime + (180 * 24 * 60 * 60 * 1000L))
+ || rec.time < (historyStart + (5 * 60 * 1000L))) {
+ startWalltime = 0;
}
- if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
- || rec.cmd == HistoryItem.CMD_RESET) {
- // If there is a ridiculously large jump in time, then we won't be
- // able to create a good chart with that data, so just ignore the
- // times we got before and pretend like our data extends back from
- // the time we have now.
- // Also, if we are getting a time change and we are less than 5 minutes
- // since the start of the history real time, then also use this new
- // time to compute the base time, since whatever time we had before is
- // pretty much just noise.
- if (rec.currentTime > (lastWallTime + (180 * 24 * 60 * 60 * 1000L))
- || rec.time < (historyStart + (5 * 60 * 1000L))) {
- startWalltime = 0;
- }
- lastWallTime = rec.currentTime;
- lastRealtime = rec.time;
- if (startWalltime == 0) {
- startWalltime = lastWallTime - (lastRealtime - historyStart);
- }
- }
- if (rec.isDeltaData()) {
- lastInteresting = pos;
- historyEnd = rec.time;
+ lastWallTime = rec.currentTime;
+ lastRealtime = rec.time;
+ if (startWalltime == 0) {
+ startWalltime = lastWallTime - (lastRealtime - historyStart);
}
}
+ if (rec.isDeltaData()) {
+ lastInteresting = pos;
+ historyEnd = rec.time;
+ }
}
- stats.finishIteratingHistoryLocked();
+
endWalltime = lastWallTime + historyEnd - lastRealtime;
int i = 0;
@@ -367,9 +372,11 @@
for (int j = 0; j < parsers.length; j++) {
parsers[j].onParsingStarted(startWalltime, endWalltime);
}
- if (endWalltime > startWalltime && stats.startIteratingHistoryLocked()) {
- final HistoryItem rec = new HistoryItem();
- while (stats.getNextHistoryLocked(rec) && i < N) {
+
+ if (endWalltime > startWalltime) {
+ final BatteryStatsHistoryIterator iterator2 =
+ mBatteryUsageStats.iterateBatteryStatsHistory();
+ while (iterator2.next(rec) && i < N) {
if (rec.isDeltaData()) {
curWalltime += rec.time - lastRealtime;
lastRealtime = rec.time;
@@ -404,8 +411,6 @@
}
}
- stats.finishIteratingHistoryLocked();
-
for (int j = 0; j < parsers.length; j++) {
parsers[j].onParsingDone();
}
diff --git a/src/com/android/settings/fuelgauge/BatteryInfoLoader.java b/src/com/android/settings/fuelgauge/BatteryInfoLoader.java
index cd87612..ffee462 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfoLoader.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfoLoader.java
@@ -19,7 +19,6 @@
import androidx.annotation.VisibleForTesting;
-import com.android.internal.os.BatteryStatsHelper;
import com.android.settingslib.utils.AsyncLoaderCompat;
/**
@@ -28,17 +27,14 @@
* when not available.
*/
public class BatteryInfoLoader extends AsyncLoaderCompat<BatteryInfo>{
-
- BatteryStatsHelper mStatsHelper;
private static final String LOG_TAG = "BatteryInfoLoader";
@VisibleForTesting
- BatteryUtils batteryUtils;
+ BatteryUtils mBatteryUtils;
- public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
+ public BatteryInfoLoader(Context context) {
super(context);
- mStatsHelper = batteryStatsHelper;
- batteryUtils = BatteryUtils.getInstance(context);
+ mBatteryUtils = BatteryUtils.getInstance(context);
}
@Override
@@ -48,6 +44,6 @@
@Override
public BatteryInfo loadInBackground() {
- return batteryUtils.getBatteryInfo(mStatsHelper, LOG_TAG);
+ return mBatteryUtils.getBatteryInfo(LOG_TAG);
}
}
diff --git a/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java b/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java
index 5b184a9..d35ef82 100644
--- a/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java
+++ b/src/com/android/settings/fuelgauge/BatteryUsageStatsLoader.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.os.BatteryStatsManager;
import android.os.BatteryUsageStats;
+import android.os.BatteryUsageStatsQuery;
import com.android.settingslib.utils.AsyncLoaderCompat;
@@ -27,15 +28,21 @@
*/
public class BatteryUsageStatsLoader extends AsyncLoaderCompat<BatteryUsageStats> {
private final BatteryStatsManager mBatteryStatsManager;
+ private final boolean mIncludeBatteryHistory;
- public BatteryUsageStatsLoader(Context context) {
+ public BatteryUsageStatsLoader(Context context, boolean includeBatteryHistory) {
super(context);
mBatteryStatsManager = context.getSystemService(BatteryStatsManager.class);
+ mIncludeBatteryHistory = includeBatteryHistory;
}
@Override
public BatteryUsageStats loadInBackground() {
- return mBatteryStatsManager.getBatteryUsageStats();
+ final BatteryUsageStatsQuery.Builder builder = new BatteryUsageStatsQuery.Builder();
+ if (mIncludeBatteryHistory) {
+ builder.includeBatteryHistory();
+ }
+ return mBatteryStatsManager.getBatteryUsageStats(builder.build());
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index 5b1f096..8c0ab46 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -24,6 +24,9 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
+import android.os.BatteryStatsManager;
+import android.os.BatteryUsageStats;
+import android.os.BatteryUsageStatsQuery;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
@@ -103,7 +106,7 @@
}
@VisibleForTesting
- BatteryUtils(Context context) {
+ public BatteryUtils(Context context) {
mContext = context;
mPackageManager = context.getPackageManager();
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
@@ -472,29 +475,35 @@
}
@WorkerThread
- public BatteryInfo getBatteryInfo(final BatteryStatsHelper statsHelper, final String tag) {
+ public BatteryInfo getBatteryInfo(final String tag) {
+ final BatteryStatsManager systemService = mContext.getSystemService(
+ BatteryStatsManager.class);
+ final BatteryUsageStats batteryUsageStats = systemService.getBatteryUsageStats(
+ new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
+
final long startTime = System.currentTimeMillis();
// Stuff we always need to get BatteryInfo
final Intent batteryBroadcast = mContext.registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+
final long elapsedRealtimeUs = PowerUtil.convertMsToUs(
SystemClock.elapsedRealtime());
- final BatteryStats stats = statsHelper.getStats();
+
BatteryInfo batteryInfo;
Estimate estimate = getEnhancedEstimate();
// couldn't get estimate from cache or provider, use fallback
if (estimate == null) {
estimate = new Estimate(
- PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
+ PowerUtil.convertUsToMs(batteryUsageStats.getBatteryTimeRemainingMs()),
false /* isBasedOnUsage */,
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
- batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
- estimate, elapsedRealtimeUs, false /* shortString */);
+ batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast,
+ batteryUsageStats, estimate, elapsedRealtimeUs, false /* shortString */);
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
return batteryInfo;
diff --git a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
index c8dbb59..0623bcb 100644
--- a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
+++ b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
@@ -19,6 +19,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryStats;
+import android.os.BatteryStatsManager;
+import android.os.BatteryUsageStats;
import android.os.SystemClock;
import com.android.internal.os.BatteryStatsHelper;
@@ -56,15 +58,17 @@
Intent batteryBroadcast = getContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
BatteryStats stats = mStatsHelper.getStats();
-
+ BatteryUsageStats batteryUsageStats =
+ context.getSystemService(BatteryStatsManager.class).getBatteryUsageStats();
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
- stats, elapsedRealtimeUs, false);
+ batteryUsageStats, elapsedRealtimeUs, false);
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
if (estimate == null) {
estimate = new Estimate(0, false, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
- BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
+ BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast,
+ batteryUsageStats,
estimate, elapsedRealtimeUs, false);
List<BatteryInfo> infos = new ArrayList<>();
diff --git a/src/com/android/settings/fuelgauge/FakeUid.java b/src/com/android/settings/fuelgauge/FakeUid.java
index e1fc7f4..4bb98ed 100644
--- a/src/com/android/settings/fuelgauge/FakeUid.java
+++ b/src/com/android/settings/fuelgauge/FakeUid.java
@@ -361,6 +361,11 @@
}
@Override
+ public long getCpuMeasuredBatteryConsumptionUC() {
+ return 0;
+ }
+
+ @Override
public long[] getCustomConsumerMeasuredBatteryConsumptionUC() {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
index befede4..86e52d9 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAdvanced.java
@@ -142,6 +142,11 @@
}
@Override
+ protected boolean isBatteryHistoryNeeded() {
+ return true;
+ }
+
+ @Override
protected void refreshUi(@BatteryUpdateType int refreshType) {
final Context context = getContext();
if (context == null) {
diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java
index 3a5ed6c..29ecedc 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageBase.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java
@@ -19,10 +19,12 @@
import android.app.Activity;
import android.content.Context;
+import android.os.BatteryUsageStats;
import android.os.Bundle;
import android.os.UserManager;
import android.view.Menu;
+import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
@@ -40,12 +42,29 @@
static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
private static final String TAG = "PowerUsageBase";
private static final String KEY_REFRESH_TYPE = "refresh_type";
+ private static final String KEY_INCLUDE_HISTORY = "include_history";
+
+ private static final int LOADER_BATTERY_STATS_HELPER = 0;
+ private static final int LOADER_BATTERY_USAGE_STATS = 1;
protected BatteryStatsHelper mStatsHelper;
+ @VisibleForTesting
+ BatteryUsageStats mBatteryUsageStats;
+
protected UserManager mUm;
private BatteryBroadcastReceiver mBatteryBroadcastReceiver;
protected boolean mIsBatteryPresent = true;
+ // TODO(b/180630447): switch to BatteryUsageStatsLoader and remove all references to
+ // BatteryStatsHelper and BatterySipper
+ @VisibleForTesting
+ final BatteryStatsHelperLoaderCallbacks mBatteryStatsHelperLoaderCallbacks =
+ new BatteryStatsHelperLoaderCallbacks();
+
+ @VisibleForTesting
+ final BatteryUsageStatsLoaderCallbacks mBatteryUsageStatsLoaderCallbacks =
+ new BatteryUsageStatsLoaderCallbacks();
+
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@@ -83,42 +102,73 @@
protected void restartBatteryStatsLoader(int refreshType) {
final Bundle bundle = new Bundle();
bundle.putInt(KEY_REFRESH_TYPE, refreshType);
+ bundle.putBoolean(KEY_INCLUDE_HISTORY, isBatteryHistoryNeeded());
+ getLoaderManager().restartLoader(LOADER_BATTERY_STATS_HELPER, bundle,
+ mBatteryStatsHelperLoaderCallbacks);
+ getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
+ mBatteryUsageStatsLoaderCallbacks);
+ }
- getLoaderManager().restartLoader(0, bundle, new PowerLoaderCallback());
+ private void onLoadFinished(@BatteryUpdateType int refreshType) {
+ // Wait for both loaders to finish before proceeding.
+ if (mStatsHelper == null || mBatteryUsageStats == null) {
+ return;
+ }
+
+ refreshUi(refreshType);
}
protected abstract void refreshUi(@BatteryUpdateType int refreshType);
+ protected abstract boolean isBatteryHistoryNeeded();
protected void updatePreference(BatteryHistoryPreference historyPref) {
final long startTime = System.currentTimeMillis();
- historyPref.setStats(mStatsHelper);
+ historyPref.setBatteryUsageStats(mBatteryUsageStats);
BatteryUtils.logRuntime(TAG, "updatePreference", startTime);
}
- /**
- * {@link android.app.LoaderManager.LoaderCallbacks} for {@link PowerUsageBase} to load
- * the {@link BatteryStatsHelper}
- */
- public class PowerLoaderCallback implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
+ private class BatteryStatsHelperLoaderCallbacks
+ implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> {
private int mRefreshType;
@Override
- public Loader<BatteryStatsHelper> onCreateLoader(int id,
- Bundle args) {
+ public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) {
mRefreshType = args.getInt(KEY_REFRESH_TYPE);
return new BatteryStatsHelperLoader(getContext());
}
@Override
public void onLoadFinished(Loader<BatteryStatsHelper> loader,
- BatteryStatsHelper statsHelper) {
- mStatsHelper = statsHelper;
- refreshUi(mRefreshType);
+ BatteryStatsHelper batteryHelper) {
+ mStatsHelper = batteryHelper;
+ PowerUsageBase.this.onLoadFinished(mRefreshType);
}
@Override
public void onLoaderReset(Loader<BatteryStatsHelper> loader) {
+ }
+ }
+ private class BatteryUsageStatsLoaderCallbacks
+ implements LoaderManager.LoaderCallbacks<BatteryUsageStats> {
+ private int mRefreshType;
+
+ @Override
+ @NonNull
+ public Loader<BatteryUsageStats> onCreateLoader(int id, Bundle args) {
+ mRefreshType = args.getInt(KEY_REFRESH_TYPE);
+ return new BatteryUsageStatsLoader(getContext(), args.getBoolean(KEY_INCLUDE_HISTORY));
+ }
+
+ @Override
+ public void onLoadFinished(Loader<BatteryUsageStats> loader,
+ BatteryUsageStats batteryUsageStats) {
+ mBatteryUsageStats = batteryUsageStats;
+ PowerUsageBase.this.onLoadFinished(mRefreshType);
+ }
+
+ @Override
+ public void onLoaderReset(Loader<BatteryUsageStats> loader) {
}
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index c00c131..4f8ac62 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -88,7 +88,7 @@
@Override
public Loader<BatteryInfo> onCreateLoader(int i, Bundle bundle) {
- return new BatteryInfoLoader(getContext(), mStatsHelper);
+ return new BatteryInfoLoader(getContext());
}
@Override
@@ -190,6 +190,11 @@
return R.string.help_url_battery;
}
+ @Override
+ protected boolean isBatteryHistoryNeeded() {
+ return false;
+ }
+
protected void refreshUi(@BatteryUpdateType int refreshType) {
final Context context = getContext();
if (context == null) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index 0c916b2..9b80a1f 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -65,12 +65,11 @@
}
final List<BatteryTip> tips = new ArrayList<>();
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
- final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
+ final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(TAG);
final Context context = getContext();
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
- tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper,
- batteryInfo.discharging).detect());
+ tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper, batteryInfo).detect());
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new BatteryDefenderDetector(batteryInfo).detect());
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
index 067046c..928ae52 100644
--- a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
@@ -45,6 +45,7 @@
public class HighUsageDetector implements BatteryTipDetector {
private BatteryTipPolicy mPolicy;
private BatteryStatsHelper mBatteryStatsHelper;
+ private final BatteryInfo mBatteryInfo;
private List<AppInfo> mHighUsageAppList;
@VisibleForTesting
HighUsageDataParser mDataParser;
@@ -54,14 +55,15 @@
boolean mDischarging;
public HighUsageDetector(Context context, BatteryTipPolicy policy,
- BatteryStatsHelper batteryStatsHelper, boolean discharging) {
+ BatteryStatsHelper batteryStatsHelper, BatteryInfo batteryInfo) {
mPolicy = policy;
mBatteryStatsHelper = batteryStatsHelper;
+ mBatteryInfo = batteryInfo;
mHighUsageAppList = new ArrayList<>();
mBatteryUtils = BatteryUtils.getInstance(context);
mDataParser = new HighUsageDataParser(mPolicy.highUsagePeriodMs,
mPolicy.highUsageBatteryDraining);
- mDischarging = discharging;
+ mDischarging = batteryInfo.discharging;
}
@Override
@@ -115,6 +117,6 @@
@VisibleForTesting
void parseBatteryData() {
- BatteryInfo.parse(mBatteryStatsHelper.getStats(), mDataParser);
+ mBatteryInfo.parseBatteryHistory(mDataParser);
}
}
diff --git a/src/com/android/settings/inputmethod/OWNERS b/src/com/android/settings/inputmethod/OWNERS
index 9f33394..556de5f 100644
--- a/src/com/android/settings/inputmethod/OWNERS
+++ b/src/com/android/settings/inputmethod/OWNERS
@@ -1,5 +1,7 @@
-# Default reviewers for this and subdirectories.
-yukawa@google.com
-michaelwr@google.com
+# Bug component: 34867
+include platform/frameworks/base:/services/core/java/com/android/server/inputmethod/OWNERS
-# Emergency approvers in case the above are not available
\ No newline at end of file
+# Settings for physical keyboard and game pad are better to be reviewed by the input team
+per-file GameControllerPreferenceController.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS
+per-file KeyboardLayoutPicker*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS
+per-file PhysicalKeyboard*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS
diff --git a/src/com/android/settings/location/BluetoothScanningFragment.java b/src/com/android/settings/location/BluetoothScanningFragment.java
new file mode 100644
index 0000000..553f975
--- /dev/null
+++ b/src/com/android/settings/location/BluetoothScanningFragment.java
@@ -0,0 +1,81 @@
+/*
+ * 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.location;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A page that configures the Bluetooth scanning setting.
+ */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class BluetoothScanningFragment extends DashboardFragment {
+ private static final String TAG = "BluetoothScanningFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION_SERVICES;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_services_bluetooth_scanning;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new BluetoothScanningPreferenceController(context));
+ return controllers;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.location_services_bluetooth_scanning) {
+
+ @Override
+ public List<AbstractPreferenceController> createPreferenceControllers(Context
+ context) {
+ return buildPreferenceControllers(context);
+ }
+ };
+}
diff --git a/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
new file mode 100644
index 0000000..051fd8d
--- /dev/null
+++ b/src/com/android/settings/location/BluetoothScanningMainSwitchPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 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.location;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.widget.Switch;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
+/**
+ * Preference controller for Bluetooth scanning main switch.
+ */
+public class BluetoothScanningMainSwitchPreferenceController extends TogglePreferenceController
+ implements OnMainSwitchChangeListener {
+
+ private static final String KEY_BLUETOOTH_SCANNING_SWITCH = "bluetooth_always_scanning_switch";
+
+ public BluetoothScanningMainSwitchPreferenceController(Context context) {
+ super(context, KEY_BLUETOOTH_SCANNING_SWITCH);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ MainSwitchPreference pref = screen.findPreference(getPreferenceKey());
+ pref.addOnSwitchChangeListener(this);
+ pref.updateStatus(isChecked());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, isChecked ? 1 : 0);
+ // Returning true means the underlying setting is updated.
+ return true;
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != isChecked()) {
+ setChecked(isChecked);
+ }
+ }
+}
diff --git a/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java b/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java
new file mode 100644
index 0000000..9913848
--- /dev/null
+++ b/src/com/android/settings/location/LocationServicesBluetoothScanningPreferenceController.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 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.location;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for Bluetooth scanning in Location Services.
+ */
+public class LocationServicesBluetoothScanningPreferenceController extends
+ BasePreferenceController {
+
+ public LocationServicesBluetoothScanningPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
+ int resId =
+ bleScanOn ? R.string.scanning_status_text_on : R.string.scanning_status_text_off;
+ return mContext.getString(resId);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java b/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java
new file mode 100644
index 0000000..080a023
--- /dev/null
+++ b/src/com/android/settings/location/LocationServicesWifiScanningPreferenceController.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 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.location;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for Wi-Fi scanning in Location Services.
+ */
+public class LocationServicesWifiScanningPreferenceController extends BasePreferenceController {
+
+ private final WifiManager mWifiManager;
+
+ public LocationServicesWifiScanningPreferenceController(Context context, String key) {
+ super(context, key);
+ mWifiManager = context.getSystemService(WifiManager.class);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ final boolean wifiScanOn = mWifiManager.isScanAlwaysAvailable();
+ int resId =
+ wifiScanOn ? R.string.scanning_status_text_on : R.string.scanning_status_text_off;
+ return mContext.getString(resId);
+ }
+
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+}
diff --git a/src/com/android/settings/location/WifiScanningFragment.java b/src/com/android/settings/location/WifiScanningFragment.java
new file mode 100644
index 0000000..f5cb0ae
--- /dev/null
+++ b/src/com/android/settings/location/WifiScanningFragment.java
@@ -0,0 +1,81 @@
+/*
+ * 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.location;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A page that configures the Wi-Fi scanning setting.
+ */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class WifiScanningFragment extends DashboardFragment {
+ private static final String TAG = "WifiScanningFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION_SERVICES;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_services_wifi_scanning;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new WifiScanningPreferenceController(context));
+ return controllers;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.location_services_wifi_scanning) {
+
+ @Override
+ public List<AbstractPreferenceController> createPreferenceControllers(Context
+ context) {
+ return buildPreferenceControllers(context);
+ }
+ };
+}
diff --git a/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
new file mode 100644
index 0000000..a69fdb8
--- /dev/null
+++ b/src/com/android/settings/location/WifiScanningMainSwitchPreferenceController.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 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.location;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.widget.Switch;
+
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.widget.MainSwitchPreference;
+import com.android.settingslib.widget.OnMainSwitchChangeListener;
+
+/**
+ * Preference controller for Wi-Fi scanning main switch.
+ */
+public class WifiScanningMainSwitchPreferenceController extends TogglePreferenceController
+ implements OnMainSwitchChangeListener {
+
+ private static final String KEY_WIFI_SCANNING_SWITCH = "wifi_always_scanning_switch";
+ private final WifiManager mWifiManager;
+
+ public WifiScanningMainSwitchPreferenceController(Context context) {
+ super(context, KEY_WIFI_SCANNING_SWITCH);
+ mWifiManager = context.getSystemService(WifiManager.class);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ MainSwitchPreference pref = screen.findPreference(getPreferenceKey());
+ pref.addOnSwitchChangeListener(this);
+ pref.updateStatus(isChecked());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_location_scanning)
+ ? AVAILABLE
+ : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mWifiManager.isScanAlwaysAvailable();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ mWifiManager.setScanAlwaysAvailable(isChecked);
+ // Returning true means the underlying setting is updated.
+ return true;
+ }
+
+ @Override
+ public void onSwitchChanged(Switch switchView, boolean isChecked) {
+ if (isChecked != isChecked()) {
+ setChecked(isChecked);
+ }
+ }
+}
diff --git a/src/com/android/settings/network/AllowedNetworkTypesListener.java b/src/com/android/settings/network/AllowedNetworkTypesListener.java
index a9ed8be..ecc1d9c 100644
--- a/src/com/android/settings/network/AllowedNetworkTypesListener.java
+++ b/src/com/android/settings/network/AllowedNetworkTypesListener.java
@@ -24,7 +24,6 @@
import androidx.annotation.VisibleForTesting;
-import java.util.Map;
import java.util.concurrent.Executor;
@@ -72,9 +71,10 @@
}
@Override
- public void onAllowedNetworkTypesChanged(Map<Integer, Long> allowedNetworkTypesList) {
- long newAllowedNetworkType = allowedNetworkTypesList.get(
- TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER);
+ public void onAllowedNetworkTypesChanged(int reason, long newAllowedNetworkType) {
+ if (reason != TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER) {
+ return;
+ }
if (mListener != null && mAllowedNetworkType != newAllowedNetworkType) {
mListener.onAllowedNetworkTypesChanged();
Log.d(LOG_TAG, "onAllowedNetworkChanged: " + mAllowedNetworkType);
diff --git a/src/com/android/settings/network/InternetPreferenceController.java b/src/com/android/settings/network/InternetPreferenceController.java
index 2fe9c0a..f64ed30 100644
--- a/src/com/android/settings/network/InternetPreferenceController.java
+++ b/src/com/android/settings/network/InternetPreferenceController.java
@@ -124,12 +124,6 @@
return;
}
- if (mInternetType == INTERNET_NETWORKS_AVAILABLE
- && mInternetUpdater.isApmNetworksAvailable()) {
- mPreference.setSummary(R.string.airplane_mode_network_available);
- return;
- }
-
final @IdRes int summary = sSummaryMap.get(mInternetType);
if (summary != 0) {
mPreference.setSummary(summary);
diff --git a/src/com/android/settings/network/InternetUpdater.java b/src/com/android/settings/network/InternetUpdater.java
index 3bd1e7b..2f704e7 100644
--- a/src/com/android/settings/network/InternetUpdater.java
+++ b/src/com/android/settings/network/InternetUpdater.java
@@ -73,9 +73,9 @@
default void onAirplaneModeChanged(boolean isAirplaneModeOn) {};
/**
- * Called when airplane mode networks state is changed.
+ * Called when Wi-Fi enabled is changed.
*/
- default void onAirplaneModeNetworksChanged(boolean available) {};
+ default void onWifiEnabledChanged(boolean enabled) {};
}
/**
@@ -157,9 +157,8 @@
@Override
public void onReceive(Context context, Intent intent) {
fetchActiveNetwork();
- if (mListener != null && mAirplaneModeEnabler.isAirplaneModeOn()) {
- mListener.onAirplaneModeNetworksChanged(
- mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED);
+ if (mListener != null) {
+ mListener.onWifiEnabledChanged(mWifiManager.isWifiEnabled());
}
}
};
@@ -272,10 +271,9 @@
}
/**
- * Return ture when the APM networks is available.
+ * Return ture when the Wi-Fi is enabled.
*/
- public boolean isApmNetworksAvailable() {
- return mAirplaneModeEnabler.isAirplaneModeOn()
- && (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED);
+ public boolean isWifiEnabled() {
+ return mWifiManager.isWifiEnabled();
}
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 4d6849b..803b981 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -55,6 +55,7 @@
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
+import com.android.settings.AirplaneModeEnabler;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.core.FeatureFlags;
@@ -98,7 +99,8 @@
public class NetworkProviderSettings extends RestrictedSettingsFragment
implements Indexable, WifiPickerTracker.WifiPickerTrackerCallback,
WifiDialog2.WifiDialog2Listener, DialogInterface.OnDismissListener,
- ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback {
+ ConnectivitySubsystemsRecoveryManager.RecoveryStatusCallback,
+ AirplaneModeEnabler.OnAirplaneModeChangedListener {
public static final String ACTION_NETWORK_PROVIDER_SETTINGS =
"android.settings.NETWORK_PROVIDER_SETTINGS";
@@ -118,6 +120,7 @@
static final int CONFIG_NETWORK_REQUEST = 3;
static final int MANAGE_SUBSCRIPTION = 4;
+ private static final String PREF_KEY_AIRPLANE_MODE_MSG = "airplane_mode_message";
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
// TODO(b/70983952): Rename these to use WifiEntry instead of AccessPoint.
private static final String PREF_KEY_CONNECTED_ACCESS_POINTS = "connected_access_point";
@@ -185,6 +188,8 @@
private boolean mIsRestricted;
@VisibleForTesting
+ AirplaneModeEnabler mAirplaneModeEnabler;
+ @VisibleForTesting
WifiPickerTracker mWifiPickerTracker;
private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
@@ -204,8 +209,7 @@
@VisibleForTesting
DataUsagePreference mDataUsagePreference;
@VisibleForTesting
- ViewAirplaneModeNetworksLayoutPreferenceController
- mViewAirplaneModeNetworksButtonPreference;
+ Preference mAirplaneModeMsgPreference;
@VisibleForTesting
LayoutPreference mResetInternetPreference;
@VisibleForTesting
@@ -241,6 +245,7 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ mAirplaneModeEnabler = new AirplaneModeEnabler(getContext(), this);
// TODO(b/37429702): Add animations and preference comparator back after initial screen is
// loaded (ODR).
@@ -254,6 +259,8 @@
private void addPreferences() {
addPreferencesFromResource(R.xml.network_provider_settings);
+ mAirplaneModeMsgPreference = findPreference(PREF_KEY_AIRPLANE_MODE_MSG);
+ updateAirplaneModeMsgPreference(mAirplaneModeEnabler.isAirplaneModeOn() /* visible */);
mConnectedWifiEntryPreferenceCategory = findPreference(PREF_KEY_CONNECTED_ACCESS_POINTS);
mWifiEntryPreferenceCategory = findPreference(PREF_KEY_ACCESS_POINTS);
mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
@@ -269,11 +276,16 @@
mResetInternetPreference.setVisible(false);
}
addNetworkMobileProviderController();
- addViewAirplaneModeNetworksButtonController();
addConnectedEthernetNetworkController();
addWifiSwitchPreferenceController();
}
+ private void updateAirplaneModeMsgPreference(boolean visible) {
+ if (mAirplaneModeMsgPreference != null) {
+ mAirplaneModeMsgPreference.setVisible(visible);
+ }
+ }
+
private void addNetworkMobileProviderController() {
if (mNetworkMobileProviderController == null) {
mNetworkMobileProviderController = new NetworkMobileProviderController(
@@ -283,15 +295,6 @@
mNetworkMobileProviderController.displayPreference(getPreferenceScreen());
}
- private void addViewAirplaneModeNetworksButtonController() {
- if (mViewAirplaneModeNetworksButtonPreference == null) {
- mViewAirplaneModeNetworksButtonPreference =
- new ViewAirplaneModeNetworksLayoutPreferenceController(
- getContext(), getSettingsLifecycle());
- }
- mViewAirplaneModeNetworksButtonPreference.displayPreference(getPreferenceScreen());
- }
-
private void addConnectedEthernetNetworkController() {
if (mConnectedEthernetNetworkController == null) {
mConnectedEthernetNetworkController =
@@ -386,10 +389,11 @@
@Override
public void onStart() {
super.onStart();
-
if (mIsRestricted) {
restrictUi();
+ return;
}
+ mAirplaneModeEnabler.start();
}
private void restrictUi() {
@@ -419,6 +423,7 @@
public void onStop() {
getView().removeCallbacks(mUpdateWifiEntryPreferencesRunnable);
getView().removeCallbacks(mHideProgressBarRunnable);
+ mAirplaneModeEnabler.stop();
super.onStop();
}
@@ -1188,9 +1193,7 @@
if (mResetInternetPreference != null) {
mResetInternetPreference.setVisible(true);
}
- if (mViewAirplaneModeNetworksButtonPreference != null) {
- mViewAirplaneModeNetworksButtonPreference.setVisible(false);
- }
+ updateAirplaneModeMsgPreference(false /* visible */);
}
/**
@@ -1200,9 +1203,18 @@
if (mResetInternetPreference != null) {
mResetInternetPreference.setVisible(false);
}
- if (mViewAirplaneModeNetworksButtonPreference != null
- && mViewAirplaneModeNetworksButtonPreference.isAvailable()) {
- mViewAirplaneModeNetworksButtonPreference.setVisible(true);
+ if (mAirplaneModeEnabler.isAirplaneModeOn()) {
+ updateAirplaneModeMsgPreference(true /* visible */);
}
}
+
+ /**
+ * Called when airplane mode status is changed.
+ *
+ * @param isAirplaneModeOn The airplane mode is on
+ */
+ @Override
+ public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
+ updateAirplaneModeMsgPreference(isAirplaneModeOn /* visible */);
+ }
}
diff --git a/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceController.java b/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceController.java
deleted file mode 100644
index 923e773..0000000
--- a/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceController.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.network;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.wifi.WifiManager;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.AirplaneModeEnabler;
-import com.android.settings.R;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.widget.LayoutPreference;
-
-/**
- * This controls the airplane mode message and click button of the "View airplane mode networks"
- * item on the Network & internet page.
- */
-public class ViewAirplaneModeNetworksLayoutPreferenceController extends AbstractPreferenceController
- implements LifecycleObserver, AirplaneModeEnabler.OnAirplaneModeChangedListener,
- View.OnClickListener {
-
- public static final String KEY = "view_airplane_mode_netwokrs_button";
-
- private LayoutPreference mPreference;
- @VisibleForTesting
- TextView mTextView;
- @VisibleForTesting
- Button mButton;
-
- private AirplaneModeEnabler mAirplaneModeEnabler;
- private final WifiManager mWifiManager;
- private final IntentFilter mIntentFilter;
- private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
- refreshLayout();
- }
- }
- };
-
- public ViewAirplaneModeNetworksLayoutPreferenceController(Context context,
- Lifecycle lifecycle) {
- super(context);
- if (lifecycle == null) {
- throw new IllegalArgumentException("Lifecycle must be set");
- }
- mAirplaneModeEnabler = new AirplaneModeEnabler(context, this);
- mWifiManager = context.getSystemService(WifiManager.class);
- mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
- lifecycle.addObserver(this);
- }
-
- @Override
- public boolean isAvailable() {
- return mAirplaneModeEnabler.isAirplaneModeOn();
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(getPreferenceKey());
- generateLayout();
- }
-
- /** Lifecycle.Event.ON_START */
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- public void onStart() {
- mAirplaneModeEnabler.start();
- }
-
- /** Lifecycle.Event.ON_STOP */
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- public void onStop() {
- mAirplaneModeEnabler.stop();
- }
-
- /** Lifecycle.Event.ON_RESUME */
- @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
- public void onResume() {
- mContext.registerReceiver(mBroadcastReceiver, mIntentFilter);
- }
-
- /** Lifecycle.Event.ON_PAUSE */
- @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
- public void onPause() {
- mContext.unregisterReceiver(mBroadcastReceiver);
- }
-
- @Override
- public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
- if (mPreference != null) {
- mPreference.setVisible(isAirplaneModeOn);
- }
- }
-
- @Override
- public void onClick(View v) {
- mWifiManager.setWifiEnabled(true);
- }
-
- private void generateLayout() {
- if (mPreference == null) {
- return;
- }
- if (mTextView == null) {
- mTextView = mPreference.findViewById(R.id.airplane_mode_text);
- }
- if (mButton == null) {
- mButton = mPreference.findViewById(R.id.view_airplane_mode_networks_button);
- }
- if (mButton != null) {
- mButton.setOnClickListener(this);
- }
- refreshLayout();
- }
-
- @VisibleForTesting
- void refreshLayout() {
- boolean isWifiEnabled = mWifiManager.isWifiEnabled();
- if (mTextView != null) {
- mTextView.setText(isWifiEnabled ? R.string.viewing_airplane_mode_networks
- : R.string.condition_airplane_title);
- }
- if (mButton != null) {
- mButton.setVisibility(isWifiEnabled ? View.GONE : View.VISIBLE);
- }
- }
-
- /**
- * Sets the visibility of the preference.
- */
- public void setVisible(boolean visible) {
- if (mPreference != null) {
- mPreference.setVisible(visible);
- }
- }
-}
diff --git a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
index 8d037fb..d00efc7 100644
--- a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
@@ -106,7 +106,7 @@
return false;
}
try {
- return imsMmTelMgr.isCrossSimCallingEnabledByUser();
+ return imsMmTelMgr.isCrossSimCallingEnabled();
} catch (ImsException exception) {
Log.w(LOG_TAG, "fail to get cross SIM calling configuration", exception);
}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java b/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
index 44fd029..c16dbc9 100644
--- a/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
+++ b/src/com/android/settings/network/telephony/NetworkProviderWifiCallingGroup.java
@@ -217,7 +217,12 @@
pref.setEnabled(getTelephonyManagerForSubscriptionId(subId).getCallState()
== TelephonyManager.CALL_STATE_IDLE);
pref.setOrder(order++);
- pref.setSummary(R.string.calls_sms_wfc_summary);
+
+ int resId = com.android.internal.R.string.wifi_calling_off_summary;
+ if (queryImsState(subId).isEnabledByUser()) {
+ resId = R.string.calls_sms_wfc_summary;
+ }
+ pref.setSummary(resId);
mWifiCallingForSubPreferences.put(subId, pref);
}
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 0f3695a..dcba273 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -127,20 +127,23 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- final PreferenceScreen screen = getPreferenceScreen();
- final Bundle arguments = getArguments();
+ // TODO(b/182237530): This method should be removed when this flag is deprecated.
+ if (!FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
+ final PreferenceScreen screen = getPreferenceScreen();
+ final Bundle arguments = getArguments();
- if (screen == null) {
- return;
- }
- if (arguments != null) {
- final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
- if (!TextUtils.isEmpty(highlightKey)) {
- final PreferenceCategory advancedCategory =
- screen.findPreference(KEY_ADVANCED_CATEGORY);
- // Has highlight row - expand everything
- advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- scrollToPreference(advancedCategory);
+ if (screen == null) {
+ return;
+ }
+ if (arguments != null) {
+ final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
+ if (!TextUtils.isEmpty(highlightKey)) {
+ final PreferenceCategory advancedCategory =
+ screen.findPreference(KEY_ADVANCED_CATEGORY);
+ // Has highlight row - expand everything
+ advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
+ scrollToPreference(advancedCategory);
+ }
}
}
}
diff --git a/src/com/android/settings/notification/app/ChannelNotificationSettings.java b/src/com/android/settings/notification/app/ChannelNotificationSettings.java
index bdea30d..296863c 100644
--- a/src/com/android/settings/notification/app/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/app/ChannelNotificationSettings.java
@@ -68,12 +68,16 @@
if (mChannel != null && !TextUtils.isEmpty(mChannel.getConversationId())
&& !mChannel.isDemoted()) {
- startActivity(new SubSettingLauncher(mContext)
+ Intent intent = new SubSettingLauncher(mContext)
.setDestination(ConversationNotificationSettings.class.getName())
.setArguments(getArguments())
.setExtras(getIntent() != null ? getIntent().getExtras(): null)
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION)
- .toIntent());
+ .toIntent();
+ if (mPreferenceFilter != null) {
+ intent.setClass(mContext, ChannelPanelActivity.class);
+ }
+ startActivity(intent);
finish();
return;
}
@@ -84,6 +88,7 @@
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
+ animatePanel();
}
@Override
diff --git a/src/com/android/settings/notification/app/ChannelPanelActivity.java b/src/com/android/settings/notification/app/ChannelPanelActivity.java
new file mode 100644
index 0000000..3ba118e
--- /dev/null
+++ b/src/com/android/settings/notification/app/ChannelPanelActivity.java
@@ -0,0 +1,111 @@
+/*
+ * 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.notification.app;
+
+import android.app.settings.SettingsEnums;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.Window;
+import android.view.WindowManager;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+import com.android.settings.core.HideNonSystemOverlayMixin;
+import com.android.settings.core.SubSettingLauncher;
+
+/**
+ * Dialog Activity to host channel settings
+ */
+public class ChannelPanelActivity extends FragmentActivity {
+
+ private static final String TAG = "ChannelPanelActivity";
+
+ final Bundle mBundle = new Bundle();
+ NotificationSettings mPanelFragment;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (!getIntent().hasExtra(Settings.EXTRA_CHANNEL_FILTER_LIST)) {
+ launchFullSettings();
+ }
+
+ getApplicationContext().getTheme().rebase();
+ createOrUpdatePanel();
+ getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ setIntent(intent);
+ createOrUpdatePanel();
+ }
+
+ @Override
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ }
+
+ private void launchFullSettings() {
+ Bundle extras = getIntent().getExtras();
+ extras.remove(Settings.EXTRA_CHANNEL_FILTER_LIST);
+ startActivity(new SubSettingLauncher(this)
+ .setDestination(ChannelNotificationSettings.class.getName())
+ .setExtras(extras)
+ .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_TOPIC_NOTIFICATION)
+ .toIntent());
+ finish();
+ }
+
+ private void createOrUpdatePanel() {
+ final Intent callingIntent = getIntent();
+ if (callingIntent == null) {
+ Log.e(TAG, "Null intent, closing Panel Activity");
+ finish();
+ return;
+ }
+
+ final FragmentManager fragmentManager = getSupportFragmentManager();
+ setContentView(R.layout.notification_channel_panel);
+
+ // Move the window to the bottom of screen, and make it take up the entire screen width.
+ final Window window = getWindow();
+ window.setGravity(Gravity.BOTTOM);
+ window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
+ WindowManager.LayoutParams.WRAP_CONTENT);
+
+ findViewById(R.id.done).setOnClickListener(v -> finish());
+ findViewById(R.id.see_more).setOnClickListener(v -> launchFullSettings());
+
+ mPanelFragment = callingIntent.hasExtra(Settings.EXTRA_CONVERSATION_ID)
+ ? new ConversationNotificationSettings()
+ : new ChannelNotificationSettings();
+ mPanelFragment.setArguments(new Bundle(mBundle));
+ fragmentManager.beginTransaction().replace(
+ android.R.id.list_container, mPanelFragment).commit();
+ }
+}
diff --git a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
index 313b387..73659b8 100644
--- a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java
@@ -93,6 +93,7 @@
.done(activity, mContext);
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
+ pref.findViewById(R.id.entity_header).setBackground(null);
}
}
diff --git a/src/com/android/settings/notification/app/ConversationNotificationSettings.java b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
index 819ba83..d712c84 100644
--- a/src/com/android/settings/notification/app/ConversationNotificationSettings.java
+++ b/src/com/android/settings/notification/app/ConversationNotificationSettings.java
@@ -49,10 +49,11 @@
for (NotificationPreferenceController controller : mControllers) {
controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,
- mConversationInfo, mSuspendedAppsAdmin, null);
+ mConversationInfo, mSuspendedAppsAdmin, mPreferenceFilter);
controller.displayPreference(getPreferenceScreen());
}
updatePreferenceStates();
+ animatePanel();
}
@Override
diff --git a/src/com/android/settings/notification/app/HeaderPreferenceController.java b/src/com/android/settings/notification/app/HeaderPreferenceController.java
index 6482943..4e9c039 100644
--- a/src/com/android/settings/notification/app/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/app/HeaderPreferenceController.java
@@ -92,6 +92,7 @@
.setRecyclerView(mFragment.getListView(), mFragment.getSettingsLifecycle())
.done(activity, mContext);
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
+ pref.findViewById(R.id.entity_header).setBackground(null);
}
}
diff --git a/src/com/android/settings/notification/app/NotificationSettings.java b/src/com/android/settings/notification/app/NotificationSettings.java
index 44c735a..99f067d 100644
--- a/src/com/android/settings/notification/app/NotificationSettings.java
+++ b/src/com/android/settings/notification/app/NotificationSettings.java
@@ -18,6 +18,9 @@
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@@ -39,8 +42,13 @@
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.animation.DecelerateInterpolator;
import android.widget.Toast;
+import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
@@ -85,6 +93,20 @@
protected Intent mIntent;
protected Bundle mArgs;
+ private ViewGroup mLayoutView;
+ private static final int DURATION_ANIMATE_PANEL_EXPAND_MS = 250;
+
+ private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener =
+ new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ animateIn();
+ if (mLayoutView != null) {
+ mLayoutView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ }
+ }
+ };
+
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -187,6 +209,50 @@
collectConfigActivities();
}
+ protected void animatePanel() {
+ if (mPreferenceFilter != null) {
+ mLayoutView = getActivity().findViewById(R.id.main_content);
+ mLayoutView.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);
+ }
+ }
+
+ /**
+ * Animate a Panel onto the screen.
+ * <p>
+ * Takes the entire panel and animates in from behind the navigation bar.
+ * <p>
+ * Relies on the Panel being having a fixed height to begin the animation.
+ */
+ private void animateIn() {
+ final AnimatorSet animatorSet = buildAnimatorSet(mLayoutView,
+ mLayoutView.getHeight() /* startY */, 0.0f /* endY */,
+ 0.0f /* startAlpha */, 1.0f /* endAlpha */,
+ DURATION_ANIMATE_PANEL_EXPAND_MS);
+ final ValueAnimator animator = new ValueAnimator();
+ animator.setFloatValues(0.0f, 1.0f);
+ animatorSet.play(animator);
+ animatorSet.start();
+ }
+
+ /**
+ * Build an {@link AnimatorSet} to animate the Panel, {@param parentView} in or out of the
+ * screen, based on the positional parameters {@param startY}, {@param endY}, the parameters
+ * for alpha changes {@param startAlpha}, {@param endAlpha}, and the {@param duration} in
+ * milliseconds.
+ */
+ @NonNull
+ private static AnimatorSet buildAnimatorSet(@NonNull View targetView,
+ float startY, float endY,
+ float startAlpha, float endAlpha, int duration) {
+ final AnimatorSet animatorSet = new AnimatorSet();
+ animatorSet.setDuration(duration);
+ animatorSet.setInterpolator(new DecelerateInterpolator());
+ animatorSet.playTogether(
+ ObjectAnimator.ofFloat(targetView, View.TRANSLATION_Y, startY, endY),
+ ObjectAnimator.ofFloat(targetView, View.ALPHA, startAlpha, endAlpha));
+ return animatorSet;
+ }
+
private void loadPreferencesFilter() {
Intent intent = getActivity().getIntent();
mPreferenceFilter = intent != null
diff --git a/src/com/android/settings/panel/InternetConnectivityPanel.java b/src/com/android/settings/panel/InternetConnectivityPanel.java
index 46843b0..4fda0a4 100644
--- a/src/com/android/settings/panel/InternetConnectivityPanel.java
+++ b/src/com/android/settings/panel/InternetConnectivityPanel.java
@@ -50,9 +50,8 @@
@VisibleForTesting
boolean mIsProviderModelEnabled;
private PanelContentCallback mCallback;
- private InternetUpdater mInternetUpdater;
- private boolean mIsAirplaneModeOn;
- private boolean mIsApmNetworksAvailable;
+ @VisibleForTesting
+ InternetUpdater mInternetUpdater;
public static InternetConnectivityPanel create(Context context) {
return new InternetConnectivityPanel(context);
@@ -62,8 +61,6 @@
mContext = context.getApplicationContext();
mIsProviderModelEnabled = Utils.isProviderModelEnabled(mContext);
mInternetUpdater = new InternetUpdater(context, null /* Lifecycle */, this);
- mIsAirplaneModeOn = mInternetUpdater.isAirplaneModeOn();
- mIsApmNetworksAvailable = mInternetUpdater.isApmNetworksAvailable();
}
/** @OnLifecycleEvent(ON_RESUME) */
@@ -90,9 +87,8 @@
@Override
public CharSequence getTitle() {
if (mIsProviderModelEnabled) {
- return mContext.getText(mIsApmNetworksAvailable
- ? R.string.airplane_mode_network_panel_title
- : R.string.provider_internet_settings);
+ return mContext.getText(mInternetUpdater.isAirplaneModeOn()
+ ? R.string.airplane_mode : R.string.provider_internet_settings);
}
return mContext.getText(R.string.internet_connectivity_panel_title);
}
@@ -102,8 +98,9 @@
*/
@Override
public CharSequence getSubTitle() {
- if (mIsProviderModelEnabled && mIsAirplaneModeOn && !mIsApmNetworksAvailable) {
- return mContext.getText(R.string.condition_airplane_title);
+ if (mIsProviderModelEnabled && mInternetUpdater.isAirplaneModeOn()
+ && mInternetUpdater.isWifiEnabled()) {
+ return mContext.getText(R.string.wifi_is_turned_on_subtitle);
}
return null;
}
@@ -136,7 +133,7 @@
@Override
public CharSequence getCustomizedButtonTitle() {
- if (mIsAirplaneModeOn && !mIsApmNetworksAvailable) {
+ if (mInternetUpdater.isAirplaneModeOn() && !mInternetUpdater.isWifiEnabled()) {
return null;
}
return mContext.getText(R.string.settings_button);
@@ -162,19 +159,14 @@
*/
@Override
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
- if (!isAirplaneModeOn) {
- mIsApmNetworksAvailable = false;
- }
- mIsAirplaneModeOn = isAirplaneModeOn;
updatePanelTitle();
}
/**
- * Called when airplane mode networks state is changed.
+ * Called when Wi-Fi enabled is changed.
*/
@Override
- public void onAirplaneModeNetworksChanged(boolean available) {
- mIsApmNetworksAvailable = available;
+ public void onWifiEnabledChanged(boolean enabled) {
updatePanelTitle();
}
@@ -183,16 +175,14 @@
return;
}
- if (mIsAirplaneModeOn && !mIsApmNetworksAvailable) {
- // When the airplane mode is on.
- // Title: Internet
- // Sub-Title: Airplane mode is on
- // Settings button: Hide
+ if (mInternetUpdater.isAirplaneModeOn() && mInternetUpdater.isWifiEnabled()) {
+ // When the airplane mode is on and Wi-Fi is enabled.
+ // Title: Airplane mode
+ // Sub-Title: Wi-Fi is turned on
mCallback.onHeaderChanged();
} else {
- // Except for airplane mode on.
- // Title: Airplane mode networks / Internet
- // Settings button: Show
+ // Other situations.
+ // Title: Airplane mode / Internet
mCallback.onTitleChanged();
}
mCallback.onCustomizedButtonStateChanged();
diff --git a/src/com/android/settings/widget/LabeledSeekBarPreference.java b/src/com/android/settings/widget/LabeledSeekBarPreference.java
index e2b2d68..3a9ac18 100644
--- a/src/com/android/settings/widget/LabeledSeekBarPreference.java
+++ b/src/com/android/settings/widget/LabeledSeekBarPreference.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.SeekBar;
import android.widget.TextView;
@@ -32,6 +33,7 @@
private final int mTextStartId;
private final int mTextEndId;
+ private final int mTickMarkId;
private OnPreferenceChangeListener mStopListener;
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
@@ -48,6 +50,8 @@
mTextEndId = styledAttrs.getResourceId(
R.styleable.LabeledSeekBarPreference_textEnd,
R.string.summary_placeholder);
+ mTickMarkId = styledAttrs.getResourceId(
+ R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
styledAttrs.recycle();
}
@@ -65,6 +69,13 @@
final TextView endText = (TextView) holder.findViewById(android.R.id.text2);
startText.setText(mTextStartId);
endText.setText(mTextEndId);
+
+ if (mTickMarkId != 0) {
+ final Drawable tickMark = getContext().getDrawable(mTickMarkId);
+ final SeekBar seekBar = (SeekBar) holder.findViewById(
+ com.android.internal.R.id.seekbar);
+ seekBar.setTickMark(tickMark);
+ }
}
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
diff --git a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
index 0758869..ae200b9 100644
--- a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -23,6 +23,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.time.TimeManager;
@@ -62,9 +63,33 @@
}
@Test
+ public void setChecked_withTrue_shouldUpdateSetting() {
+ // Simulate the UI being clicked.
+ mController.setChecked(true);
+
+ // Verify the TimeManager was updated with the UI value.
+ TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(true)
+ .build();
+ verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
+ }
+
+ @Test
+ public void setChecked_withFalse_shouldUpdateSetting() {
+ // Simulate the UI being clicked.
+ mController.setChecked(false);
+
+ // Verify the TimeManager was updated with the UI value.
+ TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(false)
+ .build();
+ verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
+ }
+
+ @Test
public void testLocationTimeZoneDetection_supported_shouldBeShown() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
+ createTimeZoneCapabilities(CAPABILITY_POSSESSED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
@@ -76,7 +101,7 @@
@Test
public void testLocationTimeZoneDetection_unsupported_shouldNotBeShown() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ false);
+ createTimeZoneCapabilities(CAPABILITY_NOT_SUPPORTED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
@@ -91,20 +116,34 @@
@Test
public void testLocationTimeZoneDetection_summary_geoDetectionEnabled() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
+ createTimeZoneCapabilities(CAPABILITY_POSSESSED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- assertThat(mController.getSummary()).isEqualTo(
- mContext.getString(R.string.location_time_zone_detection_on));
+ assertThat(mController.getSummary().toString()).isEmpty();
}
- private static TimeZoneCapabilities createTimeZoneCapabilities(boolean geoDetectionSupported) {
+ @Test
+ public void testLocationTimeZoneDetection_toggleIsOn_whenGeoDetectionEnabledAnsMlsIsOff() {
+ TimeZoneCapabilities capabilities =
+ createTimeZoneCapabilities(CAPABILITY_NOT_APPLICABLE);
+ TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
+ new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
+
+ when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
+ when(mLocationManager.isLocationEnabled()).thenReturn(false);
+
+ assertThat(mController.isChecked()).isTrue();
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getString(R.string.location_app_permission_summary_location_off));
+ }
+
+ private static TimeZoneCapabilities createTimeZoneCapabilities(
+ @TimeZoneCapabilities.CapabilityState int geoDetectionCapability) {
UserHandle arbitraryUserHandle = UserHandle.of(123);
- int geoDetectionCapability =
- geoDetectionSupported ? CAPABILITY_POSSESSED : CAPABILITY_NOT_SUPPORTED;
return new TimeZoneCapabilities.Builder(arbitraryUserHandle)
.setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
.setConfigureGeoDetectionEnabledCapability(geoDetectionCapability)
diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java
deleted file mode 100644
index 9f16492..0000000
--- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.datetime.locationtimezone;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.provider.SearchIndexableResource;
-
-import com.android.settings.R;
-
-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 TimeZoneDetectionSettingsTest {
-
- private Context mContext;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- }
-
- @Test
- public void searchProvider_shouldIndexDefaultXml() {
- final List<SearchIndexableResource> sir =
- TimeZoneDetectionSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
- mContext, /* enabled= */ true);
-
- assertThat(sir).hasSize(1);
- assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_time_zone_detection);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java
deleted file mode 100644
index 27a9859..0000000
--- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.datetime.locationtimezone;
-
-import static android.app.time.TimeZoneCapabilities.CAPABILITY_NOT_APPLICABLE;
-import static android.app.time.TimeZoneCapabilities.CAPABILITY_POSSESSED;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.time.TimeManager;
-import android.app.time.TimeZoneCapabilities;
-import android.app.time.TimeZoneCapabilitiesAndConfig;
-import android.app.time.TimeZoneConfiguration;
-import android.content.Context;
-import android.os.UserHandle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class TimeZoneDetectionTogglePreferenceControllerTest {
-
- private static final String PREF_KEY = "test_key";
-
- @Mock
- private Context mContext;
-
- @Mock
- private TimeManager mTimeManager;
- private TimeZoneDetectionTogglePreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
-
- mController = new TimeZoneDetectionTogglePreferenceController(mContext, PREF_KEY);
- }
-
- @Test
- public void isAvailable_shouldReturnTrue() {
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void isChecked_whenEnabled_shouldReturnTrue() {
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
- .thenReturn(createTimeZoneCapabilitiesAndConfig(true));
-
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void isChecked_whenDisabled_shouldReturnFalse() {
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
- .thenReturn(createTimeZoneCapabilitiesAndConfig(false));
-
- assertThat(mController.isChecked()).isFalse();
- }
-
- @Test
- public void setChecked_withTrue_shouldUpdateSetting() {
- // Simulate the UI being clicked.
- mController.setChecked(true);
-
- // Verify the TimeManager was updated with the UI value.
- TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(true)
- .build();
- verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
- }
-
- @Test
- public void setChecked_withFalse_shouldUpdateSetting() {
- // Simulate the UI being clicked.
- mController.setChecked(false);
-
- // Verify the TimeManager was updated with the UI value.
- TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(false)
- .build();
- verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
- }
-
- private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig(
- boolean geoDetectionEnabled) {
- UserHandle arbitraryUserHandle = UserHandle.of(123);
- TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(arbitraryUserHandle)
- .setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
- .setConfigureGeoDetectionEnabledCapability(CAPABILITY_POSSESSED)
- .setSuggestManualTimeZoneCapability(CAPABILITY_NOT_APPLICABLE)
- .build();
- TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
- .setAutoDetectionEnabled(true)
- .setGeoDetectionEnabled(geoDetectionEnabled)
- .build();
- return new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceControllerTest.java
index 65fa187..8d38509 100644
--- a/tests/robotests/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/emergency/EmergencyGestureEntrypointPreferenceControllerTest.java
@@ -105,7 +105,7 @@
}
@Test
- public void getAvailabilityStatus_noSuitableIntent_shouldReturnUnsupported() {
+ public void getAvailabilityStatus_noSuitableIntent_shouldReturnAvailable() {
SettingsShadowResources.overrideResource(
R.bool.config_show_emergency_gesture_settings,
Boolean.TRUE);
@@ -117,7 +117,8 @@
EmergencyGestureEntrypointPreferenceController controller =
new EmergencyGestureEntrypointPreferenceController(mContext, PREF_KEY);
- assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ assertThat(controller.mIntent).isNull();
}
private void prepareCustomIntent() {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
index 6593767..5bcaf0a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoLoaderTest.java
@@ -19,23 +19,23 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
-import android.os.BatteryStats;
+import android.os.BatteryStatsManager;
+import android.os.BatteryUsageStats;
+import android.os.BatteryUsageStatsQuery;
-import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -46,10 +46,10 @@
private static final long TEST_TIME_REMAINING = 1000L;
- @Mock (answer = Answers.RETURNS_DEEP_STUBS)
- private BatteryStatsHelper mHelper;
- @Mock (answer = Answers.RETURNS_DEEP_STUBS)
- private BatteryStats mStats;
+ @Mock
+ private BatteryStatsManager mBatteryStatsManager;
+ @Mock
+ private BatteryUsageStats mBatteryUsageStats;
private Context mContext;
@@ -60,8 +60,11 @@
FakeFeatureFactory.setupForTest().getPowerUsageFeatureProvider(mContext);
doReturn(mContext).when(mContext).getApplicationContext();
- when(mStats.computeBatteryTimeRemaining(anyLong())).thenReturn(TEST_TIME_REMAINING);
- doReturn(mStats).when(mHelper).getStats();
+ when(mContext.getSystemService(eq(Context.BATTERY_STATS_SERVICE)))
+ .thenReturn(mBatteryStatsManager);
+ when(mBatteryUsageStats.getBatteryTimeRemainingMs()).thenReturn(TEST_TIME_REMAINING);
+ when(mBatteryStatsManager.getBatteryUsageStats(any(BatteryUsageStatsQuery.class)))
+ .thenReturn(mBatteryUsageStats);
final Intent dischargingBatteryBroadcast = BatteryTestUtils.getDischargingIntent();
doReturn(dischargingBatteryBroadcast).when(mContext).registerReceiver(any(), any());
@@ -69,8 +72,8 @@
@Test
public void test_loadInBackground_dischargingOldEstimate_dischargingLabelNotNull() {
- BatteryInfoLoader loader = new BatteryInfoLoader(mContext, mHelper);
- loader.batteryUtils = new BatteryUtils(mContext);
+ BatteryInfoLoader loader = new BatteryInfoLoader(mContext);
+ loader.mBatteryUtils = new BatteryUtils(mContext);
BatteryInfo info = loader.loadInBackground();
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index 4c19477..18c5326 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -34,9 +34,11 @@
import android.content.Intent;
import android.os.BatteryManager;
import android.os.BatteryStats;
+import android.os.BatteryUsageStats;
import android.os.SystemClock;
import android.util.SparseIntArray;
+import com.android.internal.os.BatteryStatsHistoryIterator;
import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.widget.UsageView;
@@ -46,7 +48,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -83,9 +84,8 @@
private Intent mChargingBatteryBroadcast;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private BatteryStats mBatteryStats;
+ @Mock
+ private BatteryUsageStats mBatteryUsageStats;
@Before
public void setUp() {
@@ -100,9 +100,10 @@
@Test
public void testGetBatteryInfo_hasStatusLabel() {
- doReturn(REMAINING_TIME_NULL).when(mBatteryStats).computeBatteryTimeRemaining(anyLong());
+ doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getBatteryTimeRemainingMs();
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext,
- mDisChargingBatteryBroadcast, mBatteryStats, SystemClock.elapsedRealtime() * 1000,
+ mDisChargingBatteryBroadcast, mBatteryUsageStats,
+ SystemClock.elapsedRealtime() * 1000,
true /* shortString */);
assertThat(info.statusLabel).isEqualTo(STATUS_NOT_CHARGING);
@@ -110,28 +111,28 @@
@Test
public void testGetBatteryInfo_doNotShowChargingMethod_hasRemainingTime() {
- doReturn(REMAINING_TIME).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
+ doReturn(REMAINING_TIME).when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
- mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
+ mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
assertThat(info.chargeLabel.toString()).isEqualTo(STATUS_CHARGING_TIME);
}
@Test
public void testGetBatteryInfo_doNotShowChargingMethod_noRemainingTime() {
- doReturn(REMAINING_TIME_NULL).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
+ doReturn(REMAINING_TIME_NULL).when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
- mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
+ mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */);
assertThat(info.chargeLabel.toString()).isEqualTo(STATUS_CHARGING_NO_TIME);
}
@Test
public void testGetBatteryInfo_pluggedInUsingShortString_usesCorrectData() {
- doReturn(TEST_CHARGE_TIME_REMAINING).when(mBatteryStats).computeChargeTimeRemaining(
- anyLong());
+ doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
+ .when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info = BatteryInfo.getBatteryInfoOld(mContext, mChargingBatteryBroadcast,
- mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */);
+ mBatteryUsageStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */);
assertThat(info.discharging).isEqualTo(false);
assertThat(info.chargeLabel.toString()).isEqualTo("50% - 1 min until charged");
@@ -143,10 +144,10 @@
true /* isBasedOnUsage */,
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
true /* shortString */);
// We only add special mention for the long string
@@ -163,10 +164,10 @@
true /* isBasedOnUsage */,
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
true /* shortString */);
// These should be identical in either case
@@ -183,7 +184,7 @@
true /* isBasedOnUsage */,
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(info.suggestionLabel).doesNotContain(BATTERY_RUN_OUT_PREFIX);
@@ -196,7 +197,7 @@
true /* isBasedOnUsage */,
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
// Check that strings are showing less than 15 minutes remaining regardless of exact time.
@@ -211,10 +212,10 @@
@Test
public void testGetBatteryInfo_basedOnUsageFalse_usesDefaultString() {
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
- mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
true /* shortString */);
assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
@@ -223,12 +224,11 @@
@Test
public void testGetBatteryInfo_charging_usesChargeTime() {
- doReturn(TEST_CHARGE_TIME_REMAINING)
- .when(mBatteryStats)
- .computeChargeTimeRemaining(anyLong());
+ doReturn(TEST_CHARGE_TIME_REMAINING / 1000)
+ .when(mBatteryUsageStats).getChargeTimeRemainingMs();
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
- mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
assertThat(info.remainingLabel.toString())
@@ -240,7 +240,7 @@
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 100);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
- mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(info.chargeLabel).isEqualTo("100%");
@@ -249,13 +249,13 @@
@Test
public void testGetBatteryInfo_chargingWithOverheated_updateChargeLabel() {
doReturn(TEST_CHARGE_TIME_REMAINING)
- .when(mBatteryStats)
- .computeChargeTimeRemaining(anyLong());
+ .when(mBatteryUsageStats)
+ .getChargeTimeRemainingMs();
mChargingBatteryBroadcast
.putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
- mBatteryStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
+ mBatteryUsageStats, MOCK_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(info.isOverheated).isTrue();
@@ -264,28 +264,29 @@
// Make our battery stats return a sequence of battery events.
private void mockBatteryStatsHistory() {
- // Mock out new data every time start...Locked is called.
+ // Mock out new data every time iterateBatteryStatsHistory is called.
doAnswer(invocation -> {
- doAnswer(new Answer() {
- private int count = 0;
- private long[] times = {1000, 1500, 2000};
- private byte[] levels = {99, 98, 97};
+ BatteryStatsHistoryIterator iterator = mock(BatteryStatsHistoryIterator.class);
+ doAnswer(new Answer<Boolean>() {
+ private int mCount = 0;
+ private final long[] mTimes = {1000, 1500, 2000};
+ private final byte[] mLevels = {99, 98, 97};
@Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- if (count == times.length) {
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ if (mCount == mTimes.length) {
return false;
}
BatteryStats.HistoryItem record = invocation.getArgument(0);
record.cmd = BatteryStats.HistoryItem.CMD_UPDATE;
- record.time = times[count];
- record.batteryLevel = levels[count];
- count++;
+ record.time = mTimes[mCount];
+ record.batteryLevel = mLevels[mCount];
+ mCount++;
return true;
}
- }).when(mBatteryStats).getNextHistoryLocked(any(BatteryStats.HistoryItem.class));
- return true;
- }).when(mBatteryStats).startIteratingHistoryLocked();
+ }).when(iterator).next(any(BatteryStats.HistoryItem.class));
+ return iterator;
+ }).when(mBatteryUsageStats).iterateBatteryStatsHistory();
}
private void assertOnlyHistory(BatteryInfo info) {
@@ -337,9 +338,9 @@
private BatteryInfo getBatteryInfo(boolean charging, boolean enhanced, boolean estimate) {
if (charging && estimate) {
- doReturn(1000L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
+ doReturn(1000L).when(mBatteryUsageStats).getChargeTimeRemainingMs();
} else {
- doReturn(0L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
+ doReturn(0L).when(mBatteryUsageStats).getChargeTimeRemainingMs();
}
Estimate batteryEstimate = new Estimate(
estimate ? 1000 : 0,
@@ -347,7 +348,7 @@
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
charging ? mChargingBatteryBroadcast : mDisChargingBatteryBroadcast,
- mBatteryStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
+ mBatteryUsageStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
doReturn(enhanced).when(mFeatureFactory.powerUsageFeatureProvider)
.isEnhancedBatteryPredictionEnabled(mContext);
return info;
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index f393da8..c8fdf8c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -48,6 +48,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
+import android.os.BatteryStatsManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
@@ -157,6 +158,8 @@
private ApplicationInfo mApplicationInfo;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private BatteryStatsHelper mBatteryStatsHelper;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private BatteryStatsManager mBatteryStatsManager;
@Mock
private ApplicationInfo mHighApplicationInfo;
@Mock
@@ -228,6 +231,8 @@
mContext = spy(RuntimeEnvironment.application);
doReturn(mPackageManager).when(mContext).getPackageManager();
doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
+ doReturn(mBatteryStatsManager).when(mContext)
+ .getSystemService(Context.BATTERY_STATS_SERVICE);
mBatteryUtils = spy(new BatteryUtils(mContext));
mBatteryUtils.mPowerUsageFeatureProvider = mProvider;
doReturn(0L).when(mBatteryUtils)
@@ -741,7 +746,7 @@
any(IntentFilter.class))).thenReturn(new Intent());
//Should not crash
- assertThat(mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG)).isNotNull();
+ assertThat(mBatteryUtils.getBatteryInfo(TAG)).isNotNull();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
index cd1b178..8754700 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageBaseTest.java
@@ -75,6 +75,11 @@
}
@Override
+ protected boolean isBatteryHistoryNeeded() {
+ return false;
+ }
+
+ @Override
protected void refreshUi(int refreshType) {
// Do nothing
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
index 8cc17d8..c97d79f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoaderTest.java
@@ -77,7 +77,7 @@
doReturn(mContext).when(mContext).getApplicationContext();
doReturn(mPowerManager).when(mContext).getSystemService(Context.POWER_SERVICE);
doReturn(mIntent).when(mContext).registerReceiver(any(), any());
- doReturn(mBatteryInfo).when(mBatteryUtils).getBatteryInfo(any(), any());
+ doReturn(mBatteryInfo).when(mBatteryUtils).getBatteryInfo(any());
mBatteryTipLoader = new BatteryTipLoader(mContext, mBatteryStatsHelper);
mBatteryTipLoader.mBatteryUtils = mBatteryUtils;
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
index 5c56f46..93005d5 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
@@ -18,7 +18,9 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -26,8 +28,11 @@
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
import android.os.BatteryStats;
-import android.text.format.DateUtils;
+import android.os.BatteryStatsManager;
+import android.os.BatteryUsageStats;
+import android.os.BatteryUsageStatsQuery;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
@@ -53,6 +58,8 @@
@RunWith(RobolectricTestRunner.class)
public class HighUsageDetectorTest {
+ private static final String TAG = "HighUsageDetectorTest";
+
private static final int UID_HIGH = 123;
private static final int UID_LOW = 345;
private static final double POWER_HIGH = 20000;
@@ -68,6 +75,10 @@
private BatterySipper mSystemBatterySipper;
@Mock
private HighUsageDataParser mDataParser;
+ @Mock
+ private BatteryUsageStats mBatteryUsageStats;
+ @Mock
+ private BatteryStatsManager mBatteryStatsManager;
private AppInfo mHighAppInfo;
private AppInfo mLowAppInfo;
@@ -80,11 +91,19 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
+ mContext = spy(RuntimeEnvironment.application);
mPolicy = spy(new BatteryTipPolicy(mContext));
- mBatteryUtils = spy(BatteryUtils.getInstance(mContext));
+ mBatteryUtils = spy(new BatteryUtils(mContext));
+
+ when(mContext.getSystemService(eq(Context.BATTERY_STATS_SERVICE)))
+ .thenReturn(mBatteryStatsManager);
+ when(mBatteryStatsManager.getBatteryUsageStats(any(BatteryUsageStatsQuery.class)))
+ .thenReturn(mBatteryUsageStats);
+
+ mContext.sendStickyBroadcast(new Intent(Intent.ACTION_BATTERY_CHANGED));
+
mHighUsageDetector = spy(new HighUsageDetector(mContext, mPolicy, mBatteryStatsHelper,
- true /* mDischarging */));
+ mBatteryUtils.getBatteryInfo(TAG)));
mHighUsageDetector.mBatteryUtils = mBatteryUtils;
mHighUsageDetector.mDataParser = mDataParser;
doNothing().when(mHighUsageDetector).parseBatteryData();
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index aa96666..d7c0ffe 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -54,6 +54,7 @@
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
+import com.android.settings.AirplaneModeEnabler;
import com.android.settings.R;
import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
@@ -90,6 +91,8 @@
@Mock
private UserManager mUserManager;
@Mock
+ private AirplaneModeEnabler mAirplaneModeEnabler;
+ @Mock
private DataUsagePreference mDataUsagePreference;
private Context mContext;
private NetworkProviderSettings mNetworkProviderSettings;
@@ -100,8 +103,7 @@
@Mock
private ConnectivitySubsystemsRecoveryManager mConnectivitySubsystemsRecoveryManager;
@Mock
- private ViewAirplaneModeNetworksLayoutPreferenceController
- mViewAirplaneModeNetworksButtonPreference;
+ private Preference mAirplaneModeMsgPreference;
@Mock
private LayoutPreference mResetInternetPreference;
@Mock
@@ -126,6 +128,9 @@
new Preference(mContext);
mNetworkProviderSettings.mWifiPickerTracker = mMockWifiPickerTracker;
mNetworkProviderSettings.mWifiManager = mWifiManager;
+ mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference;
+ mNetworkProviderSettings.mAirplaneModeMsgPreference = mAirplaneModeMsgPreference;
+ mNetworkProviderSettings.mAirplaneModeEnabler = mAirplaneModeEnabler;
}
@Test
@@ -421,27 +426,35 @@
}
@Test
- public void onSubsystemRestartOperationBegin_showResetInternetHideApmNetworks() {
- mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference;
- mNetworkProviderSettings.mViewAirplaneModeNetworksButtonPreference =
- mViewAirplaneModeNetworksButtonPreference;
-
+ public void onSubsystemRestartOperationBegin_showResetInternetHideApmMsg() {
mNetworkProviderSettings.onSubsystemRestartOperationBegin();
verify(mResetInternetPreference).setVisible(true);
- verify(mViewAirplaneModeNetworksButtonPreference).setVisible(false);
+ verify(mAirplaneModeMsgPreference).setVisible(false);
}
@Test
- public void onSubsystemRestartOperationEnd_showApmNetworksHideResetInternet() {
- mNetworkProviderSettings.mResetInternetPreference = mResetInternetPreference;
- mNetworkProviderSettings.mViewAirplaneModeNetworksButtonPreference =
- mViewAirplaneModeNetworksButtonPreference;
- doReturn(true).when(mViewAirplaneModeNetworksButtonPreference).isAvailable();
+ public void onSubsystemRestartOperationEnd_showApmMsgHideResetInternet() {
+ doReturn(true).when(mAirplaneModeEnabler).isAirplaneModeOn();
mNetworkProviderSettings.onSubsystemRestartOperationEnd();
verify(mResetInternetPreference).setVisible(false);
- verify(mViewAirplaneModeNetworksButtonPreference).setVisible(true);
+ verify(mAirplaneModeMsgPreference).setVisible(true);
+ }
+
+ @Test
+ public void onAirplaneModeChanged_apmIsOn_showApmMsg() {
+ mNetworkProviderSettings.onAirplaneModeChanged(true);
+
+ verify(mAirplaneModeMsgPreference).setVisible(true);
+ }
+
+
+ @Test
+ public void onAirplaneModeChanged_apmIsOff_hideApmMsg() {
+ mNetworkProviderSettings.onAirplaneModeChanged(false);
+
+ verify(mAirplaneModeMsgPreference).setVisible(false);
}
}
diff --git a/tests/unit/src/com/android/settings/applications/autofill/PasswordsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/autofill/PasswordsPreferenceControllerTest.java
new file mode 100644
index 0000000..216658f
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/autofill/PasswordsPreferenceControllerTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.applications.autofill;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Looper;
+import android.service.autofill.AutofillServiceInfo;
+
+import androidx.preference.Preference;
+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.google.android.collect.Lists;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Collections;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class PasswordsPreferenceControllerTest {
+
+ private Context mContext;
+ private PreferenceScreen mScreen;
+ private PreferenceCategory mPasswordsPreferenceCategory;
+
+ @Before
+ public void setUp() {
+ mContext = ApplicationProvider.getApplicationContext();
+ if (Looper.myLooper() == null) {
+ Looper.prepare(); // needed to create the preference screen
+ }
+ mScreen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
+ mPasswordsPreferenceCategory = new PreferenceCategory(mContext);
+ mPasswordsPreferenceCategory.setKey("passwords");
+ mScreen.addPreference(mPasswordsPreferenceCategory);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noServices_returnsUnavailable() {
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Collections.emptyList());
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noPasswords_returnsUnavailable() {
+ AutofillServiceInfo service = new AutofillServiceInfo.TestDataBuilder().build();
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Lists.newArrayList(service));
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_withPasswords_returnsAvailable() {
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Lists.newArrayList(createServiceWithPasswords()));
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void displayPreference_noServices_noPreferencesAdded() {
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Collections.emptyList());
+ controller.displayPreference(mScreen);
+ assertThat(mPasswordsPreferenceCategory.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void displayPreference_noPasswords_noPreferencesAdded() {
+ AutofillServiceInfo service = new AutofillServiceInfo.TestDataBuilder().build();
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Lists.newArrayList(service));
+ controller.displayPreference(mScreen);
+ assertThat(mPasswordsPreferenceCategory.getPreferenceCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void displayPreference_withPasswords_addsPreference() {
+ AutofillServiceInfo service = createServiceWithPasswords();
+ PasswordsPreferenceController controller =
+ createControllerWithServices(Lists.newArrayList(service));
+ controller.displayPreference(mScreen);
+
+ assertThat(mPasswordsPreferenceCategory.getPreferenceCount()).isEqualTo(1);
+ Preference pref = mPasswordsPreferenceCategory.getPreference(0);
+ assertThat(pref.getIcon()).isNotNull();
+ assertThat(pref.getIntent().getComponent())
+ .isEqualTo(
+ new ComponentName(
+ service.getServiceInfo().packageName,
+ service.getPasswordsActivity()));
+ }
+
+ private PasswordsPreferenceController createControllerWithServices(
+ List<AutofillServiceInfo> availableServices) {
+ return new PasswordsPreferenceController(
+ mContext, mPasswordsPreferenceCategory.getKey(), availableServices);
+ }
+
+ private AutofillServiceInfo createServiceWithPasswords() {
+ return new AutofillServiceInfo.TestDataBuilder()
+ .setPasswordsActivity("com.android.test.Passwords")
+ .build();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/AllowedNetworkTypesListenerTest.java b/tests/unit/src/com/android/settings/network/AllowedNetworkTypesListenerTest.java
index d8f3c78..e89a257 100644
--- a/tests/unit/src/com/android/settings/network/AllowedNetworkTypesListenerTest.java
+++ b/tests/unit/src/com/android/settings/network/AllowedNetworkTypesListenerTest.java
@@ -40,9 +40,6 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import java.util.HashMap;
-import java.util.Map;
-
@RunWith(AndroidJUnit4.class)
public class AllowedNetworkTypesListenerTest {
@@ -73,12 +70,11 @@
@Test
public void onChange_shouldCallListener() {
mAllowedNetworkTypesListener.mListener = mListener;
- Map<Integer, Long> allowedNetworkTypesList = new HashMap<>();
long networkType = (long) RadioAccessFamily.getRafFromNetworkType(
TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO);
- allowedNetworkTypesList.put(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
- networkType);
- mAllowedNetworkTypesListener.onAllowedNetworkTypesChanged(allowedNetworkTypesList);
+
+ mAllowedNetworkTypesListener.onAllowedNetworkTypesChanged(
+ TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, networkType);
verify(mListener).onAllowedNetworkTypesChanged();
}
diff --git a/tests/unit/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceControllerTest.java
deleted file mode 100644
index 972e3fb..0000000
--- a/tests/unit/src/com/android/settings/network/ViewAirplaneModeNetworksLayoutPreferenceControllerTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-import android.content.Context;
-import android.net.wifi.WifiManager;
-import android.os.Looper;
-import android.view.View;
-
-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.testutils.AirplaneModeRule;
-import com.android.settings.testutils.ResourcesUtils;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.widget.LayoutPreference;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnit;
-import org.mockito.junit.MockitoRule;
-
-@RunWith(AndroidJUnit4.class)
-public class ViewAirplaneModeNetworksLayoutPreferenceControllerTest {
-
- private static final String KEY = ViewAirplaneModeNetworksLayoutPreferenceController.KEY;
- private static final String RES_ID_AIRPLANE_MODE_IS_ON = "condition_airplane_title";
- private static final String RES_ID_VIEWING_AIRPLANE_MODE_NETWORKS =
- "viewing_airplane_mode_networks";
-
- @Rule
- public final MockitoRule mMockitoRule = MockitoJUnit.rule();
- @Rule
- public AirplaneModeRule mAirplaneModeRule = new AirplaneModeRule();
- @Mock
- private WifiManager mWifiManager;
-
- private Context mContext;
- private PreferenceScreen mScreen;
- private LayoutPreference mPreference;
- private ViewAirplaneModeNetworksLayoutPreferenceController mController;
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- doReturn(mWifiManager).when(mContext).getSystemService(Context.WIFI_SERVICE);
-
- mController = new ViewAirplaneModeNetworksLayoutPreferenceController(mContext,
- mock(Lifecycle.class));
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
- final PreferenceManager preferenceManager = new PreferenceManager(mContext);
- mScreen = preferenceManager.createPreferenceScreen(mContext);
- mPreference = new LayoutPreference(mContext,
- ResourcesUtils.getResourcesId(
- mContext, "layout", "view_airplane_mode_networks_button"));
- mPreference.setKey(KEY);
- mScreen.addPreference(mPreference);
- }
-
- @Test
- public void isAvailable_airplaneModeOff_returnFalse() {
- mAirplaneModeRule.setAirplaneMode(false);
-
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void isAvailable_airplaneModeOn_returnTrue() {
- mAirplaneModeRule.setAirplaneMode(true);
-
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void displayPreference_wifiDisabled_showAirplaneModeIsOnButtonVisible() {
- mAirplaneModeRule.setAirplaneMode(true);
- doReturn(false).when(mWifiManager).isWifiEnabled();
-
- mController.displayPreference(mScreen);
-
- assertThat(mController.mTextView.getText())
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, RES_ID_AIRPLANE_MODE_IS_ON));
- assertThat(mController.mButton.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void displayPreference_wifiEnabled_showViewingAirplaneModeNetworksButtonGone() {
- mAirplaneModeRule.setAirplaneMode(true);
- doReturn(true).when(mWifiManager).isWifiEnabled();
-
- mController.displayPreference(mScreen);
-
- assertThat(mController.mTextView.getText()).isEqualTo(
- ResourcesUtils.getResourcesString(mContext, RES_ID_VIEWING_AIRPLANE_MODE_NETWORKS));
- assertThat(mController.mButton.getVisibility()).isEqualTo(View.GONE);
- }
-
- @Test
- public void refreshLayout_wifiEnabledThenDisabled_showAirplaneModeIsOnButtonVisible() {
- mAirplaneModeRule.setAirplaneMode(true);
- // Wi-Fi enabled
- doReturn(true).when(mWifiManager).isWifiEnabled();
- // Display preference
- mController.displayPreference(mScreen);
- // Then Wi-Fi disabled
- doReturn(false).when(mWifiManager).isWifiEnabled();
-
- // Refresh layout
- mController.refreshLayout();
-
- assertThat(mController.mTextView.getText())
- .isEqualTo(ResourcesUtils.getResourcesString(mContext, RES_ID_AIRPLANE_MODE_IS_ON));
- assertThat(mController.mButton.getVisibility()).isEqualTo(View.VISIBLE);
- }
-
- @Test
- public void refreshLayout_wifiDisabledThenEnabled_showViewingAirplaneModeNetworksButtonGone() {
- mAirplaneModeRule.setAirplaneMode(true);
- // Wi-Fi disabled
- doReturn(false).when(mWifiManager).isWifiEnabled();
- // Display preference
- mController.displayPreference(mScreen);
- // Then Wi-Fi enabled
- doReturn(true).when(mWifiManager).isWifiEnabled();
-
- // Refresh layout
- mController.refreshLayout();
-
- assertThat(mController.mTextView.getText()).isEqualTo(
- ResourcesUtils.getResourcesString(mContext, RES_ID_VIEWING_AIRPLANE_MODE_NETWORKS));
- assertThat(mController.mButton.getVisibility()).isEqualTo(View.GONE);
- }
-
- @Test
- public void onClick_shouldSetWifiEnabled() {
- mAirplaneModeRule.setAirplaneMode(true);
- doReturn(false).when(mWifiManager).isWifiEnabled();
-
- mController.onClick(mock(View.class));
-
- verify(mWifiManager).setWifiEnabled(true);
- }
-}
diff --git a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
index 5d95d9a..ba5ee8e 100644
--- a/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
+++ b/tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.clearInvocations;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -29,6 +30,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.network.AirplaneModePreferenceController;
+import com.android.settings.network.InternetUpdater;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.testutils.ResourcesUtils;
@@ -47,10 +49,10 @@
public static final String TITLE_INTERNET = ResourcesUtils.getResourcesString(
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 TITLE_APM = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "airplane_mode");
+ public static final String SUBTITLE_WIFI_IS_TURNED_ON = ResourcesUtils.getResourcesString(
+ ApplicationProvider.getApplicationContext(), "wifi_is_turned_on_subtitle");
public static final String BUTTON_SETTINGS = ResourcesUtils.getResourcesString(
ApplicationProvider.getApplicationContext(), "settings_button");
@@ -58,6 +60,8 @@
public final MockitoRule mMocks = MockitoJUnit.rule();
@Mock
PanelContentCallback mPanelContentCallback;
+ @Mock
+ InternetUpdater mInternetUpdater;
private Context mContext;
private InternetConnectivityPanel mPanel;
@@ -69,73 +73,65 @@
mPanel = InternetConnectivityPanel.create(mContext);
mPanel.registerCallback(mPanelContentCallback);
mPanel.mIsProviderModelEnabled = true;
+ mPanel.mInternetUpdater = mInternetUpdater;
}
@Test
- public void getTitle_apmOnApmNetworksOff_shouldBeInternet() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(false);
+ public void getTitle_apmOff_shouldBeInternet() {
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
}
@Test
- public void getTitle_apmOnApmNetworksOn_shouldBeApmNetworks() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(true);
+ public void getTitle_apmOn_shouldBeApm() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM_NETWORKS);
- }
-
- @Test
- public void getTitle_notInternetApmNetworks_shouldBeInternet() {
- mPanel.onAirplaneModeNetworksChanged(false);
-
- assertThat(mPanel.getTitle()).isEqualTo(TITLE_INTERNET);
- }
-
- @Test
- public void getSubTitle_apmOnApmNetworksOff_shouldBeApmIsOn() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(false);
-
- assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_APM_IS_ON);
- }
-
- @Test
- public void getSubTitle_apmOnApmNetworksOn_shouldBeNull() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(true);
-
- assertThat(mPanel.getSubTitle()).isNull();
+ assertThat(mPanel.getTitle()).isEqualTo(TITLE_APM);
}
@Test
public void getSubTitle_apmOff_shouldBeNull() {
- mPanel.onAirplaneModeChanged(false);
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
assertThat(mPanel.getSubTitle()).isNull();
}
@Test
- public void getCustomizedButtonTitle_apmOnApmNetworksOff_shouldBeNull() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(false);
+ public void getSubTitle_apmOnWifiOff_shouldBeNull() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
- assertThat(mPanel.getCustomizedButtonTitle()).isNull();
+ assertThat(mPanel.getSubTitle()).isNull();
}
@Test
- public void getCustomizedButtonTitle_apmOnApmNetworksOn_shouldBeSettings() {
- mPanel.onAirplaneModeChanged(true);
- mPanel.onAirplaneModeNetworksChanged(true);
+ public void getSubTitle_apmOnWifiOn_shouldWifiIsTurnedOn() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(true).when(mInternetUpdater).isWifiEnabled();
+
+ assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_WIFI_IS_TURNED_ON);
+ }
+
+ @Test
+ public void getCustomizedButtonTitle_apmOff_shouldBeSettings() {
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
}
@Test
- public void getCustomizedButtonTitle_apmOff_shouldBeSettings() {
- mPanel.onAirplaneModeChanged(false);
+ public void getCustomizedButtonTitle_apmOnWifiOff_shouldBeNull() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
+
+ assertThat(mPanel.getCustomizedButtonTitle()).isNull();
+ }
+
+ @Test
+ public void getCustomizedButtonTitle_apmOnWifiOn_shouldBeSettings() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(true).when(mInternetUpdater).isWifiEnabled();
assertThat(mPanel.getCustomizedButtonTitle()).isEqualTo(BUTTON_SETTINGS);
}
@@ -166,46 +162,86 @@
}
@Test
- public void onAirplaneModeOn_apmNetworksOff_changeHeaderAndHideSettings() {
- mPanel.onAirplaneModeNetworksChanged(false);
+ public void onAirplaneModeOn_apmOff_onTitleChanged() {
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onAirplaneModeChanged(false);
+
+ verify(mPanelContentCallback).onTitleChanged();
+ }
+
+ @Test
+ public void onAirplaneModeOn_apmOnWifiOff_onTitleChanged() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onAirplaneModeChanged(true);
+
+ verify(mPanelContentCallback).onTitleChanged();
+ }
+
+ @Test
+ public void onAirplaneModeOn_apmOnWifiOn_onHeaderChanged() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(true).when(mInternetUpdater).isWifiEnabled();
clearInvocations(mPanelContentCallback);
mPanel.onAirplaneModeChanged(true);
verify(mPanelContentCallback).onHeaderChanged();
- verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
- public void onAirplaneModeOn_apmNetworksOn_changeTitleAndShowSettings() {
- mPanel.onAirplaneModeNetworksChanged(true);
+ public void onAirplaneModeOn_onCustomizedButtonStateChanged() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
clearInvocations(mPanelContentCallback);
mPanel.onAirplaneModeChanged(true);
- verify(mPanelContentCallback).onTitleChanged();
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
- public void onAirplaneModeNetworksOn_apmOff_changeTitleAndShowSettings() {
- mPanel.onAirplaneModeChanged(false);
+ public void onWifiEnabledChanged_apmOff_onTitleChanged() {
+ doReturn(false).when(mInternetUpdater).isAirplaneModeOn();
clearInvocations(mPanelContentCallback);
- mPanel.onAirplaneModeNetworksChanged(true);
+ mPanel.onWifiEnabledChanged(false);
verify(mPanelContentCallback).onTitleChanged();
- verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
@Test
- public void onAirplaneModeNetworksOff_apmOff_changeTitleAndShowSettings() {
- mPanel.onAirplaneModeChanged(false);
+ public void onWifiEnabledChanged_apmOnWifiOff_onTitleChanged() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(false).when(mInternetUpdater).isWifiEnabled();
clearInvocations(mPanelContentCallback);
- mPanel.onAirplaneModeNetworksChanged(false);
+ mPanel.onWifiEnabledChanged(true);
verify(mPanelContentCallback).onTitleChanged();
+ }
+
+ @Test
+ public void onWifiEnabledChanged_apmOnWifiOn_onHeaderChanged() {
+ doReturn(true).when(mInternetUpdater).isAirplaneModeOn();
+ doReturn(true).when(mInternetUpdater).isWifiEnabled();
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onWifiEnabledChanged(true);
+
+ verify(mPanelContentCallback).onHeaderChanged();
+ }
+
+ @Test
+ public void onWifiEnabledChanged_onCustomizedButtonStateChanged() {
+ doReturn(true).when(mInternetUpdater).isWifiEnabled();
+ clearInvocations(mPanelContentCallback);
+
+ mPanel.onWifiEnabledChanged(true);
+
verify(mPanelContentCallback).onCustomizedButtonStateChanged();
}
}