Merge "Fix tests in TimeoutToDockUserPreferenceControllerTest" into main
diff --git a/Android.bp b/Android.bp
index 2699c38..b456a72 100644
--- a/Android.bp
+++ b/Android.bp
@@ -75,7 +75,6 @@
"android.hardware.dumpstate-V1-java",
"android.hardware.dumpstate-V1.0-java",
"android.hardware.dumpstate-V1.1-java",
- "android.nfc.flags-aconfig-java",
"android.view.accessibility.flags-aconfig-java",
"com_android_server_accessibility_flags_lib",
"net-utils-framework-common",
@@ -94,6 +93,7 @@
"battery-event-protos-lite",
"battery-usage-slot-protos-lite",
"contextualcards",
+ "development_settings_flag_lib",
"factory_reset_flags_lib",
"fuelgauge-log-protos-lite",
"fuelgauge-usage-state-protos-lite",
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8ec5b3d..095452c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -16,11 +16,6 @@
android:name="com.android.settings.USE_BIOMETRIC_PROVIDER"
android:protectionLevel="signature|privileged"/>
- <!-- Permissions for acting as the factory reset preparation application. -->
- <permission
- android:name="com.android.settings.permissions.PREPARE_FACTORY_RESET"
- android:protectionLevel="signature|privileged"/>
-
<uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" />
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
@@ -4290,6 +4285,15 @@
android:value="true" />
</activity>
+ <!-- Access to the Credential Manager list. -->
+ <activity android:name=".applications.credentials.CredentialsPickerActivity"
+ android:excludeFromRecents="true"
+ android:launchMode="singleInstance"
+ android:exported="false">
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.applications.credentials.DefaultCombinedPicker" />
+ </activity>
+
<activity
android:name=".Settings$SystemDashboardActivity"
android:label="@string/header_category_system"
diff --git a/aconfig/Android.bp b/aconfig/Android.bp
index de6d0af..d14cc6f 100644
--- a/aconfig/Android.bp
+++ b/aconfig/Android.bp
@@ -47,3 +47,16 @@
name: "accessibility_settings_flags_lib",
aconfig_declarations: "accessibility_flags",
}
+
+aconfig_declarations {
+ name: "development_settings_flags",
+ package: "com.android.settings.development",
+ srcs: [
+ "development/**/*.aconfig"
+ ],
+}
+
+java_aconfig_library {
+ name: "development_settings_flag_lib",
+ aconfig_declarations: "development_settings_flags",
+}
diff --git a/aconfig/development/settings_core_flag_declarations.aconfig b/aconfig/development/settings_core_flag_declarations.aconfig
new file mode 100644
index 0000000..c012263
--- /dev/null
+++ b/aconfig/development/settings_core_flag_declarations.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.settings.development"
+
+flag {
+ name: "deprecate_list_activity"
+ namespace: "android_settings"
+ description: "Feature flag for deprecating ListActivity in Settings"
+ bug: "299195099"
+}
diff --git a/res/drawable/battery_hints_chip_bg.xml b/res/drawable/battery_hints_chip_bg.xml
index e7d1d0f..c2b662c 100644
--- a/res/drawable/battery_hints_chip_bg.xml
+++ b/res/drawable/battery_hints_chip_bg.xml
@@ -16,7 +16,8 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
- <solid android:color="@color/settingslib_dialog_background" />
+ <solid android:color="?androidprv:attr/materialColorPrimaryContainer" />
<corners android:radius="@dimen/battery_hints_chip_corner_radius" />
</shape>
\ No newline at end of file
diff --git a/res/layout/content_protection_preference_fragment.xml b/res/layout/content_protection_preference_fragment.xml
index 8bf6582..f85f2d1 100644
--- a/res/layout/content_protection_preference_fragment.xml
+++ b/res/layout/content_protection_preference_fragment.xml
@@ -40,8 +40,9 @@
<com.android.settingslib.RestrictedSwitchPreference
android:key="content_protection_preference_user_consent_work_profile_switch"
android:title="@string/content_protection_preference_user_consent_work_profile_switch_title"
+ settings:controller="com.android.settings.security.ContentProtectionWorkSwitchController"
settings:restrictedSwitchSummary="@string/summary_placeholder"
- settings:controller="com.android.settings.security.ContentProtectionWorkSwitchController"/>
+ settings:useAdditionalSummary="true"/>
<com.android.settingslib.widget.FooterPreference
android:key="content_protection_preference_subpage_footer"
diff --git a/res/layout/power_anomaly_hints.xml b/res/layout/power_anomaly_hints.xml
index e4ec47b..3781046 100644
--- a/res/layout/power_anomaly_hints.xml
+++ b/res/layout/power_anomaly_hints.xml
@@ -17,6 +17,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
@@ -36,7 +37,7 @@
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
android:textAlignment="viewStart"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/textColorPrimary"/>
+ android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle2"
+ android:textColor="?androidprv:attr/materialColorOnSurface"/>
</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8dca8d0..14a4a51 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -881,11 +881,11 @@
<!-- Title shown for menu item that launches watch unlock settings. [CHAR LIMIT=40] -->
<string name ="security_settings_activeunlock_preference_title">Watch Unlock</string>
<!-- Introduction shown in face and fingerprint page to introduce the biometric feature. [CHAR LIMIT=NONE]-->
- <string name="biometric_settings_intro_with_activeunlock">When you set up Face Unlock and Fingerprint Unlock, your phone will ask for your fingerprint when you wear a mask or are in a dark area.\n\nYou can unlock with your watch when your face or fingerprint isn\u2019t recognized.</string>
+ <string name="biometric_settings_intro_with_activeunlock">When you set up Face Unlock and Fingerprint Unlock, your phone will ask for your fingerprint when you wear a mask or are in a dark area.\n\nWatch Unlock is another convenient way to unlock your phone, for example, when your fingers are wet or face isn\u2019t recognized.</string>
<!-- Introduction shown in fingerprint page to explain that watch unlock can be used if fingerprint isn't recognized. [CHAR LIMIT=NONE]-->
- <string name="biometric_settings_intro_with_fingerprint">You can unlock with your watch when your fingerprint isn\u2019t recognized.</string>
+ <string name="biometric_settings_intro_with_fingerprint">Watch Unlock is another convenient way to unlock your phone, for example, when your fingerprint isn\u2019t recognized.</string>
<!-- Introduction shown in face page to explain that watch unlock can be used if face isn't recognized. [CHAR LIMIT=NONE]-->
- <string name="biometric_settings_intro_with_face">You can unlock with your watch when your face isn\u2019t recognized.</string>
+ <string name="biometric_settings_intro_with_face">Watch Unlock is another convenient way to unlock your phone, for example, when your face isn\u2019t recognized.</string>
<string name="biometric_settings_use_fingerprint_or_watch_for"> Use fingerprint or watch to</string>
<string name="biometric_settings_use_face_or_watch_for"> Use face or watch to</string>
<string name="biometric_settings_use_face_fingerprint_or_watch_for"> Use face, fingerprint, or watch to</string>
@@ -2308,8 +2308,6 @@
<string name="wifi_hotspot_name_title">Hotspot name</string>
<!-- Label for Wifi hotspot password. -->
<string name="wifi_hotspot_password_title">Hotspot password</string>
- <!-- Label for Wifi hotspot AP Band. -->
- <string name="wifi_hotspot_ap_band_title">AP Band</string>
<!-- Title for the toggle to turn off hotspot automatically [CHAR LIMIT=NONE]-->
<string name="wifi_hotspot_auto_off_title">Turn off hotspot automatically</string>
@@ -3409,29 +3407,8 @@
<!-- Tethering preference summary when hotspot and tethering are off [CHAR LIMIT=NONE]-->
<string name="tether_preference_summary_off">Off</string>
- <!-- Tethering interface options [CHAR LIMIT=NONE]-->
- <string name="tethering_interface_options">Tethering</string>
-
- <!-- Disable Wifi Hotspot option-->
- <!-- Don't use Wi-Fi hotspot title [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_title">Don\u2019t use Wi\u2011Fi hotspot</string>
- <!-- Don't use Wi-Fi hotspot summary when USB tethering is chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_usb_on">Only share internet via USB</string>
- <!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering is chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_bluetooth_on">Only share internet via Bluetooth</string>
- <!-- Don't use Wi-Fi hotspot summary when Ethernet tethering is chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_ethernet_on">Only share internet via Ethernet</string>
- <!-- Don't use Wi-Fi hotspot summary when USB tethering and Bluetooth tethering are chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_usb_and_bluetooth_on">Only share internet via USB and Bluetooth</string>
- <!-- Don't use Wi-Fi hotspot summary when USB tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_usb_and_ethernet_on">Only share internet via USB and Ethernet</string>
- <!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_bluetooth_and_ethernet_on">Only share internet via Bluetooth and Ethernet</string>
- <!-- Don't use Wi-Fi hotspot summary when USB, Bluetooth and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
- <string name="disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on">Only share internet via USB, Bluetooth and Ethernet</string>
-
<!-- USB Tethering options -->
- <string name="usb_title">USB</string>
+ <!-- Label for USB tethering switch [CHAR LIMIT=NONE]-->
<string name="usb_tethering_button_text">USB tethering</string>
<!-- Bluetooth Tethering settings-->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0786458..2c928ff 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -950,7 +950,7 @@
</style>
<style name="ScreenLockPasswordHintTextFontStyle">
- <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textColor">?android:attr/colorError</item>
<item name="android:fontFamily">google-sans-text</item>
</style>
diff --git a/res/xml/all_tether_prefs.xml b/res/xml/all_tether_prefs.xml
deleted file mode 100644
index 8673d31..0000000
--- a/res/xml/all_tether_prefs.xml
+++ /dev/null
@@ -1,100 +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:key="all_tether_prefs_screen"
- android:title="@string/tether_settings_title_all"
- settings:searchable="false">
-
- <PreferenceCategory
- android:key="wifi_tether_settings_group"
- android:title="@string/wifi_hotspot_checkbox_text"
- settings:searchable="false">
- <com.android.settings.wifi.tether.WifiTetherSsidPreference
- android:key="wifi_tether_network_name_2"
- android:title="@string/wifi_hotspot_name_title"
- android:summary="@string/summary_placeholder"/>
-
- <com.android.settings.widget.ValidatedEditTextPreference
- android:key="wifi_tether_network_password_2"
- android:persistent="false"
- android:title="@string/wifi_hotspot_password_title"/>
-
- <SwitchPreferenceCompat
- android:key="wifi_tether_auto_turn_off_2"
- android:title="@string/wifi_hotspot_auto_off_title"
- android:summary="@string/wifi_hotspot_auto_off_summary"/>
-
- <ListPreference
- android:key="wifi_tether_network_ap_band_2"
- android:title="@string/wifi_hotspot_ap_band_title"/>
-
- <ListPreference
- android:key="wifi_tether_security_2"
- android:title="@string/wifi_security"
- android:summary="@string/summary_placeholder"
- android:entries="@array/wifi_tether_security"
- android:entryValues="@array/wifi_tether_security_values"/>
- </PreferenceCategory>
-
- <PreferenceCategory
- android:key="tethering_options_group"
- android:title="@string/tethering_interface_options"
- settings:searchable="false">
- <SwitchPreferenceCompat
- android:key="enable_usb_tethering"
- android:title="@string/usb_tethering_button_text"
- android:summary="@string/usb_tethering_subtext"
- settings:controller="com.android.settings.network.UsbTetherPreferenceController"
- settings:keywords="@string/keywords_hotspot_tethering" />
-
- <SwitchPreferenceCompat
- android:key="enable_bluetooth_tethering_2"
- android:title="@string/bluetooth_tether_checkbox_text"
- android:summary="@string/bluetooth_tethering_subtext"
- settings:controller="com.android.settings.network.BluetoothTetherPreferenceController"
- settings:keywords="@string/keywords_hotspot_tethering" />
-
- <SwitchPreferenceCompat
- android:key="enable_ethernet_tethering_2"
- android:title="@string/ethernet_tether_checkbox_text"
- android:summary="@string/ethernet_tethering_subtext"
- settings:controller="com.android.settings.network.EthernetTetherPreferenceController"
- settings:keywords="@string/keywords_hotspot_tethering"/>
-
- <SwitchPreferenceCompat
- android:key="disable_wifi_tethering"
- android:title="@string/disable_wifi_hotspot_title"
- android:summary="@string/summary_placeholder"
- settings:controller="com.android.settings.network.WifiTetherDisablePreferenceController"
- settings:keywords="@string/keywords_hotspot_tethering" />
- </PreferenceCategory>
-
- <Preference
- android:key="disabled_on_data_saver_2"
- android:summary="@string/tether_settings_disabled_on_data_saver"
- android:selectable="false"
- settings:searchable="false"
- settings:allowDividerAbove="true" />
-
- <com.android.settingslib.widget.FooterPreference
- android:key="tether_prefs_footer_2"
- android:selectable="false"
- settings:searchable="false"/>
-</PreferenceScreen>
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index e7170ca..f1c62bb 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -24,19 +24,22 @@
android:key="auto_time"
android:title="@string/date_time_auto"
settings:useAdditionalSummary="true"
- settings:userRestriction="no_config_date_time"/>
+ settings:userRestriction="no_config_date_time"
+ settings:controller="com.android.settings.datetime.AutoTimePreferenceController" />
<com.android.settingslib.RestrictedPreference
android:key="date"
android:title="@string/date_time_set_date_title"
android:summary="@string/summary_placeholder"
- settings:userRestriction="no_config_date_time"/>
+ settings:userRestriction="no_config_date_time"
+ settings:controller="com.android.settings.datetime.DatePreferenceController" />
<com.android.settingslib.RestrictedPreference
android:key="time"
android:title="@string/date_time_set_time_title"
android:summary="@string/summary_placeholder"
- settings:userRestriction="no_config_date_time"/>
+ settings:userRestriction="no_config_date_time"
+ settings:controller="com.android.settings.datetime.TimePreferenceController" />
<PreferenceCategory
android:key="timezone_preference_category"
@@ -45,7 +48,8 @@
<com.android.settingslib.RestrictedSwitchPreference
android:key="auto_zone"
android:title="@string/zone_auto_title"
- settings:userRestriction="no_config_date_time"/>
+ settings:userRestriction="no_config_date_time"
+ settings:controller="com.android.settings.datetime.AutoTimeZonePreferenceController" />
<com.android.settingslib.widget.BannerMessagePreference
android:key="location_time_zone_detection_status"
@@ -53,7 +57,7 @@
settings:controller="com.android.settings.datetime.LocationProviderStatusPreferenceController"/>
<!-- This preference gets removed if location-based time zone detection is not supported -->
- <SwitchPreferenceCompat
+ <SwitchPreference
android:key="location_time_zone_detection"
android:title="@string/location_time_zone_detection_toggle_title"
settings:controller="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceController"/>
@@ -64,7 +68,8 @@
android:summary="@string/summary_placeholder"
android:fragment="com.android.settings.datetime.timezone.TimeZoneSettings"
settings:userRestriction="no_config_date_time"
- settings:keywords="@string/keywords_time_zone"/>
+ settings:keywords="@string/keywords_time_zone"
+ settings:controller="com.android.settings.datetime.TimeZonePreferenceController" />
</PreferenceCategory>
@@ -72,13 +77,15 @@
android:key="time_format_preference_category"
android:title="@string/time_format_category_title"
settings:keywords="@string/keywords_time_format">
- <SwitchPreferenceCompat
+ <SwitchPreference
android:key="auto_24hour"
- android:title="@string/date_time_24hour_auto"/>
+ android:title="@string/date_time_24hour_auto"
+ settings:controller="com.android.settings.datetime.AutoTimeFormatPreferenceController" />
- <SwitchPreferenceCompat
+ <SwitchPreference
android:key="24 hour"
- android:title="@string/date_time_24hour" />
+ android:title="@string/date_time_24hour"
+ settings:controller="com.android.settings.datetime.TimeFormatPreferenceController" />
</PreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/development_app_picker.xml b/res/xml/development_app_picker.xml
new file mode 100644
index 0000000..15e4ce0
--- /dev/null
+++ b/res/xml/development_app_picker.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2023 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/>
diff --git a/res/xml/network_provider_internet.xml b/res/xml/network_provider_internet.xml
index 8e9d45d..cd44ab1 100644
--- a/res/xml/network_provider_internet.xml
+++ b/res/xml/network_provider_internet.xml
@@ -65,18 +65,7 @@
android:icon="@drawable/ic_wifi_tethering"
android:order="5"
android:summary="@string/summary_placeholder"
- settings:keywords="@string/keywords_hotspot_tethering"
- settings:userRestriction="no_config_tethering"
- settings:useAdminDisabledSummary="true" />
-
- <com.android.settingslib.PrimarySwitchPreference
- android:fragment="com.android.settings.AllInOneTetherSettings"
- android:key="all_tether_settings"
- android:title="@string/tether_settings_title_all"
- android:icon="@drawable/ic_wifi_tethering"
- android:order="6"
- android:summary="@string/summary_placeholder"
- settings:controller="com.android.settings.network.AllInOneTetherPreferenceController"
+ settings:controller="com.android.settings.network.TetherPreferenceController"
settings:keywords="@string/keywords_hotspot_tethering"
settings:userRestriction="no_config_tethering"
settings:useAdminDisabledSummary="true" />
diff --git a/src/com/android/settings/AllInOneTetherSettings.java b/src/com/android/settings/AllInOneTetherSettings.java
deleted file mode 100644
index b3644f8..0000000
--- a/src/com/android/settings/AllInOneTetherSettings.java
+++ /dev/null
@@ -1,444 +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;
-
-import static android.net.ConnectivityManager.TETHERING_WIFI;
-import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
-import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
-
-import android.app.settings.SettingsEnums;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.wifi.SoftApConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.os.UserManager;
-import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceGroup;
-
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.dashboard.RestrictedDashboardFragment;
-import com.android.settings.datausage.DataSaverBackend;
-import com.android.settings.network.BluetoothTetherPreferenceController;
-import com.android.settings.network.EthernetTetherPreferenceController;
-import com.android.settings.network.TetherEnabler;
-import com.android.settings.network.UsbTetherPreferenceController;
-import com.android.settings.network.WifiTetherDisablePreferenceController;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.widget.MainSwitchBarController;
-import com.android.settings.widget.SettingsMainSwitchBar;
-import com.android.settings.wifi.tether.WifiTetherApBandPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherBasePreferenceController;
-import com.android.settings.wifi.tether.WifiTetherFooterPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherPasswordPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherSSIDPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
-import com.android.settingslib.TetherUtil;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.search.SearchIndexable;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Displays preferences for all Tethering options.
- */
-@SearchIndexable
-public class AllInOneTetherSettings extends RestrictedDashboardFragment
- implements DataSaverBackend.Listener,
- WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
-
- // TODO(b/148622133): Should clean up the postfix once this fragment replaced TetherSettings.
- public static final String DEDUP_POSTFIX = "_2";
-
- @VisibleForTesting
- static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name" + DEDUP_POSTFIX;
- @VisibleForTesting
- static final String KEY_WIFI_TETHER_NETWORK_PASSWORD =
- "wifi_tether_network_password" + DEDUP_POSTFIX;
- @VisibleForTesting
- static final String KEY_WIFI_TETHER_AUTO_OFF = "wifi_tether_auto_turn_off" + DEDUP_POSTFIX;
- @VisibleForTesting
- static final String KEY_WIFI_TETHER_NETWORK_AP_BAND =
- "wifi_tether_network_ap_band" + DEDUP_POSTFIX;
- @VisibleForTesting
- static final String KEY_WIFI_TETHER_SECURITY = "wifi_tether_security" + DEDUP_POSTFIX;
-
- private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX;
- private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group";
- public static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
- public static final String USB_TETHER_KEY = "enable_usb_tethering";
- public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
- public static final String ETHERNET_TETHER_KEY = "enable_ethernet_tethering" + DEDUP_POSTFIX;
-
- @VisibleForTesting
- static final int EXPANDED_CHILD_COUNT_DEFAULT = 4;
- @VisibleForTesting
- static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 3;
- @VisibleForTesting
- static final int EXPANDED_CHILD_COUNT_MAX = Integer.MAX_VALUE;
- private static final String TAG = "AllInOneTetherSettings";
-
- private boolean mUnavailable;
-
- private DataSaverBackend mDataSaverBackend;
- private boolean mDataSaverEnabled;
- private Preference mDataSaverFooter;
-
- private WifiManager mWifiManager;
- private boolean mRestartWifiApAfterConfigChange;
- private final AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<>();
-
- private WifiTetherSSIDPreferenceController mSSIDPreferenceController;
- private WifiTetherPasswordPreferenceController mPasswordPreferenceController;
- private WifiTetherApBandPreferenceController mApBandPreferenceController;
- private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
- private PreferenceGroup mWifiTetherGroup;
- private boolean mShouldShowWifiConfig = true;
- private boolean mHasShownAdvance;
- private TetherEnabler mTetherEnabler;
- @VisibleForTesting
- final TetherEnabler.OnTetherStateUpdateListener mStateUpdateListener =
- state -> {
- mShouldShowWifiConfig = TetherEnabler.isTethering(state, TETHERING_WIFI)
- || state == TetherEnabler.TETHERING_OFF;
- getPreferenceScreen().setInitialExpandedChildrenCount(
- getInitialExpandedChildCount());
- mWifiTetherGroup.setVisible(mShouldShowWifiConfig);
- };
-
- private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context content, Intent intent) {
- String action = intent.getAction();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG,
- "updating display config due to receiving broadcast action " + action);
- }
- updateDisplayWithNewConfig();
- if (TextUtils.equals(action, ACTION_TETHER_STATE_CHANGED)) {
- restartWifiTetherIfNeed(mWifiManager.getWifiApState());
- } else if (TextUtils.equals(action, WIFI_AP_STATE_CHANGED_ACTION)) {
- restartWifiTetherIfNeed(intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0));
- }
- }
-
- private void restartWifiTetherIfNeed(int state) {
- if (state == WifiManager.WIFI_AP_STATE_DISABLED
- && mRestartWifiApAfterConfigChange) {
- mRestartWifiApAfterConfigChange = false;
- mTetherEnabler.startTethering(TETHERING_WIFI);
- }
- }
- };
-
- private final BluetoothProfile.ServiceListener mProfileServiceListener =
- new BluetoothProfile.ServiceListener() {
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- mBluetoothPan.set((BluetoothPan) proxy);
- }
-
- public void onServiceDisconnected(int profile) {
- mBluetoothPan.set(null);
- }
- };
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.TETHER;
- }
-
- public AllInOneTetherSettings() {
- super(UserManager.DISALLOW_CONFIG_TETHERING);
- }
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-
- mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);
- mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
- mPasswordPreferenceController = use(WifiTetherPasswordPreferenceController.class);
- mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
- getSettingsLifecycle().addObserver(use(UsbTetherPreferenceController.class));
- getSettingsLifecycle().addObserver(use(BluetoothTetherPreferenceController.class));
- getSettingsLifecycle().addObserver(use(EthernetTetherPreferenceController.class));
- getSettingsLifecycle().addObserver(use(WifiTetherDisablePreferenceController.class));
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- mDataSaverBackend = new DataSaverBackend(getContext());
- mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
- mDataSaverFooter = findPreference(KEY_DATA_SAVER_FOOTER);
- mWifiTetherGroup = findPreference(KEY_WIFI_TETHER_GROUP);
-
- setIfOnlyAvailableForAdmins(true);
- if (isUiRestricted()) {
- mUnavailable = true;
- return;
- }
-
- mDataSaverBackend.addListener(this);
-
- // Set initial state based on Data Saver mode.
- onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (mUnavailable) {
- return;
- }
- // Assume we are in a SettingsActivity. This is only safe because we currently use
- // SettingsActivity as base for all preference fragments.
- final SettingsActivity activity = (SettingsActivity) getActivity();
- final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- if (adapter != null) {
- adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener,
- BluetoothProfile.PAN);
- }
- final SettingsMainSwitchBar mainSwitch = activity.getSwitchBar();
- mTetherEnabler = new TetherEnabler(activity,
- new MainSwitchBarController(mainSwitch), mBluetoothPan);
- getSettingsLifecycle().addObserver(mTetherEnabler);
- use(UsbTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
- use(BluetoothTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
- use(EthernetTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
- use(WifiTetherDisablePreferenceController.class).setTetherEnabler(mTetherEnabler);
- mainSwitch.show();
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- if (mUnavailable) {
- if (!isUiRestrictedByOnlyAdmin()) {
- getEmptyTextView().setText(
- com.android.settingslib.R.string.tethering_settings_not_available);
- }
- getPreferenceScreen().removeAll();
- return;
- }
- final Context context = getContext();
- if (context != null) {
- // The intent WIFI_AP_STATE_CHANGED_ACTION is not sticky intent after SC-V2
- // But ACTION_TETHER_STATE_CHANGED is still sticky intent. So no need to handle
- // initial state for WIFI_AP_STATE_CHANGED_ACTION
- IntentFilter filter = new IntentFilter(ACTION_TETHER_STATE_CHANGED);
- filter.addAction(WIFI_AP_STATE_CHANGED_ACTION);
- context.registerReceiver(mTetherChangeReceiver, filter);
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mUnavailable) {
- return;
- }
- if (mTetherEnabler != null) {
- mTetherEnabler.addListener(mStateUpdateListener);
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- if (mUnavailable) {
- return;
- }
- if (mTetherEnabler != null) {
- mTetherEnabler.removeListener(mStateUpdateListener);
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
- if (mUnavailable) {
- return;
- }
- final Context context = getContext();
- if (context != null) {
- context.unregisterReceiver(mTetherChangeReceiver);
- }
- }
-
- @Override
- public void onDestroy() {
- mDataSaverBackend.remListener(this);
- super.onDestroy();
- }
-
- @Override
- public void onDataSaverChanged(boolean isDataSaving) {
- mDataSaverEnabled = isDataSaving;
- mDataSaverFooter.setVisible(mDataSaverEnabled);
- }
-
- @Override
- public void onAllowlistStatusChanged(int uid, boolean isAllowlisted) {
- // Do nothing
- }
-
- @Override
- public void onDenylistStatusChanged(int uid, boolean isDenylisted) {
- // Do nothing
- }
-
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, this);
- }
-
- private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
- WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(
- new WifiTetherSSIDPreferenceController(context, listener));
- controllers.add(
- new WifiTetherPasswordPreferenceController(context, listener));
- controllers.add(
- new WifiTetherApBandPreferenceController(context, listener));
- controllers.add(
- new WifiTetherSecurityPreferenceController(context, listener));
- controllers.add(
- new WifiTetherAutoOffPreferenceController(context, KEY_WIFI_TETHER_AUTO_OFF));
- controllers.add(
- new WifiTetherFooterPreferenceController(context));
-
- return controllers;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.all_tether_prefs;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- public int getHelpResource() {
- return R.string.help_url_tether;
- }
-
- @Override
- public void onTetherConfigUpdated(AbstractPreferenceController controller) {
- final SoftApConfiguration config = buildNewConfig();
- mPasswordPreferenceController.setSecurityType(config.getSecurityType());
- mWifiManager.setSoftApConfiguration(config);
-
- if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Wifi AP config changed while enabled, stop and restart");
- }
- mRestartWifiApAfterConfigChange = true;
- mTetherEnabler.stopTethering(TETHERING_WIFI);
- }
- }
-
- private SoftApConfiguration buildNewConfig() {
- final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
- final int securityType = mSecurityPreferenceController.getSecurityType();
- configBuilder.setSsid(mSSIDPreferenceController.getSSID());
- if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
- configBuilder.setPassphrase(
- mPasswordPreferenceController.getPasswordValidated(securityType),
- SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
- }
- configBuilder.setBand(mApBandPreferenceController.getBandIndex());
- return configBuilder.build();
- }
-
- private void updateDisplayWithNewConfig() {
- mSSIDPreferenceController.updateDisplay();
- mSecurityPreferenceController.updateDisplay();
- mPasswordPreferenceController.updateDisplay();
- mApBandPreferenceController.updateDisplay();
- }
-
- @Override
- public int getInitialExpandedChildCount() {
- if (mHasShownAdvance || !mShouldShowWifiConfig) {
- mHasShownAdvance = true;
- return EXPANDED_CHILD_COUNT_MAX;
- }
-
- if (mSecurityPreferenceController == null) {
- return EXPANDED_CHILD_COUNT_DEFAULT;
- }
-
- return (mSecurityPreferenceController.getSecurityType()
- == SoftApConfiguration.SECURITY_TYPE_OPEN)
- ? EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
- }
-
- @Override
- public void onExpandButtonClick() {
- super.onExpandButtonClick();
- mHasShownAdvance = true;
- }
-
- public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.all_tether_prefs) {
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = super.getNonIndexableKeys(context);
-
- if (!TetherUtil.isTetherAvailable(context)) {
- keys.add(KEY_WIFI_TETHER_NETWORK_NAME);
- keys.add(KEY_WIFI_TETHER_NETWORK_PASSWORD);
- keys.add(KEY_WIFI_TETHER_AUTO_OFF);
- keys.add(KEY_WIFI_TETHER_NETWORK_AP_BAND);
- keys.add(KEY_WIFI_TETHER_SECURITY);
- }
- return keys;
- }
-
- @Override
- protected boolean isPageSearchEnabled(Context context) {
- return FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
- }
-
- @Override
- public List<AbstractPreferenceController> createPreferenceControllers(
- Context context) {
- return buildPreferenceControllers(context, null /*listener*/);
- }
- };
-}
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 64e3244..68ae0ae 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -19,18 +19,15 @@
import static android.provider.Settings.ACTION_PRIVACY_SETTINGS;
import android.content.ActivityNotFoundException;
-import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.ims.ImsRcsManager;
import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.biometrics.face.FaceSettings;
import com.android.settings.communal.CommunalPreferenceController;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.network.MobileNetworkIntentConverter;
import com.android.settings.overlay.FeatureFactory;
@@ -58,42 +55,8 @@
public static class FingerprintSettingsActivityV2 extends SettingsActivity { /* empty */ }
public static class CombinedBiometricSettingsActivity extends SettingsActivity { /* empty */ }
public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
- public static class TetherSettingsActivity extends SettingsActivity {
- // TODO(b/147675042): Clean the override up when we enable the new Fragment persistently.
- @Override
- public Intent getIntent() {
- return wrapIntentWithAllInOneTetherSettingsIfNeeded(
- getApplicationContext(), super.getIntent());
- }
- }
- public static class WifiTetherSettingsActivity extends SettingsActivity {
- // TODO(b/147675042): Clean the override up when we enable the new Fragment persistently.
- @Override
- public Intent getIntent() {
- return wrapIntentWithAllInOneTetherSettingsIfNeeded(
- getApplicationContext(), super.getIntent());
- }
- }
-
- private static Intent wrapIntentWithAllInOneTetherSettingsIfNeeded(
- Context context, Intent superIntent) {
- if (!FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE)) {
- return superIntent;
- }
-
- final Intent modIntent = new Intent(superIntent);
- modIntent.putExtra(EXTRA_SHOW_FRAGMENT,
- AllInOneTetherSettings.class.getCanonicalName());
- Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
- if (args != null) {
- args = new Bundle(args);
- } else {
- args = new Bundle();
- }
- args.putParcelable("intent", superIntent);
- modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
- return modIntent;
- }
+ public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
+ public static class WifiTetherSettingsActivity extends SettingsActivity { /* empty */ }
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
/** Activity for Data saver settings. */
diff --git a/src/com/android/settings/applications/credentials/CombinedProviderInfo.java b/src/com/android/settings/applications/credentials/CombinedProviderInfo.java
index 074fb7b..e8541389 100644
--- a/src/com/android/settings/applications/credentials/CombinedProviderInfo.java
+++ b/src/com/android/settings/applications/credentials/CombinedProviderInfo.java
@@ -82,6 +82,37 @@
return mAutofillServiceInfo.getServiceInfo().applicationInfo;
}
+ /** Returns the package name. */
+ public @Nullable String getPackageName() {
+ ApplicationInfo ai = getApplicationInfo();
+ if (ai != null) {
+ return ai.packageName;
+ }
+
+ return null;
+ }
+
+ /** Returns the settings activity. */
+ public @Nullable String getSettingsActivity() {
+ // This logic is not used by the top entry but rather what activity should
+ // be launched from the settings screen.
+ for (CredentialProviderInfo cpi : mCredentialProviderInfos) {
+ final CharSequence settingsActivity = cpi.getSettingsActivity();
+ if (!TextUtils.isEmpty(settingsActivity)) {
+ return String.valueOf(settingsActivity);
+ }
+ }
+
+ if (mAutofillServiceInfo != null) {
+ final String settingsActivity = mAutofillServiceInfo.getSettingsActivity();
+ if (!TextUtils.isEmpty(settingsActivity)) {
+ return settingsActivity;
+ }
+ }
+
+ return null;
+ }
+
/** Returns the app icon. */
@Nullable
public Drawable getAppIcon(@NonNull Context context, int userId) {
diff --git a/src/com/android/settings/applications/credentials/CredentialsPickerActivity.java b/src/com/android/settings/applications/credentials/CredentialsPickerActivity.java
new file mode 100644
index 0000000..495c104
--- /dev/null
+++ b/src/com/android/settings/applications/credentials/CredentialsPickerActivity.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2023 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.credentials;
+
+
+import com.android.settings.SettingsActivity;
+
+/** Standalone activity used to launch a {@link DefaultCombinedPicker} fragment. */
+public class CredentialsPickerActivity extends SettingsActivity {
+
+ @Override
+ protected boolean isValidFragment(String fragmentName) {
+ return super.isValidFragment(fragmentName)
+ || DefaultCombinedPicker.class.getName().equals(fragmentName);
+ }
+}
diff --git a/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceController.java b/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceController.java
index 59c33b2..47a89ec 100644
--- a/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceController.java
+++ b/src/com/android/settings/applications/credentials/DefaultCombinedPreferenceController.java
@@ -16,11 +16,10 @@
package com.android.settings.applications.credentials;
+import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.credentials.CredentialManager;
import android.credentials.CredentialProviderInfo;
@@ -29,16 +28,19 @@
import android.service.autofill.AutofillService;
import android.service.autofill.AutofillServiceInfo;
import android.text.TextUtils;
-import android.util.Log;
import android.view.autofill.AutofillManager;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
import com.android.settingslib.applications.DefaultAppInfo;
import java.util.ArrayList;
import java.util.List;
-public class DefaultCombinedPreferenceController extends DefaultAppPreferenceController {
+public class DefaultCombinedPreferenceController extends DefaultAppPreferenceController
+ implements Preference.OnPreferenceClickListener {
private static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);
private static final String TAG = "DefaultCombinedPreferenceController";
@@ -73,18 +75,55 @@
@Override
protected Intent getSettingIntent(DefaultAppInfo info) {
- if (info == null) {
- return null;
+ // Despite this method being called getSettingIntent this intent actually
+ // opens the primary picker. This is so that we can swap the cog and the left
+ // hand side presses to align the UX.
+ return new Intent(mContext, CredentialsPickerActivity.class);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ final String prefKey = getPreferenceKey();
+ final Preference preference = screen.findPreference(prefKey);
+ if (preference != null) {
+ preference.setOnPreferenceClickListener((Preference.OnPreferenceClickListener) this);
}
- final AutofillSettingIntentProvider intentProvider =
- new AutofillSettingIntentProvider(mContext, getUser(), info.getKey());
- return intentProvider.getIntent();
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ // Get the selected provider.
+ final CombinedProviderInfo topProvider = getTopProvider();
+ if (topProvider == null) {
+ return false;
+ }
+
+ // If the top provider has a defined Credential Manager settings
+ // provider then we should open that up.
+ final String settingsActivity = topProvider.getSettingsActivity();
+ if (!TextUtils.isEmpty(settingsActivity)) {
+ final Intent intent =
+ new Intent(Intent.ACTION_MAIN)
+ .setComponent(
+ new ComponentName(
+ topProvider.getPackageName(), settingsActivity));
+ startActivity(intent);
+ return true;
+ }
+
+ return false;
+ }
+
+ private @Nullable CombinedProviderInfo getTopProvider() {
+ List<CombinedProviderInfo> providers = getAllProviders(getUser());
+ return CombinedProviderInfo.getTopProvider(providers);
}
@Override
protected DefaultAppInfo getDefaultAppInfo() {
- List<CombinedProviderInfo> providers = getAllProviders(getUser());
- CombinedProviderInfo topProvider = CombinedProviderInfo.getTopProvider(providers);
+ CombinedProviderInfo topProvider = getTopProvider();
if (topProvider != null) {
ServiceInfo brandingService = topProvider.getBrandingService();
if (brandingService == null) {
@@ -138,53 +177,6 @@
return true;
}
- /** Provides Intent to setting activity for the specified autofill service. */
- static final class AutofillSettingIntentProvider {
-
- private final String mKey;
- private final Context mContext;
- private final int mUserId;
-
- public AutofillSettingIntentProvider(Context context, int userId, String key) {
- mKey = key;
- mContext = context;
- mUserId = userId;
- }
-
- public Intent getIntent() {
- final List<ResolveInfo> resolveInfos =
- mContext.getPackageManager()
- .queryIntentServicesAsUser(
- AUTOFILL_PROBE, PackageManager.GET_META_DATA, mUserId);
-
- for (ResolveInfo resolveInfo : resolveInfos) {
- final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
-
- // If there are multiple autofill services then pick the first one.
- if (mKey != null && mKey.startsWith(serviceInfo.packageName)) {
- final String settingsActivity;
- try {
- settingsActivity =
- new AutofillServiceInfo(mContext, serviceInfo)
- .getSettingsActivity();
- } catch (SecurityException e) {
- // Service does not declare the proper permission, ignore it.
- Log.e(TAG, "Error getting info for " + serviceInfo + ": " + e);
- return null;
- }
- if (TextUtils.isEmpty(settingsActivity)) {
- return null;
- }
- return new Intent(Intent.ACTION_MAIN)
- .setComponent(
- new ComponentName(serviceInfo.packageName, settingsActivity));
- }
- }
-
- return null;
- }
- }
-
protected int getUser() {
return UserHandle.myUserId();
}
diff --git a/src/com/android/settings/applications/credentials/DefaultPrivateCombinedPreferenceController.kt b/src/com/android/settings/applications/credentials/DefaultPrivateCombinedPreferenceController.kt
index d606f3c..990e221 100644
--- a/src/com/android/settings/applications/credentials/DefaultPrivateCombinedPreferenceController.kt
+++ b/src/com/android/settings/applications/credentials/DefaultPrivateCombinedPreferenceController.kt
@@ -36,15 +36,6 @@
return "default_credman_autofill_private"
}
- override fun getSettingIntent(info: DefaultAppInfo ?): Intent ? {
- if (info == null) {
- return null
- }
- return userHandle?.let { handle ->
- AutofillSettingIntentProvider(mContext, handle.identifier, info.key).intent
- } ?: null
- }
-
override fun startActivity(intent: Intent) {
userHandle?.let { handle ->
mContext.startActivityAsUser(intent, handle)
diff --git a/src/com/android/settings/applications/credentials/DefaultWorkCombinedPreferenceController.java b/src/com/android/settings/applications/credentials/DefaultWorkCombinedPreferenceController.java
index eb0aa7a..f7ca204 100644
--- a/src/com/android/settings/applications/credentials/DefaultWorkCombinedPreferenceController.java
+++ b/src/com/android/settings/applications/credentials/DefaultWorkCombinedPreferenceController.java
@@ -21,7 +21,6 @@
import android.os.UserHandle;
import com.android.settings.Utils;
-import com.android.settingslib.applications.DefaultAppInfo;
public class DefaultWorkCombinedPreferenceController extends DefaultCombinedPreferenceController {
private final UserHandle mUserHandle;
@@ -45,17 +44,6 @@
}
@Override
- protected Intent getSettingIntent(DefaultAppInfo info) {
- if (info == null) {
- return null;
- }
- final AutofillSettingIntentProvider intentProvider =
- new AutofillSettingIntentProvider(
- mContext, mUserHandle.getIdentifier(), info.getKey());
- return intentProvider.getIntent();
- }
-
- @Override
protected void startActivity(Intent intent) {
mContext.startActivityAsUser(intent, mUserHandle);
}
diff --git a/src/com/android/settings/applications/specialaccess/PaymentSettingsEnabler.java b/src/com/android/settings/applications/specialaccess/PaymentSettingsEnabler.java
index e378eb3..b95da80 100644
--- a/src/com/android/settings/applications/specialaccess/PaymentSettingsEnabler.java
+++ b/src/com/android/settings/applications/specialaccess/PaymentSettingsEnabler.java
@@ -17,7 +17,6 @@
package com.android.settings.applications.specialaccess;
import android.content.Context;
-import android.nfc.Flags;
import android.nfc.NfcAdapter;
import android.nfc.cardemulation.CardEmulation;
import android.os.UserHandle;
@@ -67,12 +66,8 @@
}
private boolean hasAnyServices() {
- if (Flags.enableNfcMainline()) {
- return mCardEmuManager.getServices(
- CardEmulation.CATEGORY_PAYMENT, UserHandle.myUserId()).isEmpty();
- } else {
- return mCardEmuManager.getServices(CardEmulation.CATEGORY_PAYMENT).isEmpty();
- }
+ return mCardEmuManager.getServices(
+ CardEmulation.CATEGORY_PAYMENT, UserHandle.myUserId()).isEmpty();
}
@Override
diff --git a/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java b/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
index 4d92598..2eee9df 100644
--- a/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
+++ b/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtils.java
@@ -191,13 +191,10 @@
public String getIntroForActiveUnlock() {
final boolean faceAllowed = Utils.hasFaceHardware(mContext);
final boolean fingerprintAllowed = Utils.hasFingerprintHardware(mContext);
- if (useBiometricFailureLayout()) {
+ if (isAvailable()) {
int introRes = getIntroRes(faceAllowed, fingerprintAllowed);
return introRes == 0 ? "" : mContext.getString(introRes);
}
- if (useUnlockIntentLayout() && (!faceAllowed || !fingerprintAllowed)) {
- return "";
- }
return mContext.getString(R.string.biometric_settings_intro);
}
diff --git a/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollHelper.java b/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollHelper.java
index 0bfb87d..d3bc977 100644
--- a/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollHelper.java
+++ b/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollHelper.java
@@ -182,7 +182,7 @@
* Called when a fingerprint image has been acquired, but wasn't processed yet.
*/
public void onAcquired(boolean isAcquiredGood) {
- if (mListener != null && mTotalSteps != -1) {
+ if (mListener != null) {
mListener.onAcquired(isAcquiredGood && animateIfLastStep());
}
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java
index 21f1c0e..90cf779 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java
@@ -16,8 +16,12 @@
package com.android.settings.connecteddevice.audiosharing;
+import android.bluetooth.BluetoothAdapter;
import android.content.Context;
+import androidx.annotation.NonNull;
+import androidx.lifecycle.DefaultLifecycleObserver;
+import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -26,14 +30,18 @@
import com.android.settings.flags.Flags;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.utils.ThreadUtils;
-public abstract class AudioSharingBasePreferenceController extends BasePreferenceController {
+public abstract class AudioSharingBasePreferenceController extends BasePreferenceController
+ implements DefaultLifecycleObserver {
+ private final BluetoothAdapter mBluetoothAdapter;
private final LocalBluetoothManager mBtManager;
protected final LocalBluetoothLeBroadcast mBroadcast;
protected Preference mPreference;
public AudioSharingBasePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBtManager = Utils.getLocalBtManager(context);
mBroadcast =
mBtManager == null
@@ -43,28 +51,40 @@
@Override
public int getAvailabilityStatus() {
- return mBtManager != null && Flags.enableLeAudioSharing()
- ? AVAILABLE
- : UNSUPPORTED_ON_DEVICE;
+ return Flags.enableLeAudioSharing() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
- updateVisibility(isBroadcasting());
}
- /**
- * Update the visibility of the preference.
- *
- * @param isVisible the latest visibility state for the preference.
- */
- public void updateVisibility(boolean isVisible) {
- mPreference.setVisible(isVisible);
+ @Override
+ public void onStart(@NonNull LifecycleOwner owner) {
+ if (isAvailable()) {
+ updateVisibility();
+ }
+ }
+
+ /** Update the visibility of the preference. */
+ protected void updateVisibility() {
+ if (mPreference != null) {
+ var unused =
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ boolean isVisible = isBroadcasting() && isBluetoothStateOn();
+ ThreadUtils.postOnMainThread(
+ () -> mPreference.setVisible(isVisible));
+ });
+ }
}
protected boolean isBroadcasting() {
return mBroadcast != null && mBroadcast.isEnabled(null);
}
+
+ protected boolean isBluetoothStateOn() {
+ return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
+ }
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
index 7f90ceb..52a8f18 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
@@ -93,14 +93,14 @@
}
@Override
- public void onSwitchBarChanged(boolean newState) {
- updateVisibilityForAttachedPreferences(newState);
+ public void onSwitchBarChanged() {
+ updateVisibilityForAttachedPreferences();
}
- private void updateVisibilityForAttachedPreferences(boolean isVisible) {
- mAudioSharingDeviceVolumeGroupController.updateVisibility(isVisible);
- mCallsAndAlarmsPreferenceController.updateVisibility(isVisible);
- mAudioSharingNamePreferenceController.updateVisibility(isVisible);
- mAudioStreamsCategoryController.updateVisibility(isVisible);
+ private void updateVisibilityForAttachedPreferences() {
+ mAudioSharingDeviceVolumeGroupController.updateVisibility();
+ mCallsAndAlarmsPreferenceController.updateVisibility();
+ mAudioSharingNamePreferenceController.updateVisibility();
+ mAudioStreamsCategoryController.updateVisibility();
}
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
index 90054d4..bdaa534 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java
@@ -27,7 +27,6 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
-import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
@@ -48,7 +47,7 @@
import java.util.concurrent.Executors;
public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePreferenceController
- implements DefaultLifecycleObserver, DevicePreferenceCallback {
+ implements DevicePreferenceCallback {
private static final String TAG = "AudioSharingDeviceVolumeGroupController";
private static final String KEY = "audio_sharing_device_volume_group";
@@ -162,6 +161,7 @@
@Override
public void onStart(@NonNull LifecycleOwner owner) {
+ super.onStart(owner);
if (mAssistant == null) {
Log.d(TAG, "onStart() Broadcast or assistant is not supported on this device");
return;
@@ -176,6 +176,7 @@
@Override
public void onStop(@NonNull LifecycleOwner owner) {
+ super.onStop(owner);
if (mAssistant == null) {
Log.d(TAG, "onStop() Broadcast or assistant is not supported on this device");
return;
@@ -233,10 +234,12 @@
}
@Override
- public void updateVisibility(boolean isVisible) {
- super.updateVisibility(isVisible);
+ public void updateVisibility() {
if (mPreferenceGroup != null) {
- mPreferenceGroup.setVisible(mPreferenceGroup.getPreferenceCount() > 0);
+ mPreferenceGroup.setVisible(false);
+ if (mPreferenceGroup.getPreferenceCount() > 0) {
+ super.updateVisibility();
+ }
}
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java
index 8336691..36f66ff 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java
@@ -19,16 +19,13 @@
import android.content.Context;
import androidx.annotation.NonNull;
-import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import com.android.settings.widget.ValidatedEditTextPreference;
public class AudioSharingNamePreferenceController extends AudioSharingBasePreferenceController
- implements ValidatedEditTextPreference.Validator,
- Preference.OnPreferenceChangeListener,
- DefaultLifecycleObserver {
+ implements ValidatedEditTextPreference.Validator, Preference.OnPreferenceChangeListener {
private static final String TAG = "AudioSharingNamePreferenceController";
@@ -59,11 +56,13 @@
@Override
public void onStart(@NonNull LifecycleOwner owner) {
+ super.onStart(owner);
// TODO
}
@Override
public void onStop(@NonNull LifecycleOwner owner) {
+ super.onStop(owner);
// TODO
}
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
index be02519..469a387 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java
@@ -16,17 +16,22 @@
package com.android.settings.connecteddevice.audiosharing;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcast;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@@ -54,16 +59,32 @@
private static final String PREF_KEY = "audio_sharing_main_switch";
interface OnSwitchBarChangedListener {
- void onSwitchBarChanged(boolean newState);
+ void onSwitchBarChanged();
}
private final SettingsMainSwitchBar mSwitchBar;
+ private final BluetoothAdapter mBluetoothAdapter;
private final LocalBluetoothManager mBtManager;
private final LocalBluetoothLeBroadcast mBroadcast;
private final LocalBluetoothLeBroadcastAssistant mAssistant;
private final Executor mExecutor;
private final OnSwitchBarChangedListener mListener;
private DashboardFragment mFragment;
+ @VisibleForTesting IntentFilter mIntentFilter;
+
+ @VisibleForTesting
+ BroadcastReceiver mReceiver =
+ new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) return;
+ int adapterState =
+ intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR);
+ mSwitchBar.setChecked(isBroadcasting());
+ mSwitchBar.setEnabled(adapterState == BluetoothAdapter.STATE_ON);
+ mListener.onSwitchBarChanged();
+ }
+ };
private final BluetoothLeBroadcast.Callback mBroadcastCallback =
new BluetoothLeBroadcast.Callback() {
@@ -245,27 +266,34 @@
super(context, PREF_KEY);
mSwitchBar = switchBar;
mListener = listener;
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
mBtManager = Utils.getLocalBtManager(context);
mBroadcast = mBtManager.getProfileManager().getLeAudioBroadcastProfile();
mAssistant = mBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
mExecutor = Executors.newSingleThreadExecutor();
- mSwitchBar.setChecked(isBroadcasting());
}
@Override
public void onStart(@NonNull LifecycleOwner owner) {
mSwitchBar.addOnSwitchChangeListener(this);
+ mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED);
if (mBroadcast != null) {
mBroadcast.registerServiceCallBack(mExecutor, mBroadcastCallback);
}
if (mAssistant != null) {
mAssistant.registerServiceCallBack(mExecutor, mBroadcastAssistantCallback);
}
+ if (isAvailable()) {
+ mSwitchBar.setChecked(isBroadcasting());
+ mSwitchBar.setEnabled(mBluetoothAdapter != null && mBluetoothAdapter.isEnabled());
+ }
}
@Override
public void onStop(@NonNull LifecycleOwner owner) {
mSwitchBar.removeOnSwitchChangeListener(this);
+ mContext.unregisterReceiver(mReceiver);
if (mBroadcast != null) {
mBroadcast.unregisterServiceCallBack(mBroadcastCallback);
}
@@ -321,15 +349,19 @@
}
private void updateSwitch() {
- ThreadUtils.postOnMainThread(
- () -> {
- boolean isBroadcasting = isBroadcasting();
- if (mSwitchBar.isChecked() != isBroadcasting) {
- mSwitchBar.setChecked(isBroadcasting);
- }
- mSwitchBar.setEnabled(true);
- mListener.onSwitchBarChanged(isBroadcasting);
- });
+ var unused =
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ boolean isBroadcasting = isBroadcasting();
+ ThreadUtils.postOnMainThread(
+ () -> {
+ if (mSwitchBar.isChecked() != isBroadcasting) {
+ mSwitchBar.setChecked(isBroadcasting);
+ }
+ mSwitchBar.setEnabled(true);
+ mListener.onSwitchBarChanged();
+ });
+ });
}
private boolean isBroadcasting() {
@@ -351,7 +383,7 @@
TAG,
"Add broadcast with broadcastId: "
+ broadcastMetadata.getBroadcastId()
- + "to the device: "
+ + " to the device: "
+ sink.getAnonymizedAddress());
mAssistant.addSource(sink, broadcastMetadata, /* isGroupOp= */ false);
}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java
index a6adf8a..b3d676c 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java
@@ -22,7 +22,6 @@
import android.util.Log;
import androidx.annotation.NonNull;
-import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen;
@@ -31,6 +30,7 @@
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.HashMap;
@@ -39,7 +39,7 @@
/** PreferenceController to control the dialog to choose the active device for calls and alarms */
public class CallsAndAlarmsPreferenceController extends AudioSharingBasePreferenceController
- implements BluetoothCallback, DefaultLifecycleObserver {
+ implements BluetoothCallback {
private static final String TAG = "CallsAndAlarmsPreferenceController";
private static final String PREF_KEY = "calls_and_alarms";
@@ -86,6 +86,7 @@
@Override
public void onStart(@NonNull LifecycleOwner owner) {
+ super.onStart(owner);
if (mLocalBtManager != null) {
mLocalBtManager.getEventManager().registerCallback(this);
}
@@ -93,25 +94,46 @@
@Override
public void onStop(@NonNull LifecycleOwner owner) {
+ super.onStop(owner);
if (mLocalBtManager != null) {
mLocalBtManager.getEventManager().unregisterCallback(this);
}
}
@Override
- public void updateVisibility(boolean isVisible) {
- super.updateVisibility(isVisible);
- if (isVisible && mPreference != null) {
- updateDeviceItemsInSharingSession();
- // mDeviceItemsInSharingSession is ordered. The active device is the first place if
- // exits.
- if (!mDeviceItemsInSharingSession.isEmpty()
- && mDeviceItemsInSharingSession.get(0).isActive()) {
- mPreference.setSummary(mDeviceItemsInSharingSession.get(0).getName());
- } else {
- mPreference.setSummary("");
- }
- }
+ public void updateVisibility() {
+ if (mPreference == null) return;
+ var unused =
+ ThreadUtils.postOnBackgroundThread(
+ () -> {
+ boolean isVisible = isBroadcasting() && isBluetoothStateOn();
+ if (!isVisible) {
+ ThreadUtils.postOnMainThread(() -> mPreference.setVisible(false));
+ } else {
+ updateDeviceItemsInSharingSession();
+ // mDeviceItemsInSharingSession is ordered. The active device is the
+ // first
+ // place if exits.
+ if (!mDeviceItemsInSharingSession.isEmpty()
+ && mDeviceItemsInSharingSession.get(0).isActive()) {
+ ThreadUtils.postOnMainThread(
+ () -> {
+ mPreference.setVisible(true);
+ mPreference.setSummary(
+ mDeviceItemsInSharingSession
+ .get(0)
+ .getName());
+ });
+ } else {
+ ThreadUtils.postOnMainThread(
+ () -> {
+ mPreference.setVisible(true);
+ mPreference.setSummary(
+ "No active device in sharing");
+ });
+ }
+ }
+ });
}
@Override
diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsCategoryController.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsCategoryController.java
index f80fdab..f47526f 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsCategoryController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsCategoryController.java
@@ -22,7 +22,6 @@
import android.util.Log;
import androidx.annotation.NonNull;
-import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import com.android.settings.bluetooth.Utils;
@@ -38,8 +37,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
-public class AudioStreamsCategoryController extends AudioSharingBasePreferenceController
- implements DefaultLifecycleObserver {
+public class AudioStreamsCategoryController extends AudioSharingBasePreferenceController {
private static final String TAG = "AudioStreamsCategoryController";
private static final boolean DEBUG = BluetoothUtils.D;
private final LocalBluetoothManager mLocalBtManager;
@@ -50,7 +48,7 @@
public void onActiveDeviceChanged(
@Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {
if (bluetoothProfile == BluetoothProfile.LE_AUDIO) {
- updateVisibility(isBroadcasting());
+ updateVisibility();
}
}
};
@@ -63,14 +61,15 @@
@Override
public void onStart(@NonNull LifecycleOwner owner) {
+ super.onStart(owner);
if (mLocalBtManager != null) {
mLocalBtManager.getEventManager().registerCallback(mBluetoothCallback);
}
- updateVisibility(isBroadcasting());
}
@Override
public void onStop(@NonNull LifecycleOwner owner) {
+ super.onStop(owner);
if (mLocalBtManager != null) {
mLocalBtManager.getEventManager().unregisterCallback(mBluetoothCallback);
}
@@ -84,21 +83,28 @@
}
@Override
- public void updateVisibility(boolean isBroadcasting) {
+ public void updateVisibility() {
+ if (mPreference == null) return;
mExecutor.execute(
() -> {
boolean hasActiveLe =
AudioSharingUtils.getActiveSinkOnAssistant(mLocalBtManager).isPresent();
+ boolean isBroadcasting = isBroadcasting();
+ boolean isBluetoothOn = isBluetoothStateOn();
if (DEBUG) {
Log.d(
TAG,
"updateVisibility() isBroadcasting : "
+ isBroadcasting
+ " hasActiveLe : "
- + hasActiveLe);
+ + hasActiveLe
+ + " is BT on : "
+ + isBluetoothOn);
}
ThreadUtils.postOnMainThread(
- () -> super.updateVisibility(hasActiveLe && !isBroadcasting));
+ () ->
+ mPreference.setVisible(
+ isBluetoothOn && hasActiveLe && !isBroadcasting));
});
}
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 554d23e..6d1d4e8 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -16,7 +16,6 @@
package com.android.settings.core.gateway;
-import com.android.settings.AllInOneTetherSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.IccLockSettings;
import com.android.settings.MainClear;
@@ -205,7 +204,6 @@
WifiNetworkDetailsFragment.class.getName(),
ConfigureWifiSettings.class.getName(),
SavedAccessPointsWifiSettings2.class.getName(),
- AllInOneTetherSettings.class.getName(),
TetherSettings.class.getName(),
SmartAutoRotatePreferenceFragment.class.getName(),
WifiP2pSettings.class.getName(),
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index eaad7f3..4df1fdd 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -27,7 +27,6 @@
import android.content.pm.UserInfo;
import android.content.pm.UserProperties;
import android.os.Bundle;
-import android.os.Flags;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
@@ -187,8 +186,7 @@
UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier());
if (userInfo == null
|| userInfo.isCloneProfile()
- || (Flags.allowPrivateProfile()
- && shouldHideUserInQuietMode(userHandles.get(i), userManager))) {
+ || shouldHideUserInQuietMode(userHandles.get(i), userManager)) {
if (DEBUG) {
Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier());
}
@@ -221,8 +219,7 @@
UserInfo userInfo = userManager.getUserInfo(userHandle.getIdentifier());
if (userInfo == null
|| userInfo.isCloneProfile()
- || (Flags.allowPrivateProfile()
- && shouldHideUserInQuietMode(userHandle, userManager))) {
+ || shouldHideUserInQuietMode(userHandle, userManager)) {
if (DEBUG) {
Log.d(TAG, "Delete the user: " + userHandle.getIdentifier());
}
diff --git a/src/com/android/settings/datetime/AutoTimeFormatPreferenceController.java b/src/com/android/settings/datetime/AutoTimeFormatPreferenceController.java
index 59f7f72..44e7cc6 100644
--- a/src/com/android/settings/datetime/AutoTimeFormatPreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimeFormatPreferenceController.java
@@ -19,53 +19,33 @@
import android.content.Context;
import android.provider.Settings;
import android.provider.Settings.System;
-import android.text.TextUtils;
import android.text.format.DateFormat;
-import androidx.preference.Preference;
-import androidx.preference.TwoStatePreference;
-
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
import java.util.Locale;
-public class AutoTimeFormatPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
+public class AutoTimeFormatPreferenceController extends TogglePreferenceController {
- private static final String KEY_AUTO_24_HOUR = "auto_24hour";
-
- public AutoTimeFormatPreferenceController(Context context, UpdateTimeAndDateCallback callback) {
- super(context);
+ public AutoTimeFormatPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
}
@Override
- public boolean isAvailable() {
- return true;
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
}
@Override
- public String getPreferenceKey() {
- return KEY_AUTO_24_HOUR;
+ public boolean isChecked() {
+ return isAutoTimeFormatSelection(mContext);
}
@Override
- public void updateState(Preference preference) {
- if (!(preference instanceof TwoStatePreference)) {
- return;
- }
- ((TwoStatePreference) preference).setChecked(isAutoTimeFormatSelection(mContext));
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!(preference instanceof TwoStatePreference)
- || !TextUtils.equals(KEY_AUTO_24_HOUR, preference.getKey())) {
- return false;
- }
- boolean auto24HourEnabled = ((TwoStatePreference) preference).isChecked();
+ public boolean setChecked(boolean isChecked) {
Boolean is24Hour;
- if (auto24HourEnabled) {
+ if (isChecked) {
is24Hour = null;
} else {
is24Hour = is24HourLocale(mContext.getResources().getConfiguration().locale);
@@ -74,6 +54,11 @@
return true;
}
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_system;
+ }
+
boolean is24HourLocale(Locale locale) {
return DateFormat.is24HourLocale(locale);
}
diff --git a/src/com/android/settings/datetime/AutoTimePreferenceController.java b/src/com/android/settings/datetime/AutoTimePreferenceController.java
index ca1d4ae..434eba9 100644
--- a/src/com/android/settings/datetime/AutoTimePreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimePreferenceController.java
@@ -27,28 +27,26 @@
import android.app.time.TimeManager;
import android.content.Context;
-import androidx.preference.Preference;
-import androidx.preference.TwoStatePreference;
-
import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
-public class AutoTimePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+public class AutoTimePreferenceController extends TogglePreferenceController {
- private static final String KEY_AUTO_TIME = "auto_time";
- private final UpdateTimeAndDateCallback mCallback;
+ private UpdateTimeAndDateCallback mCallback;
private final TimeManager mTimeManager;
- public AutoTimePreferenceController(Context context, UpdateTimeAndDateCallback callback) {
- super(context);
+ public AutoTimePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
+ }
+
+ public void setDateAndTimeCallback(UpdateTimeAndDateCallback callback) {
mCallback = callback;
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
TimeCapabilities timeCapabilities =
getTimeCapabilitiesAndConfig().getCapabilities();
int capability = timeCapabilities.getConfigureAutoDetectionEnabledCapability();
@@ -57,43 +55,31 @@
// This method handles the "is visible?" check.
switch (capability) {
case CAPABILITY_NOT_SUPPORTED:
- return false;
+ return DISABLED_DEPENDENT_SETTING;
case CAPABILITY_POSSESSED:
- return true;
case CAPABILITY_NOT_ALLOWED:
// This case is expected for enterprise restrictions, where the toggle should be
// present but disabled. Disabling is handled declaratively via the
// settings:userRestriction attribute in .xml. The client-side logic is expected to
// concur with the capabilities logic in the system server.
- return true;
case CAPABILITY_NOT_APPLICABLE:
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
// arbitrary.
- return true;
+ return AVAILABLE;
default:
throw new IllegalStateException("Unknown capability=" + capability);
}
}
@Override
- public void updateState(Preference preference) {
- if (!(preference instanceof TwoStatePreference)) {
- return;
- }
-
- ((TwoStatePreference) preference).setChecked(isEnabled());
+ public boolean isChecked() {
+ return isEnabled();
}
@Override
- public String getPreferenceKey() {
- return KEY_AUTO_TIME;
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- boolean autoTimeEnabled = (Boolean) newValue;
+ public boolean setChecked(boolean isChecked) {
TimeConfiguration configuration = new TimeConfiguration.Builder()
- .setAutoDetectionEnabled(autoTimeEnabled)
+ .setAutoDetectionEnabled(isChecked)
.build();
boolean result = mTimeManager.updateTimeConfiguration(configuration);
@@ -101,6 +87,11 @@
return result;
}
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_system;
+ }
+
/** Returns whether the preference should be "checked", i.e. set to the "on" position. */
@VisibleForTesting
public boolean isEnabled() {
diff --git a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
index c821ad4..011cc97 100644
--- a/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/AutoTimeZonePreferenceController.java
@@ -27,36 +27,42 @@
import android.app.time.TimeZoneConfiguration;
import android.content.Context;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.TwoStatePreference;
-
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.TogglePreferenceController;
-public class AutoTimeZonePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+public class AutoTimeZonePreferenceController extends TogglePreferenceController {
- private static final String KEY_AUTO_TIME_ZONE = "auto_zone";
-
- private final boolean mIsFromSUW;
- private final UpdateTimeAndDateCallback mCallback;
+ private boolean mIsFromSUW;
+ private UpdateTimeAndDateCallback mCallback;
private final TimeManager mTimeManager;
- public AutoTimeZonePreferenceController(Context context, UpdateTimeAndDateCallback callback,
- boolean isFromSUW) {
- super(context);
+ public AutoTimeZonePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
+ }
+
+ /**
+ * Set the Time and Date callback
+ */
+ public AutoTimeZonePreferenceController setTimeAndDateCallback(
+ UpdateTimeAndDateCallback callback) {
mCallback = callback;
+ return this;
+ }
+
+ /**
+ * Set if current fragment is launched via SUW
+ */
+ public AutoTimeZonePreferenceController setFromSUW(boolean isFromSUW) {
mIsFromSUW = isFromSUW;
+ return this;
}
@Override
- public boolean isAvailable() {
+ public int getAvailabilityStatus() {
if (mIsFromSUW) {
- return false;
+ return DISABLED_DEPENDENT_SETTING;
}
TimeZoneCapabilities timeZoneCapabilities =
@@ -67,43 +73,31 @@
// This method handles the "is visible?" check.
switch (capability) {
case CAPABILITY_NOT_SUPPORTED:
- return false;
+ return DISABLED_DEPENDENT_SETTING;
case CAPABILITY_POSSESSED:
- return true;
case CAPABILITY_NOT_ALLOWED:
// This case is expected for enterprise restrictions, where the toggle should be
// present but disabled. Disabling is handled declaratively via the
// settings:userRestriction attribute in .xml. The client-side logic is expected to
// concur with the capabilities logic in the system server.
- return true;
case CAPABILITY_NOT_APPLICABLE:
// CAPABILITY_NOT_APPLICABLE is not currently expected, so this is return value is
// arbitrary.
- return true;
+ return AVAILABLE;
default:
throw new IllegalStateException("Unknown capability=" + capability);
}
}
@Override
- public String getPreferenceKey() {
- return KEY_AUTO_TIME_ZONE;
+ public boolean isChecked() {
+ return isEnabled();
}
@Override
- public void updateState(Preference preference) {
- if (!(preference instanceof TwoStatePreference)) {
- return;
- }
-
- ((TwoStatePreference) preference).setChecked(isEnabled());
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- boolean autoZoneEnabled = (Boolean) newValue;
+ public boolean setChecked(boolean isChecked) {
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
- .setAutoDetectionEnabled(autoZoneEnabled)
+ .setAutoDetectionEnabled(isChecked)
.build();
boolean result = mTimeManager.updateTimeZoneConfiguration(configuration);
@@ -112,6 +106,11 @@
}
@Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_system;
+ }
+
+ @Override
public CharSequence getSummary() {
// If auto time zone cannot enable telephony fallback and is capable of location, then auto
// time zone must use location.
@@ -124,12 +123,6 @@
return "";
}
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- refreshSummary(screen.findPreference(getPreferenceKey()));
- }
-
@VisibleForTesting
boolean isEnabled() {
TimeZoneConfiguration config = getTimeZoneCapabilitiesAndConfig().getConfiguration();
diff --git a/src/com/android/settings/datetime/DatePreferenceController.java b/src/com/android/settings/datetime/DatePreferenceController.java
index eef5526..02aba6e 100644
--- a/src/com/android/settings/datetime/DatePreferenceController.java
+++ b/src/com/android/settings/datetime/DatePreferenceController.java
@@ -33,14 +33,12 @@
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.BasePreferenceController;
import java.util.Calendar;
-public class DatePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, DatePickerDialog.OnDateSetListener {
+public class DatePreferenceController extends BasePreferenceController
+ implements DatePickerDialog.OnDateSetListener {
public interface DatePreferenceHost extends UpdateTimeAndDateCallback {
void showDatePicker();
@@ -49,38 +47,39 @@
public static final int DIALOG_DATEPICKER = 0;
private static final String TAG = "DatePreferenceController";
- private static final String KEY_DATE = "date";
- private final DatePreferenceHost mHost;
+ private DatePreferenceHost mHost;
private final TimeManager mTimeManager;
- public DatePreferenceController(Context context, DatePreferenceHost host) {
- super(context);
- mHost = host;
+ public DatePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
}
+ public void setHost(DatePreferenceHost host) {
+ mHost = host;
+ }
+
@Override
- public boolean isAvailable() {
- return true;
+ public int getAvailabilityStatus() {
+ return isEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
@Override
public void updateState(Preference preference) {
- if (!(preference instanceof RestrictedPreference)) {
- return;
- }
- final Calendar now = Calendar.getInstance();
- preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime()));
- if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
- boolean enableManualDateSelection = isEnabled();
- preference.setEnabled(enableManualDateSelection);
- }
+ super.updateState(preference);
+ preference.setEnabled(isEnabled());
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ Calendar now = Calendar.getInstance();
+ return DateFormat.getLongDateFormat(mContext).format(now.getTime());
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(preference.getKey(), KEY_DATE)) {
+ if (!TextUtils.equals(getPreferenceKey(), preference.getKey())) {
return false;
}
mHost.showDatePicker();
@@ -88,11 +87,6 @@
}
@Override
- public String getPreferenceKey() {
- return KEY_DATE;
- }
-
- @Override
public void onDateSet(DatePicker view, int year, int month, int day) {
setDate(year, month, day);
mHost.updateTimeAndDateDisplay(mContext);
diff --git a/src/com/android/settings/datetime/DateTimeSettings.java b/src/com/android/settings/datetime/DateTimeSettings.java
index 367146b..fb1dd19 100644
--- a/src/com/android/settings/datetime/DateTimeSettings.java
+++ b/src/com/android/settings/datetime/DateTimeSettings.java
@@ -16,21 +16,17 @@
package com.android.settings.datetime;
-import android.app.Activity;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.app.timedetector.TimeDetectorHelper;
import android.content.Context;
-import android.content.Intent;
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;
+import com.google.android.setupcompat.util.WizardManagerHelper;
@SearchIndexable
public class DateTimeSettings extends DashboardFragment implements
@@ -59,40 +55,19 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ boolean isFromSUW = WizardManagerHelper.isAnySetupWizard(getIntent());
getSettingsLifecycle().addObserver(new TimeChangeListenerMixin(context, this));
use(LocationTimeZoneDetectionPreferenceController.class).setFragment(this);
- }
+ use(AutoTimePreferenceController.class).setDateAndTimeCallback(this);
+ use(DatePreferenceController.class).setHost(this);
+ use(TimePreferenceController.class).setHost(this);
+ use(AutoTimeZonePreferenceController.class)
+ .setTimeAndDateCallback(this)
+ .setFromSUW(isFromSUW);
+ use(TimeFormatPreferenceController.class)
+ .setTimeAndDateCallback(this)
+ .setFromSUW(isFromSUW);
- @Override
- protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
- final List<AbstractPreferenceController> controllers = new ArrayList<>();
- final Activity activity = getActivity();
- final Intent intent = activity.getIntent();
- final boolean isFromSUW = intent.getBooleanExtra(EXTRA_IS_FROM_SUW, false);
-
- final AutoTimePreferenceController autoTimePreferenceController =
- new AutoTimePreferenceController(
- activity, this /* UpdateTimeAndDateCallback */);
- controllers.add(autoTimePreferenceController);
- DatePreferenceController datePreferenceController = new DatePreferenceController(
- activity, this /* UpdateTimeAndDateCallback */);
- controllers.add(datePreferenceController);
- controllers.add(new TimePreferenceController(
- activity, this /* UpdateTimeAndDateCallback */, datePreferenceController));
-
- final AutoTimeZonePreferenceController autoTimeZonePreferenceController =
- new AutoTimeZonePreferenceController(
- activity, this /* UpdateTimeAndDateCallback */, isFromSUW);
- controllers.add(autoTimeZonePreferenceController);
- controllers.add(new TimeZonePreferenceController(activity));
-
- final AutoTimeFormatPreferenceController autoTimeFormatPreferenceController =
- new AutoTimeFormatPreferenceController(
- activity, this /* UpdateTimeAndDateCallback */);
- controllers.add(autoTimeFormatPreferenceController);
- controllers.add(new TimeFormatPreferenceController(
- activity, this /* UpdateTimeAndDateCallback */, isFromSUW));
- return controllers;
}
@Override
diff --git a/src/com/android/settings/datetime/TimeFormatPreferenceController.java b/src/com/android/settings/datetime/TimeFormatPreferenceController.java
index 2d2e0a5..22f7509 100644
--- a/src/com/android/settings/datetime/TimeFormatPreferenceController.java
+++ b/src/com/android/settings/datetime/TimeFormatPreferenceController.java
@@ -19,77 +19,93 @@
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
-import android.text.TextUtils;
import android.text.format.DateFormat;
import androidx.preference.Preference;
-import androidx.preference.TwoStatePreference;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
import java.util.Calendar;
import java.util.Date;
-public class TimeFormatPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
+public class TimeFormatPreferenceController extends TogglePreferenceController {
static final String HOURS_12 = "12";
static final String HOURS_24 = "24";
- private static final String KEY_TIME_FORMAT = "24 hour";
-
// Used for showing the current date format, which looks like "12/31/2010", "2010/12/13", etc.
// The date value is stubs (independent of actual date).
private final Calendar mDummyDate;
- private final boolean mIsFromSUW;
- private final UpdateTimeAndDateCallback mUpdateTimeAndDateCallback;
+ private boolean mIsFromSUW;
+ private UpdateTimeAndDateCallback mUpdateTimeAndDateCallback;
- public TimeFormatPreferenceController(Context context, UpdateTimeAndDateCallback callback,
- boolean isFromSUW) {
- super(context);
- mIsFromSUW = isFromSUW;
+ public TimeFormatPreferenceController(Context context, String key) {
+ super(context, key);
mDummyDate = Calendar.getInstance();
+ }
+
+ /**
+ * Set the Time and Date callback
+ */
+ public TimeFormatPreferenceController setTimeAndDateCallback(
+ UpdateTimeAndDateCallback callback) {
mUpdateTimeAndDateCallback = callback;
+ return this;
+ }
+
+ /**
+ * Set if current fragment is launched via SUW
+ */
+ public TimeFormatPreferenceController setFromSUW(boolean isFromSUW) {
+ mIsFromSUW = isFromSUW;
+ return this;
}
@Override
- public boolean isAvailable() {
- return !mIsFromSUW;
+ public int getAvailabilityStatus() {
+ if (mIsFromSUW) {
+ return DISABLED_DEPENDENT_SETTING;
+ }
+ if (AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext)) {
+ return DISABLED_DEPENDENT_SETTING;
+ }
+ return AVAILABLE;
}
@Override
public void updateState(Preference preference) {
- if (!(preference instanceof TwoStatePreference)) {
- return;
- }
- preference.setEnabled(
- !AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext));
- ((TwoStatePreference) preference).setChecked(is24Hour());
+ super.updateState(preference);
+ preference.setEnabled(getAvailabilityStatus() == AVAILABLE);
+ refreshSummary(preference);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return is24Hour();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ update24HourFormat(mContext, isChecked);
+ mUpdateTimeAndDateCallback.updateTimeAndDateDisplay(mContext);
+ return true;
+ }
+
+ @Override
+ public CharSequence getSummary() {
final Calendar now = Calendar.getInstance();
mDummyDate.setTimeZone(now.getTimeZone());
// We use December 31st because it's unambiguous when demonstrating the date format.
// We use 13:00 so we can demonstrate the 12/24 hour options.
mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
final Date dummyDate = mDummyDate.getTime();
- preference.setSummary(DateFormat.getTimeFormat(mContext).format(dummyDate));
+ return DateFormat.getTimeFormat(mContext).format(dummyDate);
}
@Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!(preference instanceof TwoStatePreference)
- || !TextUtils.equals(KEY_TIME_FORMAT, preference.getKey())) {
- return false;
- }
- final boolean is24Hour = ((TwoStatePreference) preference).isChecked();
- update24HourFormat(mContext, is24Hour);
- mUpdateTimeAndDateCallback.updateTimeAndDateDisplay(mContext);
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_TIME_FORMAT;
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_system;
}
private boolean is24Hour() {
diff --git a/src/com/android/settings/datetime/TimePreferenceController.java b/src/com/android/settings/datetime/TimePreferenceController.java
index 09950fc..1923d55 100644
--- a/src/com/android/settings/datetime/TimePreferenceController.java
+++ b/src/com/android/settings/datetime/TimePreferenceController.java
@@ -16,7 +16,11 @@
package com.android.settings.datetime;
+import static android.app.time.Capabilities.CAPABILITY_POSSESSED;
+
import android.app.TimePickerDialog;
+import android.app.time.TimeCapabilities;
+import android.app.time.TimeManager;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.TimeDetector;
import android.content.Context;
@@ -27,14 +31,12 @@
import androidx.preference.Preference;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.BasePreferenceController;
import java.util.Calendar;
-public class TimePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, TimePickerDialog.OnTimeSetListener {
+public class TimePreferenceController extends BasePreferenceController
+ implements TimePickerDialog.OnTimeSetListener {
public interface TimePreferenceHost extends UpdateTimeAndDateCallback {
void showTimePicker();
@@ -43,41 +45,39 @@
public static final int DIALOG_TIMEPICKER = 1;
private static final String TAG = "TimePreferenceController";
- private static final String KEY_TIME = "time";
- private final DatePreferenceController mDatePreferenceController;
- private final TimePreferenceHost mHost;
+ private TimePreferenceHost mHost;
+ private TimeManager mTimeManager;
+ public TimePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mTimeManager = context.getSystemService(TimeManager.class);
+ }
- public TimePreferenceController(Context context,
- TimePreferenceHost callback,
- DatePreferenceController datePreferenceController) {
- super(context);
- mHost = callback;
- mDatePreferenceController = datePreferenceController;
+ public void setHost(TimePreferenceHost host) {
+ mHost = host;
}
@Override
- public boolean isAvailable() {
- return true;
+ public int getAvailabilityStatus() {
+ return isEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
@Override
public void updateState(Preference preference) {
- if (!(preference instanceof RestrictedPreference)) {
- return;
- }
- final Calendar now = Calendar.getInstance();
- preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime()));
- if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
- boolean enableManualTimeSelection = mDatePreferenceController.isEnabled();
- preference.setEnabled(enableManualTimeSelection);
- }
+ super.updateState(preference);
+ preference.setEnabled(isEnabled());
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ Calendar now = Calendar.getInstance();
+ return DateFormat.getTimeFormat(mContext).format(now.getTime());
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(KEY_TIME, preference.getKey())) {
+ if (!TextUtils.equals(getPreferenceKey(), preference.getKey())) {
return false;
}
mHost.showTimePicker();
@@ -85,11 +85,6 @@
}
@Override
- public String getPreferenceKey() {
- return KEY_TIME;
- }
-
- @Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if (mContext != null) {
setTime(hourOfDay, minute);
@@ -132,4 +127,16 @@
Log.w(TAG, "Unable to set time with suggestion=" + manualTimeSuggestion);
}
}
+
+ /**
+ * Returns whether selecting the preference should prompt for the user to enter the date
+ * manually. Exposed as public so that the time controller can easily share the same logic as
+ * the rules are identical for time.
+ */
+ public boolean isEnabled() {
+ TimeCapabilities timeZoneCapabilities =
+ mTimeManager.getTimeCapabilitiesAndConfig().getCapabilities();
+ int suggestManualTimeCapability = timeZoneCapabilities.getSetManualTimeCapability();
+ return suggestManualTimeCapability == CAPABILITY_POSSESSED;
+ }
}
diff --git a/src/com/android/settings/datetime/TimeZonePreferenceController.java b/src/com/android/settings/datetime/TimeZonePreferenceController.java
index cb9c38a..913640d 100644
--- a/src/com/android/settings/datetime/TimeZonePreferenceController.java
+++ b/src/com/android/settings/datetime/TimeZonePreferenceController.java
@@ -25,45 +25,34 @@
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.datetime.ZoneGetter;
import java.util.Calendar;
-public class TimeZonePreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
-
- private static final String KEY_TIMEZONE = "timezone";
+public class TimeZonePreferenceController extends BasePreferenceController {
private final TimeManager mTimeManager;
- public TimeZonePreferenceController(Context context) {
- super(context);
+ public TimeZonePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
mTimeManager = context.getSystemService(TimeManager.class);
}
@Override
+ public CharSequence getSummary() {
+ return getTimeZoneOffsetAndName();
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return shouldEnableManualTimeZoneSelection() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
+ }
+
+ @Override
public void updateState(Preference preference) {
- if (!(preference instanceof RestrictedPreference)) {
- return;
- }
- preference.setSummary(getTimeZoneOffsetAndName());
- if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
- boolean enableManualTimeZoneSelection = shouldEnableManualTimeZoneSelection();
- preference.setEnabled(enableManualTimeZoneSelection);
- }
- }
-
- @Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_TIMEZONE;
+ super.updateState(preference);
+ preference.setEnabled(shouldEnableManualTimeZoneSelection());
}
@VisibleForTesting
diff --git a/src/com/android/settings/development/DevelopmentAppPicker.java b/src/com/android/settings/development/DevelopmentAppPicker.java
new file mode 100644
index 0000000..7ef0869
--- /dev/null
+++ b/src/com/android/settings/development/DevelopmentAppPicker.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2023 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.development;
+
+import static android.app.Activity.RESULT_OK;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Process;
+import android.os.UserHandle;
+
+import com.android.settings.R;
+import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
+import com.android.settingslib.applications.DefaultAppInfo;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class DevelopmentAppPicker extends DefaultAppPickerFragment {
+ public static final String EXTRA_REQUESTING_PERMISSION = "REQUESTING_PERMISSION";
+ public static final String EXTRA_DEBUGGABLE = "DEBUGGABLE";
+ public static final String EXTRA_SELECTING_APP = "SELECTING_APP";
+
+ private String mPermissionName;
+ private boolean mDebuggableOnly;
+ private String mSelectingApp;
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ Bundle arguments = getArguments();
+ if (arguments == null) {
+ return;
+ }
+ mPermissionName = arguments.getString(EXTRA_REQUESTING_PERMISSION);
+ mDebuggableOnly = arguments.getBoolean(EXTRA_DEBUGGABLE);
+ mSelectingApp = arguments.getString(EXTRA_SELECTING_APP);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DEVELOPMENT_APP_PICKER;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.development_app_picker;
+ }
+
+ @Override
+ protected boolean shouldShowItemNone() {
+ return true;
+ }
+
+ @Override
+ protected List<DefaultAppInfo> getCandidates() {
+ List<DefaultAppInfo> packageInfoList = new ArrayList<DefaultAppInfo>();
+ Context context = getContext();
+ List<ApplicationInfo> installedApps = mPm.getInstalledApplications(0);
+ for (ApplicationInfo ai : installedApps) {
+ if (ai.uid == Process.SYSTEM_UID) {
+ continue;
+ }
+ // Filter out apps that are not debuggable if required.
+ if (mDebuggableOnly) {
+ // On a user build, we only allow debugging of apps that
+ // are marked as debuggable, otherwise (for platform development)
+ // we allow all apps.
+ if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) == 0
+ && "user".equals(Build.TYPE)) {
+ continue;
+ }
+ }
+
+ // Filter out apps that do not request the permission if required.
+ if (mPermissionName != null) {
+ boolean requestsPermission = false;
+ try {
+ PackageInfo pi = mPm.getPackageInfo(ai.packageName,
+ PackageManager.GET_PERMISSIONS);
+ if (pi.requestedPermissions == null) {
+ continue;
+ }
+ for (String requestedPermission : pi.requestedPermissions) {
+ if (requestedPermission.equals(mPermissionName)) {
+ requestsPermission = true;
+ break;
+ }
+ }
+ if (!requestsPermission) {
+ continue;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ continue;
+ }
+ }
+ DefaultAppInfo appInfo = new DefaultAppInfo(context, mPm, UserHandle.myUserId(), ai);
+ packageInfoList.add(appInfo);
+ }
+ Collections.sort(packageInfoList, sLabelComparator);
+ return packageInfoList;
+ }
+
+ @Override
+ protected String getDefaultKey() {
+ return mSelectingApp;
+ }
+
+ @Override
+ protected boolean setDefaultKey(String key) {
+ DefaultAppInfo appInfo = (DefaultAppInfo) getCandidate(key);
+ Intent intent = new Intent();
+ if (appInfo != null && appInfo.packageItemInfo != null) {
+ intent.setAction(appInfo.packageItemInfo.packageName);
+ }
+ setResult(RESULT_OK, intent);
+ finish();
+ return true;
+ }
+
+ private static final Comparator<DefaultAppInfo> sLabelComparator =
+ new Comparator<DefaultAppInfo>() {
+ public int compare(DefaultAppInfo a, DefaultAppInfo b) {
+ return Collator.getInstance().compare(a.loadLabel(), b.loadLabel());
+ }
+ };
+}
diff --git a/src/com/android/settings/development/MockLocationAppPreferenceController.java b/src/com/android/settings/development/MockLocationAppPreferenceController.java
index b20ef02..d927c31 100644
--- a/src/com/android/settings/development/MockLocationAppPreferenceController.java
+++ b/src/com/android/settings/development/MockLocationAppPreferenceController.java
@@ -21,16 +21,20 @@
import android.Manifest;
import android.app.Activity;
import android.app.AppOpsManager;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import java.util.List;
@@ -64,10 +68,26 @@
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return false;
}
- final Intent intent = new Intent(mContext, AppPicker.class);
- intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
- Manifest.permission.ACCESS_MOCK_LOCATION);
- mFragment.startActivityForResult(intent, REQUEST_MOCK_LOCATION_APP);
+ if (Flags.deprecateListActivity()) {
+ final Bundle args = new Bundle();
+ args.putString(DevelopmentAppPicker.EXTRA_REQUESTING_PERMISSION,
+ Manifest.permission.ACCESS_MOCK_LOCATION);
+ final String debugApp = Settings.Global.getString(
+ mContext.getContentResolver(), Settings.Global.DEBUG_APP);
+ args.putString(DevelopmentAppPicker.EXTRA_SELECTING_APP, debugApp);
+ new SubSettingLauncher(mContext)
+ .setDestination(DevelopmentAppPicker.class.getName())
+ .setSourceMetricsCategory(SettingsEnums.DEVELOPMENT)
+ .setArguments(args)
+ .setTitleRes(com.android.settingslib.R.string.select_application)
+ .setResultListener(mFragment, REQUEST_MOCK_LOCATION_APP)
+ .launch();
+ } else {
+ final Intent intent = new Intent(mContext, AppPicker.class);
+ intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
+ Manifest.permission.ACCESS_MOCK_LOCATION);
+ mFragment.startActivityForResult(intent, REQUEST_MOCK_LOCATION_APP);
+ }
return true;
}
diff --git a/src/com/android/settings/development/SelectDebugAppPreferenceController.java b/src/com/android/settings/development/SelectDebugAppPreferenceController.java
index f0b0b27..d691149 100644
--- a/src/com/android/settings/development/SelectDebugAppPreferenceController.java
+++ b/src/com/android/settings/development/SelectDebugAppPreferenceController.java
@@ -19,16 +19,20 @@
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_CODE_DEBUG_APP;
import android.app.Activity;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.os.Bundle;
import android.provider.Settings;
+import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class SelectDebugAppPreferenceController extends DeveloperOptionsPreferenceController
@@ -53,13 +57,29 @@
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
- if (DEBUG_APP_KEY.equals(preference.getKey())) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+
+ if (Flags.deprecateListActivity()) {
+ final Bundle args = new Bundle();
+ args.putBoolean(DevelopmentAppPicker.EXTRA_DEBUGGABLE, true /* value */);
+ final String debugApp = Settings.Global.getString(
+ mContext.getContentResolver(), Settings.Global.DEBUG_APP);
+ args.putString(DevelopmentAppPicker.EXTRA_SELECTING_APP, debugApp);
+ new SubSettingLauncher(mContext)
+ .setDestination(DevelopmentAppPicker.class.getName())
+ .setSourceMetricsCategory(SettingsEnums.DEVELOPMENT)
+ .setArguments(args)
+ .setTitleRes(com.android.settingslib.R.string.select_application)
+ .setResultListener(mFragment, REQUEST_CODE_DEBUG_APP)
+ .launch();
+ } else {
final Intent intent = getActivityStartIntent();
intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true /* value */);
mFragment.startActivityForResult(intent, REQUEST_CODE_DEBUG_APP);
- return true;
}
- return false;
+ return true;
}
@Override
diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
index a6dd732..0b88657 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
@@ -101,7 +101,7 @@
final LockPatternUtils lpu = new LockPatternUtils(this);
if (StorageManager.isFileEncrypted()) {
for (UserInfo user : getSystemService(UserManager.class).getUsers()) {
- if (StorageManager.isUserKeyUnlocked(user.id)) {
+ if (StorageManager.isCeStorageUnlocked(user.id)) {
continue;
}
if (!lpu.isSecure(user.id)) {
diff --git a/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java
index bf16ab0..f55f822 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardMoveConfirm.java
@@ -83,7 +83,7 @@
final LockPatternUtils lpu = new LockPatternUtils(this);
if (StorageManager.isFileEncrypted()) {
for (UserInfo user : getSystemService(UserManager.class).getUsers()) {
- if (StorageManager.isUserKeyUnlocked(user.id)) {
+ if (StorageManager.isCeStorageUnlocked(user.id)) {
continue;
}
if (!lpu.isSecure(user.id)) {
diff --git a/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java b/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
index 4a25238..15f2094 100644
--- a/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
+++ b/src/com/android/settings/fuelgauge/datasaver/DynamicDenylistManager.java
@@ -95,6 +95,9 @@
/** Suggest a list of package to set as POLICY_REJECT. */
public void setDenylist(Set<Integer> denylistTargetUids) {
+ if (denylistTargetUids == null) {
+ return;
+ }
final Set<Integer> manualDenylistUids = getDenylistAllUids(getManualDenylistPref());
denylistTargetUids.removeAll(manualDenylistUids);
@@ -105,27 +108,40 @@
return;
}
- // Store target denied uids into DynamicDenylistPref.
- final SharedPreferences.Editor editor = getDynamicDenylistPref().edit();
- editor.clear();
- denylistTargetUids.forEach(
- uid -> editor.putInt(String.valueOf(uid), POLICY_REJECT_METERED_BACKGROUND));
- editor.apply();
-
+ final ArraySet<Integer> failedUids = new ArraySet<>();
synchronized (mLock) {
// Set new added UIDs into REJECT policy.
for (int uid : denylistTargetUids) {
if (!lastDynamicDenylistUids.contains(uid)) {
- mNetworkPolicyManager.setUidPolicy(uid, POLICY_REJECT_METERED_BACKGROUND);
+ try {
+ mNetworkPolicyManager.setUidPolicy(uid, POLICY_REJECT_METERED_BACKGROUND);
+ } catch (Exception e) {
+ Log.e(TAG, "failed to setUidPolicy(REJECT) for " + uid, e);
+ failedUids.add(uid);
+ }
}
}
// Unset removed UIDs back to NONE policy.
for (int uid : lastDynamicDenylistUids) {
if (!denylistTargetUids.contains(uid)) {
- mNetworkPolicyManager.setUidPolicy(uid, POLICY_NONE);
+ try {
+ mNetworkPolicyManager.setUidPolicy(uid, POLICY_NONE);
+ } catch (Exception e) {
+ Log.e(TAG, "failed to setUidPolicy(NONE) for " + uid, e);
+ }
}
}
}
+
+ // Store target denied uids into DynamicDenylistPref.
+ final SharedPreferences.Editor editor = getDynamicDenylistPref().edit();
+ editor.clear();
+ denylistTargetUids.forEach(uid -> {
+ if (!failedUids.contains(uid)) {
+ editor.putInt(String.valueOf(uid), POLICY_REJECT_METERED_BACKGROUND);
+ }
+ });
+ editor.apply();
}
/** Return true if the target uid is in {@link #getManualDenylistPref()}. */
diff --git a/src/com/android/settings/inputmethod/ModifierKeysSettings.java b/src/com/android/settings/inputmethod/ModifierKeysSettings.java
index 2353c2c..f174598 100644
--- a/src/com/android/settings/inputmethod/ModifierKeysSettings.java
+++ b/src/com/android/settings/inputmethod/ModifierKeysSettings.java
@@ -58,7 +58,8 @@
protected boolean isPageSearchEnabled(Context context) {
return FeatureFlagUtils
.isEnabled(
- context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_MODIFIER_KEY);
+ context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_MODIFIER_KEY)
+ && !PhysicalKeyboardFragment.getHardKeyboards(context).isEmpty();
}
};
}
diff --git a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
index 1ca9ee6..0e95840 100644
--- a/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/PhysicalKeyboardFragment.java
@@ -474,5 +474,10 @@
sir.xmlResId = R.xml.physical_keyboard_settings;
return Arrays.asList(sir);
}
+
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return !getHardKeyboards(context).isEmpty();
+ }
};
}
diff --git a/src/com/android/settings/network/AllInOneTetherPreferenceController.java b/src/com/android/settings/network/AllInOneTetherPreferenceController.java
deleted file mode 100644
index 7baa917..0000000
--- a/src/com/android/settings/network/AllInOneTetherPreferenceController.java
+++ /dev/null
@@ -1,246 +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.network;
-
-import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
-
-import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
-import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
-import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.UserHandle;
-import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.Lifecycle.Event;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.widget.GenericSwitchController;
-import com.android.settingslib.PrimarySwitchPreference;
-import com.android.settingslib.TetherUtil;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * This controller helps to manage the switch state and visibility of "Hotspot & tethering" switch
- * preference. It updates the preference summary text based on tethering state.
- */
-public class AllInOneTetherPreferenceController extends BasePreferenceController implements
- LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
- private static final String TAG = "AllInOneTetherPreferenceController";
-
- private int mTetheringState;
-
- private final boolean mAdminDisallowedTetherConfig;
- private final AtomicReference<BluetoothPan> mBluetoothPan;
- private final BluetoothAdapter mBluetoothAdapter;
- @VisibleForTesting
- final BluetoothProfile.ServiceListener mBtProfileServiceListener =
- new BluetoothProfile.ServiceListener() {
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- if (mBluetoothPan.get() == null) {
- mBluetoothPan.set((BluetoothPan) proxy);
- }
- }
-
- @Override
- public void onServiceDisconnected(int profile) { /* Do nothing */ }
- };
-
- private PrimarySwitchPreference mPreference;
- private TetherEnabler mTetherEnabler;
- private BroadcastReceiver mBluetoothStateReceiver;
-
- @VisibleForTesting(otherwise = VisibleForTesting.NONE)
- AllInOneTetherPreferenceController() {
- super(null /*context*/, "test");
- mAdminDisallowedTetherConfig = false;
- mBluetoothPan = new AtomicReference<>();
- mBluetoothAdapter = null;
- }
-
- public AllInOneTetherPreferenceController(Context context, String key) {
- super(context, key);
- mBluetoothPan = new AtomicReference<>();
- mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
- context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(mPreferenceKey);
- }
-
- @Override
- public int getAvailabilityStatus() {
- if (!TetherUtil.isTetherAvailable(mContext)
- || !FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)) {
- return CONDITIONALLY_UNAVAILABLE;
- } else {
- return AVAILABLE;
- }
- }
-
- @Override
- public CharSequence getSummary() {
- switch (mTetheringState) {
- case TETHERING_OFF:
- return mContext.getString(R.string.tether_settings_summary_off);
- case TETHERING_WIFI_ON:
- return mContext.getString(R.string.tether_settings_summary_hotspot_only);
- case TETHERING_USB_ON:
- return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
- case TETHERING_BLUETOOTH_ON:
- return mContext.getString(
- R.string.tether_settings_summary_bluetooth_tethering_only);
- case TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.tether_settings_summary_ethernet_tethering_only);
- case TETHERING_WIFI_ON | TETHERING_USB_ON:
- return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
- case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON:
- return mContext.getString(R.string.tether_settings_summary_hotspot_and_bluetooth);
- case TETHERING_WIFI_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.tether_settings_summary_hotspot_and_ethernet);
- case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
- return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
- case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.tether_settings_summary_usb_and_ethernet);
- case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.tether_settings_summary_bluetooth_and_ethernet);
- case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
- return mContext.getString(
- R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
- case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(
- R.string.tether_settings_summary_hotspot_and_usb_and_ethernet);
- case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(
- R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet);
- case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(
- R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet);
- case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
- | TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.tether_settings_summary_all);
- default:
- Log.e(TAG, "Unknown tethering state");
- return mContext.getString(R.string.summary_placeholder);
- }
- }
-
- @OnLifecycleEvent(Event.ON_CREATE)
- public void onCreate() {
- if (mBluetoothAdapter != null
- && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
- mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
- if (mBluetoothStateReceiver == null) {
- mBluetoothStateReceiver = new BluetoothStateReceiver();
- mContext.registerReceiver(
- mBluetoothStateReceiver,
- new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
- }
- }
-
- @OnLifecycleEvent(Event.ON_RESUME)
- public void onResume() {
- if (mTetherEnabler != null) {
- mTetherEnabler.addListener(this);
- }
- }
-
- @OnLifecycleEvent(Event.ON_PAUSE)
- public void onPause() {
- if (mTetherEnabler != null) {
- mTetherEnabler.removeListener(this);
- }
- }
-
- @OnLifecycleEvent(Event.ON_DESTROY)
- public void onDestroy() {
- final BluetoothProfile profile = mBluetoothPan.getAndSet(null);
- if (profile != null && mBluetoothAdapter != null) {
- mBluetoothAdapter.closeProfileProxy(BluetoothProfile.PAN, profile);
- }
- if (mBluetoothStateReceiver != null) {
- mContext.unregisterReceiver(mBluetoothStateReceiver);
- mBluetoothStateReceiver = null;
- }
- }
-
- void initEnabler(Lifecycle lifecycle) {
- if (mPreference != null) {
- mTetherEnabler = new TetherEnabler(
- mContext, new GenericSwitchController(mPreference), mBluetoothPan);
- if (lifecycle != null) {
- lifecycle.addObserver(mTetherEnabler);
- }
- } else {
- Log.e(TAG, "TetherEnabler is not initialized");
- }
- }
-
- @Override
- public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
- mTetheringState = state;
- updateState(mPreference);
- }
-
- private class BluetoothStateReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
- Log.i(TAG, "onReceive: action: " + action);
-
- if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {
- final int state =
- intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- Log.i(TAG, "onReceive: state: " + BluetoothAdapter.nameForState(state));
- final BluetoothProfile profile = mBluetoothPan.get();
- switch(state) {
- case BluetoothAdapter.STATE_ON:
- if (profile == null && mBluetoothAdapter != null) {
- mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
- break;
- }
- }
- }
- }
-}
diff --git a/src/com/android/settings/network/BluetoothTetherPreferenceController.java b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
deleted file mode 100644
index 96d39e3..0000000
--- a/src/com/android/settings/network/BluetoothTetherPreferenceController.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import android.bluetooth.BluetoothAdapter;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.ConnectivityManager;
-import android.text.TextUtils;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.OnLifecycleEvent;
-
-import com.google.common.annotations.VisibleForTesting;
-
-/**
- * This controller helps to manage the switch state and visibility of bluetooth tether switch
- * preference.
- */
-public final class BluetoothTetherPreferenceController extends TetherBasePreferenceController {
- private int mBluetoothState;
-
- public BluetoothTetherPreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- public void onStart() {
- mBluetoothState = BluetoothAdapter.getDefaultAdapter().getState();
- mContext.registerReceiver(mBluetoothChangeReceiver,
- new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- public void onStop() {
- mContext.unregisterReceiver(mBluetoothChangeReceiver);
- }
-
- @Override
- public boolean shouldEnable() {
- switch (mBluetoothState) {
- case BluetoothAdapter.STATE_ON:
- case BluetoothAdapter.STATE_OFF:
- // fall through.
- case BluetoothAdapter.ERROR:
- return true;
- case BluetoothAdapter.STATE_TURNING_OFF:
- case BluetoothAdapter.STATE_TURNING_ON:
- // fall through.
- default:
- return false;
- }
- }
-
- @Override
- public boolean shouldShow() {
- final String[] bluetoothRegexs = mTm.getTetherableBluetoothRegexs();
- return bluetoothRegexs != null && bluetoothRegexs.length != 0;
- }
-
- @Override
- public int getTetherType() {
- return ConnectivityManager.TETHERING_BLUETOOTH;
- }
-
- @VisibleForTesting
- final BroadcastReceiver mBluetoothChangeReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (TextUtils.equals(BluetoothAdapter.ACTION_STATE_CHANGED, intent.getAction())) {
- mBluetoothState =
- intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- updateState(mPreference);
- }
- }
- };
-}
diff --git a/src/com/android/settings/network/EthernetTetherPreferenceController.java b/src/com/android/settings/network/EthernetTetherPreferenceController.java
deleted file mode 100644
index 2fd92f3..0000000
--- a/src/com/android/settings/network/EthernetTetherPreferenceController.java
+++ /dev/null
@@ -1,99 +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.network;
-
-import android.content.Context;
-import android.net.EthernetManager;
-import android.net.TetheringManager;
-import android.os.Handler;
-import android.os.Looper;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.OnLifecycleEvent;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.settings.Utils;
-import com.android.settingslib.utils.ThreadUtils;
-
-import java.util.HashSet;
-
-/**
- * This controller helps to manage the switch state and visibility of ethernet tether switch
- * preference.
- */
-public final class EthernetTetherPreferenceController extends TetherBasePreferenceController {
-
- private final HashSet<String> mAvailableInterfaces = new HashSet<>();
- private final EthernetManager mEthernetManager;
-
- @VisibleForTesting
- EthernetManager.InterfaceStateListener mEthernetListener;
-
- public EthernetTetherPreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
- mEthernetManager = context.getSystemService(EthernetManager.class);
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- public void onStart() {
- mEthernetListener = (iface, state, role, configuration) -> {
- if (state != EthernetManager.STATE_ABSENT) {
- mAvailableInterfaces.add(iface);
- } else {
- mAvailableInterfaces.remove(iface);
- }
- updateState(mPreference);
- };
- final Handler handler = new Handler(Looper.getMainLooper());
- // Executor will execute to post the updateState event to a new handler which is created
- // from the main looper when the {@link EthernetManager.Listener.onAvailabilityChanged}
- // is triggerd.
- if (mEthernetManager != null) {
- mEthernetManager.addInterfaceStateListener(r -> handler.post(r), mEthernetListener);
- }
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- public void onStop() {
- if (mEthernetManager != null) {
- mEthernetManager.removeInterfaceStateListener(mEthernetListener);
- }
- }
-
- @Override
- public boolean shouldEnable() {
- ThreadUtils.ensureMainThread();
- String[] available = mTm.getTetherableIfaces();
- for (String s : available) {
- if (mAvailableInterfaces.contains(s)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean shouldShow() {
- return mEthernetManager != null && !Utils.isMonkeyRunning();
- }
-
- @Override
- public int getTetherType() {
- return TetheringManager.TETHERING_ETHERNET;
- }
-
-}
diff --git a/src/com/android/settings/network/InternetPreferenceController.java b/src/com/android/settings/network/InternetPreferenceController.java
index 71acd4b..1f5042f 100644
--- a/src/com/android/settings/network/InternetPreferenceController.java
+++ b/src/com/android/settings/network/InternetPreferenceController.java
@@ -43,6 +43,7 @@
import com.android.settings.widget.SummaryUpdater;
import com.android.settings.wifi.WifiPickerTrackerHelper;
import com.android.settings.wifi.WifiSummaryUpdater;
+import com.android.settings.wifi.repository.SharedConnectivityRepository;
import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
@@ -77,6 +78,7 @@
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
+ private boolean mIsHotspotNetworkEnabled = SharedConnectivityRepository.isDeviceConfigEnabled();
@VisibleForTesting
WifiPickerTrackerHelper mWifiPickerTrackerHelper;
@@ -111,7 +113,9 @@
mLifecycleOwner = lifecycleOwner;
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
- mWifiPickerTrackerHelper = new WifiPickerTrackerHelper(lifecycle, context, this);
+ if (mIsHotspotNetworkEnabled) {
+ mWifiPickerTrackerHelper = new WifiPickerTrackerHelper(lifecycle, context, this);
+ }
lifecycle.addObserver(this);
}
@@ -162,6 +166,9 @@
@VisibleForTesting
boolean updateHotspotNetwork() {
+ if (mWifiPickerTrackerHelper == null) {
+ return false;
+ }
WifiEntry entry = mWifiPickerTrackerHelper.getWifiPickerTracker().getConnectedWifiEntry();
if (!(entry instanceof HotspotNetworkEntry)) {
return false;
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index 4fcbacf..e5d9242 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -18,7 +18,6 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
-import android.os.Bundle;
import androidx.lifecycle.LifecycleOwner;
@@ -60,13 +59,6 @@
super.onAttach(context);
use(AirplaneModePreferenceController.class).setFragment(this);
- getSettingsLifecycle().addObserver(use(AllInOneTetherPreferenceController.class));
- }
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- super.onCreatePreferences(savedInstanceState, rootKey);
- use(AllInOneTetherPreferenceController.class).initEnabler(getSettingsLifecycle());
}
@Override
@@ -98,9 +90,7 @@
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new MobileNetworkSummaryController(context, lifecycle, lifecycleOwner));
- controllers.add(new TetherPreferenceController(context, lifecycle));
controllers.add(vpnPreferenceController);
- controllers.add(new ProxyPreferenceController(context));
if (internetPreferenceController != null) {
controllers.add(internetPreferenceController);
}
diff --git a/src/com/android/settings/network/ProxyPreferenceController.java b/src/com/android/settings/network/ProxyPreferenceController.java
deleted file mode 100644
index 8f26bfb..0000000
--- a/src/com/android/settings/network/ProxyPreferenceController.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.network;
-
-import android.app.admin.DevicePolicyManager;
-import android.content.Context;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-public class ProxyPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin {
-
- private static final String KEY_PROXY_SETTINGS = "proxy_settings";
-
- public ProxyPreferenceController(Context context) {
- super(context);
- }
-
- @Override
- public boolean isAvailable() {
- // proxy UI disabled until we have better app support
- return false;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- // Enable Proxy selector settings if allowed.
- final Preference pref = screen.findPreference(KEY_PROXY_SETTINGS);
- if (pref != null) {
- final DevicePolicyManager dpm = (DevicePolicyManager)
- mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
- pref.setEnabled(dpm.getGlobalProxyAdmin() == null);
- }
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_PROXY_SETTINGS;
- }
-}
diff --git a/src/com/android/settings/network/TetherBasePreferenceController.java b/src/com/android/settings/network/TetherBasePreferenceController.java
deleted file mode 100644
index b1627f2..0000000
--- a/src/com/android/settings/network/TetherBasePreferenceController.java
+++ /dev/null
@@ -1,162 +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.network;
-
-import android.content.Context;
-import android.net.TetheringManager;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.core.TogglePreferenceController;
-import com.android.settings.datausage.DataSaverBackend;
-
-public abstract class TetherBasePreferenceController extends TogglePreferenceController
- implements LifecycleObserver, DataSaverBackend.Listener,
- TetherEnabler.OnTetherStateUpdateListener {
-
- private static final String TAG = "TetherBasePreferenceController";
- final TetheringManager mTm;
- private final DataSaverBackend mDataSaverBackend;
-
- private TetherEnabler mTetherEnabler;
- Preference mPreference;
- private boolean mDataSaverEnabled;
- int mTetheringState;
-
- TetherBasePreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
- mTm = context.getSystemService(TetheringManager.class);
- mDataSaverBackend = new DataSaverBackend(context);
- mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
- }
-
- /**
- * Set TetherEnabler for the controller. Call this method to initialize the controller.
- * @param tetherEnabler The tetherEnabler to set for the controller.
- */
- public void setTetherEnabler(TetherEnabler tetherEnabler) {
- mTetherEnabler = tetherEnabler;
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
- public void onResume() {
- // Must call setEnabler() before
- if (mTetherEnabler != null) {
- mTetherEnabler.addListener(this);
- }
- mDataSaverBackend.addListener(this);
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
- public void onPause() {
- if (mTetherEnabler != null) {
- mTetherEnabler.removeListener(this);
- }
- mDataSaverBackend.remListener(this);
- }
-
- @Override
- public boolean isChecked() {
- return TetherEnabler.isTethering(mTetheringState, getTetherType());
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- if (mTetherEnabler == null) {
- return false;
- }
- if (isChecked) {
- mTetherEnabler.startTethering(getTetherType());
- } else {
- mTetherEnabler.stopTethering(getTetherType());
- }
- return true;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(mPreferenceKey);
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- if (isAvailable()) {
- preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
- }
- }
-
- @Override
- public int getAvailabilityStatus() {
- if (!shouldShow()) {
- return CONDITIONALLY_UNAVAILABLE;
- }
-
- if (mDataSaverEnabled || !shouldEnable()) {
- return DISABLED_DEPENDENT_SETTING;
- }
- return AVAILABLE;
- }
-
- @Override
- public int getSliceHighlightMenuRes() {
- return R.string.menu_key_network;
- }
-
- @Override
- public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
- mTetheringState = state;
- updateState(mPreference);
- }
-
- @Override
- public void onDataSaverChanged(boolean isDataSaving) {
- mDataSaverEnabled = isDataSaving;
- }
-
- @Override
- public void onAllowlistStatusChanged(int uid, boolean isAllowlisted) {
- }
-
- @Override
- public void onDenylistStatusChanged(int uid, boolean isDenylisted) {
- }
-
- /**
- * Used to enable or disable the preference.
- * @return true if the preference should be enabled; false otherwise.
- */
- public abstract boolean shouldEnable();
-
- /**
- * Used to determine visibility of the preference.
- * @return true if the preference should be visible; false otherwise.
- */
- public abstract boolean shouldShow();
-
- /**
- * Get the type of tether interface that is controlled by the preference.
- * @return the tether interface, like {@link ConnectivityManager#TETHERING_WIFI}
- */
- public abstract int getTetherType();
-}
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
deleted file mode 100644
index f9e5a43..0000000
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.network;
-
-import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
-
-import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.database.ContentObserver;
-import android.net.TetheringManager;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.TetherUtil;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnCreate;
-import com.android.settingslib.core.lifecycle.events.OnDestroy;
-import com.android.settingslib.core.lifecycle.events.OnPause;
-import com.android.settingslib.core.lifecycle.events.OnResume;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-public class TetherPreferenceController extends AbstractPreferenceController implements
- PreferenceControllerMixin, LifecycleObserver, OnCreate, OnResume, OnPause, OnDestroy {
-
- private static final String TAG = "TetherPreferenceController";
- private static final String KEY_TETHER_SETTINGS = "tether_settings";
-
- private final boolean mAdminDisallowedTetherConfig;
- private final AtomicReference<BluetoothPan> mBluetoothPan;
- private final BluetoothAdapter mBluetoothAdapter;
- private final TetheringManager mTetheringManager;
- @VisibleForTesting
- final BluetoothProfile.ServiceListener mBtProfileServiceListener =
- new android.bluetooth.BluetoothProfile.ServiceListener() {
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- if (mBluetoothPan.get() == null) {
- mBluetoothPan.set((BluetoothPan) proxy);
- }
- updateSummary();
- }
-
- public void onServiceDisconnected(int profile) {
- updateSummary();
- }
- };
-
- private SettingObserver mAirplaneModeObserver;
- private Preference mPreference;
- private TetherBroadcastReceiver mTetherReceiver;
- private BroadcastReceiver mBluetoothStateReceiver;
-
- @VisibleForTesting(otherwise = VisibleForTesting.NONE)
- TetherPreferenceController() {
- super(null);
- mAdminDisallowedTetherConfig = false;
- mBluetoothPan = new AtomicReference<>();
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mTetheringManager = null;
- }
-
- public TetherPreferenceController(Context context, Lifecycle lifecycle) {
- super(context);
- mBluetoothPan = new AtomicReference<>();
- mAdminDisallowedTetherConfig = isTetherConfigDisallowed(context);
- mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- mTetheringManager = context.getSystemService(TetheringManager.class);
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = screen.findPreference(KEY_TETHER_SETTINGS);
- if (mPreference != null && !mAdminDisallowedTetherConfig) {
- mPreference.setTitle(
- com.android.settingslib.Utils.getTetheringLabel(mTetheringManager));
- }
- }
-
- @Override
- public boolean isAvailable() {
- return TetherUtil.isTetherAvailable(mContext)
- && !FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE);
- }
-
- @Override
- public void updateState(Preference preference) {
- updateSummary();
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_TETHER_SETTINGS;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- if (mBluetoothAdapter != null &&
- mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
- mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
- if (mBluetoothStateReceiver == null) {
- mBluetoothStateReceiver = new BluetoothStateReceiver();
- mContext.registerReceiver(
- mBluetoothStateReceiver,
- new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
- }
- }
-
- @Override
- public void onResume() {
- if (mAirplaneModeObserver == null) {
- mAirplaneModeObserver = new SettingObserver();
- }
- if (mTetherReceiver == null) {
- mTetherReceiver = new TetherBroadcastReceiver();
- }
- mContext.registerReceiver(
- mTetherReceiver, new IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED));
- mContext.getContentResolver()
- .registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
- }
-
- @Override
- public void onPause() {
- if (mAirplaneModeObserver != null) {
- mContext.getContentResolver().unregisterContentObserver(mAirplaneModeObserver);
- }
- if (mTetherReceiver != null) {
- mContext.unregisterReceiver(mTetherReceiver);
- }
- }
-
- @Override
- public void onDestroy() {
- final BluetoothProfile profile = mBluetoothPan.getAndSet(null);
- if (profile != null && mBluetoothAdapter != null) {
- mBluetoothAdapter.closeProfileProxy(BluetoothProfile.PAN, profile);
- }
- if (mBluetoothStateReceiver != null) {
- mContext.unregisterReceiver(mBluetoothStateReceiver);
- mBluetoothStateReceiver = null;
- }
- }
-
- public static boolean isTetherConfigDisallowed(Context context) {
- return checkIfRestrictionEnforced(
- context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
- }
-
- @VisibleForTesting
- void updateSummary() {
- if (mPreference == null) {
- // Preference is not ready yet.
- return;
- }
- String[] allTethered = mTetheringManager.getTetheredIfaces();
- String[] wifiTetherRegex = mTetheringManager.getTetherableWifiRegexs();
- String[] bluetoothRegex = mTetheringManager.getTetherableBluetoothRegexs();
-
- boolean hotSpotOn = false;
- boolean tetherOn = false;
- if (allTethered != null) {
- if (wifiTetherRegex != null) {
- for (String tethered : allTethered) {
- for (String regex : wifiTetherRegex) {
- if (tethered.matches(regex)) {
- hotSpotOn = true;
- break;
- }
- }
- }
- }
- if (allTethered.length > 1) {
- // We have more than 1 tethered connection
- tetherOn = true;
- } else if (allTethered.length == 1) {
- // We have more than 1 tethered, it's either wifiTether (hotspot), or other type of
- // tether.
- tetherOn = !hotSpotOn;
- } else {
- // No tethered connection.
- tetherOn = false;
- }
- }
- if (!tetherOn
- && bluetoothRegex != null && bluetoothRegex.length > 0
- && mBluetoothAdapter != null
- && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
- // Check bluetooth state. It's not included in mTetheringManager.getTetheredIfaces.
- final BluetoothPan pan = mBluetoothPan.get();
- tetherOn = pan != null && pan.isTetheringOn();
- }
- if (!hotSpotOn && !tetherOn) {
- // Both off
- updateSummaryToOff();
- } else if (hotSpotOn && tetherOn) {
- // Both on
- mPreference.setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
- } else if (hotSpotOn) {
- mPreference.setSummary(R.string.tether_settings_summary_hotspot_on_tether_off);
- } else {
- mPreference.setSummary(R.string.tether_settings_summary_hotspot_off_tether_on);
- }
- }
-
- private void updateSummaryToOff() {
- if (mPreference == null) {
- // Preference is not ready yet.
- return;
- }
- mPreference.setSummary(R.string.tether_preference_summary_off);
- }
-
- class SettingObserver extends ContentObserver {
-
- public final Uri uri;
-
- public SettingObserver() {
- super(new Handler());
- uri = Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON);
- }
-
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- super.onChange(selfChange, uri);
- if (this.uri.equals(uri)) {
- boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
- if (isAirplaneMode) {
- // Airplane mode is on. Update summary to say tether is OFF directly. We cannot
- // go through updateSummary() because turning off tether takes time, and we
- // might still get "ON" status when rerun updateSummary(). So, just say it's off
- updateSummaryToOff();
- }
- }
- }
- }
-
- @VisibleForTesting
- class TetherBroadcastReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- updateSummary();
- }
-
- }
-
- private class BluetoothStateReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
- Log.i(TAG, "onReceive: action: " + action);
-
- if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {
- final int state =
- intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- Log.i(TAG, "onReceive: state: " + BluetoothAdapter.nameForState(state));
- final BluetoothProfile profile = mBluetoothPan.get();
- switch(state) {
- case BluetoothAdapter.STATE_ON:
- if (profile == null && mBluetoothAdapter != null) {
- mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
- break;
- }
- }
- }
- }
-}
diff --git a/src/com/android/settings/network/TetherPreferenceController.kt b/src/com/android/settings/network/TetherPreferenceController.kt
new file mode 100644
index 0000000..c36a2382
--- /dev/null
+++ b/src/com/android/settings/network/TetherPreferenceController.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2023 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.Context
+import android.net.TetheringManager
+import android.os.UserHandle
+import android.os.UserManager
+import androidx.annotation.StringRes
+import androidx.annotation.VisibleForTesting
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
+import androidx.preference.Preference
+import androidx.preference.PreferenceScreen
+import com.android.settings.R
+import com.android.settings.core.BasePreferenceController
+import com.android.settingslib.RestrictedLockUtilsInternal
+import com.android.settingslib.TetherUtil
+import com.android.settingslib.Utils
+import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+
+class TetherPreferenceController(context: Context, key: String) :
+ BasePreferenceController(context, key) {
+
+ private val tetheredRepository = TetheredRepository(context)
+ private val tetheringManager = mContext.getSystemService(TetheringManager::class.java)!!
+
+ private var preference: Preference? = null
+
+ override fun getAvailabilityStatus() =
+ if (TetherUtil.isTetherAvailable(mContext)) AVAILABLE else CONDITIONALLY_UNAVAILABLE
+
+ override fun displayPreference(screen: PreferenceScreen) {
+ super.displayPreference(screen)
+ preference = screen.findPreference(preferenceKey)
+ }
+
+ override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
+ viewLifecycleOwner.lifecycleScope.launch {
+ viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
+ getTitleResId()?.let { preference?.setTitle(it) }
+ }
+ }
+
+ tetheredRepository.tetheredTypesFlow().collectLatestWithLifecycle(viewLifecycleOwner) {
+ preference?.setSummary(getSummaryResId(it))
+ }
+ }
+
+ private suspend fun getTitleResId(): Int? = withContext(Dispatchers.Default) {
+ if (isTetherConfigDisallowed(mContext)) null
+ else Utils.getTetheringLabel(tetheringManager)
+ }
+
+ @VisibleForTesting
+ @StringRes
+ fun getSummaryResId(tetheredTypes: Set<Int>): Int {
+ val hotSpotOn = TetheringManager.TETHERING_WIFI in tetheredTypes
+ val tetherOn = tetheredTypes.any { it != TetheringManager.TETHERING_WIFI }
+ return when {
+ hotSpotOn && tetherOn -> R.string.tether_settings_summary_hotspot_on_tether_on
+ hotSpotOn -> R.string.tether_settings_summary_hotspot_on_tether_off
+ tetherOn -> R.string.tether_settings_summary_hotspot_off_tether_on
+ else -> R.string.tether_preference_summary_off
+ }
+ }
+
+ companion object {
+ @JvmStatic
+ fun isTetherConfigDisallowed(context: Context?): Boolean =
+ RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
+ context, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()
+ ) != null
+ }
+}
diff --git a/src/com/android/settings/network/TetheredRepository.kt b/src/com/android/settings/network/TetheredRepository.kt
new file mode 100644
index 0000000..f18bdca
--- /dev/null
+++ b/src/com/android/settings/network/TetheredRepository.kt
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2023 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.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothManager
+import android.bluetooth.BluetoothPan
+import android.bluetooth.BluetoothProfile
+import android.content.Context
+import android.content.IntentFilter
+import android.net.TetheringInterface
+import android.net.TetheringManager
+import com.android.settingslib.spaprivileged.framework.common.broadcastReceiverFlow
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.asExecutor
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.conflate
+import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flowOf
+import kotlinx.coroutines.flow.flowOn
+import kotlinx.coroutines.flow.merge
+import kotlinx.coroutines.launch
+
+class TetheredRepository(private val context: Context) {
+ private val tetheringManager = context.getSystemService(TetheringManager::class.java)!!
+
+ private val adapter = context.getSystemService(BluetoothManager::class.java)!!.adapter
+
+ fun tetheredTypesFlow(): Flow<Set<Int>> =
+ combine(
+ tetheredInterfacesFlow(),
+ isBluetoothTetheringOnFlow(),
+ ) { tetheringInterfaces, isBluetoothTetheringOn ->
+ val mutableSet = tetheringInterfaces.map { it.type }.toMutableSet()
+ if (isBluetoothTetheringOn) mutableSet += TetheringManager.TETHERING_BLUETOOTH
+ mutableSet
+ }.conflate().flowOn(Dispatchers.Default)
+
+ private fun tetheredInterfacesFlow(): Flow<Set<TetheringInterface>> = callbackFlow {
+ val callback = object : TetheringManager.TetheringEventCallback {
+ override fun onTetheredInterfacesChanged(interfaces: Set<TetheringInterface>) {
+ trySend(interfaces)
+ }
+ }
+
+ tetheringManager.registerTetheringEventCallback(Dispatchers.Default.asExecutor(), callback)
+
+ awaitClose { tetheringManager.unregisterTetheringEventCallback(callback) }
+ }.conflate().flowOn(Dispatchers.Default)
+
+ @OptIn(ExperimentalCoroutinesApi::class)
+ private fun isBluetoothTetheringOnFlow(): Flow<Boolean> =
+ merge(
+ flowOf(null), // kick an initial value
+ context.broadcastReceiverFlow(IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)),
+ ).flatMapLatest {
+ if (adapter.getState() == BluetoothAdapter.STATE_ON) {
+ isBluetoothPanTetheringOnFlow()
+ } else {
+ flowOf(false)
+ }
+ }.conflate().flowOn(Dispatchers.Default)
+
+ private fun isBluetoothPanTetheringOnFlow() = callbackFlow {
+ var connectedProxy: BluetoothProfile? = null
+
+ val listener = object : BluetoothProfile.ServiceListener {
+ override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
+ connectedProxy = proxy
+ launch(Dispatchers.Default) {
+ trySend((proxy as BluetoothPan).isTetheringOn)
+ }
+ }
+
+ override fun onServiceDisconnected(profile: Int) {}
+ }
+
+ adapter.getProfileProxy(context, listener, BluetoothProfile.PAN)
+
+ awaitClose {
+ connectedProxy?.let { adapter.closeProfileProxy(BluetoothProfile.PAN, it) }
+ }
+ }.conflate().flowOn(Dispatchers.Default)
+}
diff --git a/src/com/android/settings/network/UsbTetherPreferenceController.java b/src/com/android/settings/network/UsbTetherPreferenceController.java
deleted file mode 100644
index 7a5cc21..0000000
--- a/src/com/android/settings/network/UsbTetherPreferenceController.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.hardware.usb.UsbManager;
-import android.net.ConnectivityManager;
-import android.os.Environment;
-import android.text.TextUtils;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.OnLifecycleEvent;
-
-import com.android.settings.Utils;
-
-/**
- * This controller helps to manage the switch state and visibility of USB tether switch
- * preference.
- *
- */
-public final class UsbTetherPreferenceController extends TetherBasePreferenceController {
-
- private static final String TAG = "UsbTetherPrefController";
-
- private boolean mUsbConnected;
- private boolean mMassStorageActive;
-
- public UsbTetherPreferenceController(Context context, String prefKey) {
- super(context, prefKey);
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_START)
- public void onStart() {
- mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
- IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
- filter.addAction(Intent.ACTION_MEDIA_SHARED);
- filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
- mContext.registerReceiver(mUsbChangeReceiver, filter);
- }
-
- @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
- public void onStop() {
- mContext.unregisterReceiver(mUsbChangeReceiver);
- }
-
- @Override
- public boolean shouldEnable() {
- return mUsbConnected && !mMassStorageActive;
- }
-
- @Override
- public boolean shouldShow() {
- String[] usbRegexs = mTm.getTetherableUsbRegexs();
- return usbRegexs != null && usbRegexs.length != 0 && !Utils.isMonkeyRunning();
- }
-
- @Override
- public int getTetherType() {
- return ConnectivityManager.TETHERING_USB;
- }
-
- @VisibleForTesting
- final BroadcastReceiver mUsbChangeReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (TextUtils.equals(Intent.ACTION_MEDIA_SHARED, action)) {
- mMassStorageActive = true;
- } else if (TextUtils.equals(Intent.ACTION_MEDIA_UNSHARED, action)) {
- mMassStorageActive = false;
- } else if (TextUtils.equals(UsbManager.ACTION_USB_STATE, action)) {
- mUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
- }
- updateState(mPreference);
- }
- };
-}
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
deleted file mode 100644
index 783f78f..0000000
--- a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
-
-import android.content.Context;
-import android.net.ConnectivityManager;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.Utils;
-
-/**
- * This controller helps to manage the switch state and visibility of wifi tether disable switch
- * preference. When the preference checked, wifi tether will be disabled.
- *
- * @see BluetoothTetherPreferenceController
- * @see UsbTetherPreferenceController
- */
-public final class WifiTetherDisablePreferenceController extends TetherBasePreferenceController {
-
- private static final String TAG = "WifiTetherDisablePreferenceController";
-
- private PreferenceScreen mScreen;
-
- public WifiTetherDisablePreferenceController(Context context, String prefKey) {
- super(context, prefKey);
- }
-
- @Override
- public boolean isChecked() {
- return !super.isChecked();
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- return super.setChecked(!isChecked);
- }
-
- private int getTetheringStateOfOtherInterfaces() {
- return mTetheringState & (~TETHERING_WIFI_ON);
- }
-
- @Override
- public boolean shouldEnable() {
- return true;
- }
-
- @Override
- public boolean shouldShow() {
- final String[] wifiRegexs = mTm.getTetherableWifiRegexs();
- return wifiRegexs != null && wifiRegexs.length != 0 && !Utils.isMonkeyRunning()
- && getTetheringStateOfOtherInterfaces() != TetherEnabler.TETHERING_OFF;
- }
-
- @Override
- public int getTetherType() {
- return ConnectivityManager.TETHERING_WIFI;
- }
-
- @Override
- public CharSequence getSummary() {
- switch (getTetheringStateOfOtherInterfaces()) {
- case TETHERING_USB_ON:
- return mContext.getString(R.string.disable_wifi_hotspot_when_usb_on);
- case TETHERING_BLUETOOTH_ON:
- return mContext.getString(R.string.disable_wifi_hotspot_when_bluetooth_on);
- case TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.disable_wifi_hotspot_when_ethernet_on);
- case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
- return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
- case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_ethernet_on);
- case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(
- R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on);
- case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
- return mContext.getString(
- R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on);
- default:
- return mContext.getString(R.string.summary_placeholder);
- }
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mScreen = screen;
- if (mPreference != null) {
- mPreference.setOnPreferenceChangeListener(this);
- }
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- preference.setVisible(isAvailable());
- refreshSummary(preference);
- }
-}
diff --git a/src/com/android/settings/network/apn/ApnEditPageProvider.kt b/src/com/android/settings/network/apn/ApnEditPageProvider.kt
index 86d7456..5026958 100644
--- a/src/com/android/settings/network/apn/ApnEditPageProvider.kt
+++ b/src/com/android/settings/network/apn/ApnEditPageProvider.kt
@@ -39,6 +39,7 @@
import com.android.settings.network.apn.ApnNetworkTypes.getNetworkTypeSelectedOptionsState
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.framework.compose.LocalNavController
+import com.android.settingslib.spa.framework.compose.OnBackEffect
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuBox
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuCheckBox
import com.android.settingslib.spa.widget.editor.SettingsOutlinedTextField
@@ -97,21 +98,20 @@
val networkTypeSelectedOptionsState = remember {
getNetworkTypeSelectedOptionsState(apnData.networkType)
}
+ OnBackEffect{
+ validateAndSaveApnData(
+ apnDataInit,
+ apnData,
+ context,
+ uriInit,
+ networkTypeSelectedOptionsState
+ )
+ }
+ val navController = LocalNavController.current
RegularScaffold(
title = if(apnDataInit.newApn) stringResource(id = R.string.apn_add) else stringResource(id = R.string.apn_edit),
- actions = {
- IconButton(onClick = {
- validateAndSaveApnData(
- apnDataInit,
- apnData,
- context,
- uriInit,
- networkTypeSelectedOptionsState
- )
- }) { Icon(imageVector = Icons.Outlined.Done, contentDescription = "Save APN") }
- }
) {
- Column() {
+ Column {
SettingsOutlinedTextField(
value = apnData.name,
label = stringResource(R.string.apn_name),
@@ -203,12 +203,12 @@
enabled = apnData.networkTypeEnabled
) {}
if (!apnData.newApn) {
- val navController = LocalNavController.current
Preference(
object : PreferenceModel {
override val title = stringResource(R.string.menu_delete)
override val onClick = {
deleteApn(uriInit, context)
+ apnData = apnData.copy(saveEnabled = false)
navController.navigateBack()
}
}
diff --git a/src/com/android/settings/network/apn/ApnStatus.kt b/src/com/android/settings/network/apn/ApnStatus.kt
index a479868..d81a8e3 100644
--- a/src/com/android/settings/network/apn/ApnStatus.kt
+++ b/src/com/android/settings/network/apn/ApnStatus.kt
@@ -69,6 +69,7 @@
val networkTypeEnabled: Boolean = true,
val newApn: Boolean = false,
val subId: Int = -1,
+ val saveEnabled: Boolean = true,
val customizedConfig: CustomizedConfig = CustomizedConfig()
) {
fun getContentValues(context: Context): ContentValues {
@@ -230,6 +231,10 @@
uriInit: Uri,
networkTypeSelectedOptionsState: SnapshotStateList<Int>
): Boolean {
+ // Can not be saved
+ if (!apnData.saveEnabled) {
+ return false
+ }
// Nothing to do if it's a read only APN
if (apnData.customizedConfig.readOnlyApn) {
return true
diff --git a/src/com/android/settings/network/tether/TetherSettings.java b/src/com/android/settings/network/tether/TetherSettings.java
index 46cfb55..77ef4b6 100644
--- a/src/com/android/settings/network/tether/TetherSettings.java
+++ b/src/com/android/settings/network/tether/TetherSettings.java
@@ -45,7 +45,6 @@
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -57,7 +56,6 @@
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.datausage.DataSaverBackend;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
@@ -630,11 +628,6 @@
}
@Override
- protected boolean isPageSearchEnabled(Context context) {
- return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
- }
-
- @Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
final TetheringManager tm =
diff --git a/src/com/android/settings/privatespace/AutoAdvanceSetupFragment.java b/src/com/android/settings/privatespace/AutoAdvanceSetupFragment.java
index 1061498..036a13a 100644
--- a/src/com/android/settings/privatespace/AutoAdvanceSetupFragment.java
+++ b/src/com/android/settings/privatespace/AutoAdvanceSetupFragment.java
@@ -93,6 +93,13 @@
};
@Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+ if (android.os.Flags.allowPrivateProfile()) {
+ super.onCreate(savedInstanceState);
+ }
+ }
+
+ @Override
public View onCreateView(
LayoutInflater inflater,
@Nullable ViewGroup container,
diff --git a/src/com/android/settings/privatespace/DeletePrivateSpaceController.java b/src/com/android/settings/privatespace/DeletePrivateSpaceController.java
index c94f63a..98bf827 100644
--- a/src/com/android/settings/privatespace/DeletePrivateSpaceController.java
+++ b/src/com/android/settings/privatespace/DeletePrivateSpaceController.java
@@ -53,7 +53,7 @@
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return android.os.Flags.allowPrivateProfile() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceController.java b/src/com/android/settings/privatespace/HidePrivateSpaceController.java
index 8a0f167..a53055c 100644
--- a/src/com/android/settings/privatespace/HidePrivateSpaceController.java
+++ b/src/com/android/settings/privatespace/HidePrivateSpaceController.java
@@ -38,7 +38,7 @@
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return android.os.Flags.allowPrivateProfile() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceSettings.java b/src/com/android/settings/privatespace/HidePrivateSpaceSettings.java
index d7a9cf5..8c73364 100644
--- a/src/com/android/settings/privatespace/HidePrivateSpaceSettings.java
+++ b/src/com/android/settings/privatespace/HidePrivateSpaceSettings.java
@@ -17,6 +17,7 @@
package com.android.settings.privatespace;
import android.app.settings.SettingsEnums;
+import android.os.Bundle;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -25,6 +26,13 @@
private static final String TAG = "HidePrivateSpaceSettings";
@Override
+ public void onCreate(Bundle icicle) {
+ if (android.os.Flags.allowPrivateProfile()) {
+ super.onCreate(icicle);
+ }
+ }
+
+ @Override
public int getMetricsCategory() {
return SettingsEnums.PRIVATE_SPACE_SETTINGS;
}
diff --git a/src/com/android/settings/privatespace/HidePrivateSpaceSummaryController.java b/src/com/android/settings/privatespace/HidePrivateSpaceSummaryController.java
index 73b3960..42627af 100644
--- a/src/com/android/settings/privatespace/HidePrivateSpaceSummaryController.java
+++ b/src/com/android/settings/privatespace/HidePrivateSpaceSummaryController.java
@@ -36,7 +36,7 @@
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return android.os.Flags.allowPrivateProfile() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privatespace/PrivateProfileContextHelperActivity.java b/src/com/android/settings/privatespace/PrivateProfileContextHelperActivity.java
index 0539f60..31d4be9 100644
--- a/src/com/android/settings/privatespace/PrivateProfileContextHelperActivity.java
+++ b/src/com/android/settings/privatespace/PrivateProfileContextHelperActivity.java
@@ -52,6 +52,9 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
+ if (!android.os.Flags.allowPrivateProfile()) {
+ return;
+ }
setTheme(SetupWizardUtils.getTheme(this, getIntent()));
ThemeHelper.trySetDynamicColor(this);
super.onCreate(savedInstanceState);
diff --git a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
index 3f212b1..1efd445 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceAuthenticationActivity.java
@@ -66,9 +66,8 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
if (Flags.allowPrivateProfile()) {
+ super.onCreate(savedInstanceState);
ThemeHelper.trySetDynamicColor(this);
mPrivateSpaceMaintainer = new Injector().injectPrivateSpaceMaintainer(
getApplicationContext());
@@ -87,7 +86,6 @@
promptToSetDeviceLock();
}
} else {
- Log.w(TAG, "allowPrivateProfile flag is Off!");
finish();
}
}
diff --git a/src/com/android/settings/privatespace/PrivateSpaceDashboardFragment.java b/src/com/android/settings/privatespace/PrivateSpaceDashboardFragment.java
index 5d00329..1e27ec1 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceDashboardFragment.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceDashboardFragment.java
@@ -17,6 +17,7 @@
package com.android.settings.privatespace;
import android.app.settings.SettingsEnums;
+import android.os.Bundle;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -26,6 +27,13 @@
private static final String TAG = "PrivateSpaceDashboardFragment";
@Override
+ public void onCreate(Bundle icicle) {
+ if (android.os.Flags.allowPrivateProfile()) {
+ super.onCreate(icicle);
+ }
+ }
+
+ @Override
protected int getPreferenceScreenResId() {
return R.xml.private_space_settings;
}
diff --git a/src/com/android/settings/privatespace/PrivateSpaceEducation.java b/src/com/android/settings/privatespace/PrivateSpaceEducation.java
index 5dd0cfa..0c87b2b 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceEducation.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceEducation.java
@@ -39,6 +39,9 @@
LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
+ if (!android.os.Flags.allowPrivateProfile()) {
+ return null;
+ }
GlifLayout rootView =
(GlifLayout)
inflater.inflate(R.layout.privatespace_education_screen, container, false);
diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
index 341110b..3ec7c92 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
@@ -25,6 +25,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
+import android.os.Flags;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -68,6 +69,9 @@
* <p> This method should be used by the Private Space Setup Flow ONLY.
*/
final synchronized boolean createPrivateSpace() {
+ if (!Flags.allowPrivateProfile()) {
+ return false;
+ }
// Check if Private space already exists
if (doesPrivateSpaceExist()) {
return true;
@@ -130,6 +134,9 @@
/** Returns true if the Private space exists. */
public synchronized boolean doesPrivateSpaceExist() {
+ if (!Flags.allowPrivateProfile()) {
+ return false;
+ }
if (mUserHandle != null) {
return true;
}
diff --git a/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java b/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
index 93dc43b..dd60dc4 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceSetLockFragment.java
@@ -47,6 +47,9 @@
LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
+ if (!android.os.Flags.allowPrivateProfile()) {
+ return null;
+ }
GlifLayout rootView =
(GlifLayout) inflater.inflate(
R.layout.privatespace_setlock_screen, container, false);
diff --git a/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java b/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
index a5628c8..4eb61e5 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceSetupActivity.java
@@ -36,6 +36,9 @@
private NavHostFragment mNavHostFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ if (!android.os.Flags.allowPrivateProfile()) {
+ return;
+ }
setTheme(SetupWizardUtils.getTheme(this, getIntent()));
ThemeHelper.trySetDynamicColor(this);
super.onCreate(savedInstanceState);
diff --git a/src/com/android/settings/privatespace/SetupSuccessFragment.java b/src/com/android/settings/privatespace/SetupSuccessFragment.java
index 1868f65..f6796be 100644
--- a/src/com/android/settings/privatespace/SetupSuccessFragment.java
+++ b/src/com/android/settings/privatespace/SetupSuccessFragment.java
@@ -45,6 +45,9 @@
LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
+ if (!android.os.Flags.allowPrivateProfile()) {
+ return null;
+ }
GlifLayout rootView =
(GlifLayout)
inflater.inflate(R.layout.privatespace_setup_success, container, false);
diff --git a/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java b/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
index e976261..e130e4d 100644
--- a/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
+++ b/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
@@ -35,7 +35,7 @@
@Override
public boolean isAvailable() {
- return false;
+ return android.os.Flags.allowPrivateProfile();
}
@Override
diff --git a/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java b/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
index 2783c1c..20298a1 100644
--- a/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
+++ b/src/com/android/settings/privatespace/onelock/PrivateSpaceLockController.java
@@ -73,7 +73,7 @@
@Override
public boolean isAvailable() {
- return true;
+ return android.os.Flags.allowPrivateProfile();
}
@Override
diff --git a/src/com/android/settings/privatespace/onelock/UseOneLockController.java b/src/com/android/settings/privatespace/onelock/UseOneLockController.java
index 5c461e0..31634b9 100644
--- a/src/com/android/settings/privatespace/onelock/UseOneLockController.java
+++ b/src/com/android/settings/privatespace/onelock/UseOneLockController.java
@@ -45,7 +45,7 @@
}
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return android.os.Flags.allowPrivateProfile() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java b/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
index 218b870..04101b2 100644
--- a/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
+++ b/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
@@ -94,7 +94,7 @@
@Override
public boolean isAvailable() {
- return true;
+ return android.os.Flags.allowPrivateProfile();
}
@Override
diff --git a/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java b/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
index 36f8448..459116a 100644
--- a/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
+++ b/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
@@ -19,6 +19,7 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
+import android.os.Bundle;
import androidx.annotation.Nullable;
@@ -35,6 +36,13 @@
public static final int UNUNIFY_PRIVATE_LOCK_FROM_DEVICE_REQUEST = 2;
@Override
+ public void onCreate(Bundle icicle) {
+ if (android.os.Flags.allowPrivateProfile()) {
+ super.onCreate(icicle);
+ }
+ }
+
+ @Override
public int getMetricsCategory() {
return SettingsEnums.PRIVATE_SPACE_SETTINGS;
}
diff --git a/src/com/android/settings/system/FactoryResetPreferenceController.java b/src/com/android/settings/system/FactoryResetPreferenceController.java
index 739a0a7..e62e548 100644
--- a/src/com/android/settings/system/FactoryResetPreferenceController.java
+++ b/src/com/android/settings/system/FactoryResetPreferenceController.java
@@ -15,6 +15,7 @@
*/
package com.android.settings.system;
+import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
@@ -38,9 +39,6 @@
private static final String ACTION_PREPARE_FACTORY_RESET =
"com.android.settings.ACTION_PREPARE_FACTORY_RESET";
- private static final String PREPARE_FACTORY_RESET_PERMISSION =
- "com.android.settings.permissions.PREPARE_FACTORY_RESET";
-
private final UserManager mUm;
private ActivityResultLauncher<Intent> mFactoryResetPreparationLauncher;
@@ -103,7 +101,7 @@
boolean isGranted =
(factoryResetWizardPackageInfo.requestedPermissionsFlags[i]
& PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
- if (permission.equals(PREPARE_FACTORY_RESET_PERMISSION) && isGranted) {
+ if (permission.equals(Manifest.permission.PREPARE_FACTORY_RESET) && isGranted) {
return prepareFactoryResetWizardRequest;
}
}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java
deleted file mode 100644
index 8a4be10..0000000
--- a/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceController.java
+++ /dev/null
@@ -1,139 +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.wifi.tether;
-
-import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.net.wifi.SoftApConfiguration;
-import android.util.FeatureFlagUtils;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-
-import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
-
-public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController {
-
- private static final String TAG = "WifiTetherApBandPref";
- private static final String PREF_KEY = "wifi_tether_network_ap_band";
-
- private String[] mBandEntries;
- private String[] mBandSummaries;
- private int mBandIndex;
-
- public WifiTetherApBandPreferenceController(Context context,
- OnTetherConfigUpdateListener listener) {
- super(context, listener);
- updatePreferenceEntries();
- }
-
- @Override
- public void updateDisplay() {
- final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
- if (config == null) {
- mBandIndex = SoftApConfiguration.BAND_2GHZ;
- Log.d(TAG, "Updating band index to BAND_2GHZ because no config");
- } else if (is5GhzBandSupported()) {
- mBandIndex = validateSelection(config.getBand());
- Log.d(TAG, "Updating band index to " + mBandIndex);
- } else {
- mWifiManager.setSoftApConfiguration(
- new SoftApConfiguration.Builder(config).setBand(SoftApConfiguration.BAND_2GHZ)
- .build());
- mBandIndex = SoftApConfiguration.BAND_2GHZ;
- Log.d(TAG, "5Ghz not supported, updating band index to 2GHz");
- }
- ListPreference preference =
- (ListPreference) mPreference;
- preference.setEntries(mBandSummaries);
- preference.setEntryValues(mBandEntries);
-
- if (!is5GhzBandSupported()) {
- preference.setEnabled(false);
- preference.setSummary(R.string.wifi_ap_choose_2G);
- } else {
- preference.setValue(Integer.toString(config.getBand()));
- preference.setSummary(getConfigSummary());
- }
- }
-
- String getConfigSummary() {
- switch (mBandIndex) {
- case SoftApConfiguration.BAND_2GHZ:
- return mBandSummaries[0];
- case SoftApConfiguration.BAND_5GHZ:
- return mBandSummaries[1];
- default:
- return mContext.getString(R.string.wifi_ap_prefer_5G);
- }
- }
-
- @Override
- public String getPreferenceKey() {
- return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
- ? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- mBandIndex = validateSelection(Integer.parseInt((String) newValue));
- Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
- preference.setSummary(getConfigSummary());
- mListener.onTetherConfigUpdated(this);
- return true;
- }
-
- private int validateSelection(int band) {
- // unsupported states:
- // 1: BAND_5GHZ only - include 2GHZ since some of countries doesn't support 5G hotspot
- // 2: no 5 GHZ support means we can't have BAND_5GHZ - default to 2GHZ
- if (SoftApConfiguration.BAND_5GHZ == band) {
- if (!is5GhzBandSupported()) {
- return SoftApConfiguration.BAND_2GHZ;
- }
- return SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ;
- }
-
- return band;
- }
-
- @VisibleForTesting
- void updatePreferenceEntries() {
- Resources res = mContext.getResources();
- int entriesRes = R.array.wifi_ap_band;
- int summariesRes = R.array.wifi_ap_band_summary;
- mBandEntries = res.getStringArray(entriesRes);
- mBandSummaries = res.getStringArray(summariesRes);
- }
-
- private boolean is5GhzBandSupported() {
- final String countryCode = mWifiManager.getCountryCode();
- if (!mWifiManager.is5GHzBandSupported() || countryCode == null) {
- return false;
- }
- return true;
- }
-
- public int getBandIndex() {
- return mBandIndex;
- }
-}
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
index 7d0a86b..d61b3d0 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
@@ -16,20 +16,16 @@
package com.android.settings.wifi.tether;
-import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
-
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.net.wifi.SoftApConfiguration;
import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.WifiUtils;
@@ -68,8 +64,7 @@
@Override
public String getPreferenceKey() {
- return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
- ? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
+ return PREF_KEY;
}
@Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceController.java
index 1e415b3..1bcff1e 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSSIDPreferenceController.java
@@ -16,21 +16,17 @@
package com.android.settings.wifi.tether;
-import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
-
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.SoftApConfiguration;
import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.dpp.WifiDppUtils;
@@ -68,8 +64,7 @@
@Override
public String getPreferenceKey() {
- return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
- ? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
+ return PREF_KEY;
}
@Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java
index 79a97ae..41b6dd9 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java
@@ -16,14 +16,11 @@
package com.android.settings.wifi.tether;
-import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
-
import android.annotation.NonNull;
import android.content.Context;
import android.net.wifi.SoftApCapability;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -31,7 +28,6 @@
import androidx.preference.Preference;
import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import java.util.LinkedHashMap;
@@ -82,8 +78,7 @@
@Override
public String getPreferenceKey() {
- return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
- ? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
+ return PREF_KEY;
}
@Override
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index df31f49..bad29eb 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -30,7 +30,6 @@
import android.net.wifi.SoftApConfiguration;
import android.os.Bundle;
import android.os.UserManager;
-import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.Nullable;
@@ -39,7 +38,6 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -387,10 +385,7 @@
if (userManager == null || !userManager.isAdminUser()) {
return false;
}
- if (!WifiUtils.canShowWifiHotspot(context)) {
- return false;
- }
- return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
+ return WifiUtils.canShowWifiHotspot(context);
}
@Override
diff --git a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
deleted file mode 100644
index f2a55c1..0000000
--- a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
+++ /dev/null
@@ -1,240 +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;
-
-import static com.android.settings.AllInOneTetherSettings.BLUETOOTH_TETHER_KEY;
-import static com.android.settings.AllInOneTetherSettings.ETHERNET_TETHER_KEY;
-import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_DEFAULT;
-import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_MAX;
-import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITH_SECURITY_NON;
-import static com.android.settings.AllInOneTetherSettings.USB_TETHER_KEY;
-import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.EthernetManager;
-import android.net.TetheringManager;
-import android.net.wifi.SoftApConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.util.FeatureFlagUtils;
-
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.wifi.repository.WifiHotspotRepository;
-import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
-import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-public class AllInOneTetherSettingsTest {
- private static final String[] WIFI_REGEXS = {"wifi_regexs"};
- private static final String[] USB_REGEXS = {"usb_regexs"};
- private static final String[] BT_REGEXS = {"bt_regexs"};
- private static final String[] ETHERNET_REGEXS = {"ethernet_regexs"};
-
- private Context mContext;
- private AllInOneTetherSettings mAllInOneTetherSettings;
-
- @Mock
- private WifiManager mWifiManager;
- @Mock
- private ConnectivityManager mConnectivityManager;
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private UserManager mUserManager;
- @Mock
- private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- @Mock
- private PreferenceGroup mWifiTetherGroup;
- @Mock
- private EthernetManager mEthernetManager;
-
- @Before
- public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- MockitoAnnotations.initMocks(this);
- when(FakeFeatureFactory.setupForTest().getWifiFeatureProvider().getWifiHotspotRepository())
- .thenReturn(mock(WifiHotspotRepository.class));
- doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
- doReturn(mConnectivityManager)
- .when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
- doReturn(mTetheringManager)
- .when(mContext).getSystemService(Context.TETHERING_SERVICE);
- doReturn(mEthernetManager).when(mContext).getSystemService(EthernetManager.class);
- doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
- doReturn(USB_REGEXS).when(mTetheringManager).getTetherableUsbRegexs();
- doReturn(BT_REGEXS).when(mTetheringManager).getTetherableBluetoothRegexs();
- doReturn(ETHERNET_REGEXS).when(mTetheringManager).getTetherableIfaces();
- doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
- // Assume the feature is enabled for most test cases.
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
- mAllInOneTetherSettings = spy(new AllInOneTetherSettings());
- doReturn(mPreferenceScreen).when(mAllInOneTetherSettings).getPreferenceScreen();
- ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class));
- ReflectionHelpers.setField(mAllInOneTetherSettings, "mSecurityPreferenceController",
- mSecurityPreferenceController);
- ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTetherGroup", mWifiTetherGroup);
- }
-
- @Test
- public void getNonIndexableKeys_tetherAvailable_featureEnabled_keysReturnedCorrectly() {
- // To let TetherUtil.isTetherAvailable return true, select one of the combinations
- setupIsTetherAvailable(true);
-
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
- final List<String> niks =
- AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
- assertThat(niks).doesNotContain(
- AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
- assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
- assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
- assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
- assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
- assertThat(niks).doesNotContain(USB_TETHER_KEY);
- assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
-
- // This key should be returned because it's not visible by default.
- assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
- }
-
- @Test
- public void getNonIndexableKeys_tetherAvailable_featureDisabled_keysReturned() {
- setupIsTetherAvailable(true);
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
-
- final List<String> niks =
- AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
- assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
- assertThat(niks).contains(BLUETOOTH_TETHER_KEY);
- assertThat(niks).contains(USB_TETHER_KEY);
- assertThat(niks).contains(ETHERNET_TETHER_KEY);
- }
-
- @Test
- public void getNonIndexableKeys_tetherNotAvailable_keysReturned() {
- // To let TetherUtil.isTetherAvailable return false, select one of the combinations
- setupIsTetherAvailable(false);
-
- final List<String> niks =
- AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
- assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
- assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
- assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
- assertThat(niks).doesNotContain(USB_TETHER_KEY);
- assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
- }
-
- @Test
- public void getPreferenceControllers_notEmpty() {
- assertThat(AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER
- .getPreferenceControllers(mContext)).isNotEmpty();
- }
-
- @Test
- public void createPreferenceControllers_hasAutoOffPreference() {
- assertThat(mAllInOneTetherSettings.createPreferenceControllers(mContext)
- .stream()
- .filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
- .count())
- .isEqualTo(1);
- }
-
- @Test
- public void getInitialChildCount_withSecurity() {
- when(mSecurityPreferenceController.getSecurityType())
- .thenReturn(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
- assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
- EXPANDED_CHILD_COUNT_DEFAULT);
- }
-
- @Test
- public void getInitialChildCount_withoutSecurity() {
- when(mSecurityPreferenceController.getSecurityType())
- .thenReturn(SoftApConfiguration.SECURITY_TYPE_OPEN);
- assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
- EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
- }
-
- @Test
- public void getInitialExpandedChildCount_expandAllChild() {
- assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
- .isNotEqualTo(EXPANDED_CHILD_COUNT_MAX);
- ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", false);
- assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
- .isEqualTo(EXPANDED_CHILD_COUNT_MAX);
- ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", true);
- assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
- .isEqualTo(EXPANDED_CHILD_COUNT_MAX);
- }
-
- private void setupIsTetherAvailable(boolean returnValue) {
- when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
-
- // For RestrictedLockUtils.checkIfRestrictionEnforced
- final int userId = UserHandle.myUserId();
- List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
- when(mUserManager.getUserRestrictionSources(
- UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
- .thenReturn(enforcingUsers);
-
- // For RestrictedLockUtils.hasBaseUserRestriction
- when(mUserManager.hasBaseUserRestriction(
- UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
- .thenReturn(!returnValue);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/MainClearTest.java b/tests/robotests/src/com/android/settings/MainClearTest.java
index dc17dda..e84d4eb 100644
--- a/tests/robotests/src/com/android/settings/MainClearTest.java
+++ b/tests/robotests/src/com/android/settings/MainClearTest.java
@@ -56,6 +56,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -233,6 +234,7 @@
assertThat(mMainClear.showWipeEuicc()).isTrue();
}
+ @Ignore("b/313566998")
@Test
public void testShowWipeEuicc_developerMode_unprovisioned() {
prepareEuiccState(
diff --git a/tests/robotests/src/com/android/settings/accounts/ManagedProfileQuietModeEnablerTest.java b/tests/robotests/src/com/android/settings/accounts/ManagedProfileQuietModeEnablerTest.java
index 305b03a..1a0f9d0 100644
--- a/tests/robotests/src/com/android/settings/accounts/ManagedProfileQuietModeEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/ManagedProfileQuietModeEnablerTest.java
@@ -35,6 +35,8 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
@@ -42,6 +44,7 @@
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -69,6 +72,9 @@
}
};
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
@ParameterizedRobolectricTestRunner.Parameters
public static List<?> params() {
return Arrays.asList(true, false);
diff --git a/tests/robotests/src/com/android/settings/applications/AppDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/AppDashboardFragmentTest.java
index 5137516..5e58f15 100644
--- a/tests/robotests/src/com/android/settings/applications/AppDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppDashboardFragmentTest.java
@@ -38,6 +38,7 @@
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -80,6 +81,7 @@
assertThat(preferenceScreenKeys).containsAtLeastElementsIn(preferenceKeys);
}
+ @Ignore("b/313578776")
@Test
@Config(shadows = ShadowUserManager.class)
public void testAdvancedAppsCategory() {
diff --git a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
index 8740662..d27601e 100644
--- a/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppWithAdminGrantedPermissionsCounterTest.java
@@ -40,6 +40,7 @@
import android.os.UserManager;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -157,11 +158,13 @@
mDevicePolicyManager, mPackageManager, mPackageManagerService, mApp5)).isFalse();
}
+ @Ignore("b/313578776")
@Test
public void testCountInstalledAppsSync() throws Exception {
verifyCountInstalledApps(false /* async */);
}
+ @Ignore("b/313578776")
@Test
public void testCountInstalledAppsAync() throws Exception {
verifyCountInstalledApps(true /* async */);
diff --git a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
index 4eb623d..6bed1bc 100644
--- a/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/applications/ApplicationFeatureProviderImplTest.java
@@ -43,6 +43,7 @@
import com.android.settingslib.testutils.shadow.ShadowSmsApplication;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -140,11 +141,13 @@
assertThat(mAppList.get(0).appInfo.packageName).isEqualTo(APP_2);
}
+ @Ignore("b/313578776")
@Test
public void testCalculateNumberOfInstalledAppsSync() {
verifyCalculateNumberOfPolicyInstalledApps(false /* async */);
}
+ @Ignore("b/313578776")
@Test
public void testCalculateNumberOfInstalledAppsAsync() {
verifyCalculateNumberOfPolicyInstalledApps(true /* async */);
@@ -176,11 +179,13 @@
assertThat(mAppCount).isEqualTo(2);
}
+ @Ignore("b/313578776")
@Test
public void testCalculateNumberOfAppsWithAdminGrantedPermissionsSync() throws Exception {
verifyCalculateNumberOfAppsWithAdminGrantedPermissions(false /* async */);
}
+ @Ignore("b/313578776")
@Test
public void testCalculateNumberOfAppsWithAdminGrantedPermissionsAsync() throws Exception {
verifyCalculateNumberOfAppsWithAdminGrantedPermissions(true /* async */);
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
index cc789c6..8e1fd3d 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppMemoryPreferenceControllerTest.java
@@ -37,6 +37,7 @@
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -79,6 +80,7 @@
when(mFragment.getActivity()).thenReturn(mActivity);
}
+ @Ignore("b/313582035")
@Test
@Config(qualifiers = "mcc999")
public void getAvailabilityStatus_developmentSettingsEnabled_shouldReturnAvailable() {
diff --git a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
index d3ae4e3..196f206 100644
--- a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
@@ -63,6 +63,7 @@
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -313,6 +314,7 @@
verify(adapter).filterSearch(query);
}
+ @Ignore("b/313583754")
@Test
public void notifyItemChange_recyclerViewIdle_shouldNotify() {
final RecyclerView recyclerView = mock(RecyclerView.class);
@@ -327,6 +329,7 @@
verify(adapter).notifyItemChanged(0);
}
+ @Ignore("b/313583754")
@Test
public void notifyItemChange_recyclerViewScrolling_shouldNotifyWhenIdle() {
final RecyclerView recyclerView = mock(RecyclerView.class);
@@ -423,6 +426,7 @@
assertThat(adapter.getItemCount()).isEqualTo(5);
}
+ @Ignore("b/313583754")
@Test
public void applicationsAdapter_filterSearch_noMatch_shouldShowEmptyList() {
final ManageApplications.ApplicationsAdapter adapter =
diff --git a/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt b/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt
index edb1230..cdad338 100644
--- a/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt
+++ b/tests/robotests/src/com/android/settings/biometrics/BiometricSettingsProviderTest.kt
@@ -26,6 +26,7 @@
import com.android.settings.flags.Flags
import com.google.common.truth.Truth.assertThat
import org.junit.Before
+import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -73,6 +74,7 @@
provider.update(Uri.EMPTY, null, null, null)
}
+ @Ignore("b/313342682")
@Test
@RequiresFlagsEnabled(Flags.FLAG_BIOMETRIC_SETTINGS_PROVIDER)
fun getSuggestionState_shouldQueryFeatureProvider() {
diff --git a/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java b/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
index df83eae..563974d 100644
--- a/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/activeunlock/ActiveUnlockStatusUtilsTest.java
@@ -149,17 +149,31 @@
}
@Test
- public void getIntro_unlockOnIntentAndFaceEnabled_returnsEmpty() {
+ public void getIntro_faceEnabled_returnsFace() {
+ ActiveUnlockTestUtils.enable(
+ mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ when(mFaceManager.isHardwareDetected()).thenReturn(true);
+
+ assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_intro_with_face));
+ }
+
+ @Test
+ public void getIntro_fingerprintEnabled_returnsFingerprint() {
ActiveUnlockTestUtils.enable(
mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
when(mFaceManager.isHardwareDetected()).thenReturn(false);
- assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock()).isEqualTo("");
+ assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
+ .isEqualTo(mApplicationContext.getString(
+ R.string.biometric_settings_intro_with_fingerprint));
}
@Test
- public void getIntro_unlockOnIntentAndFaceAndFingerprintEnabled_returnsDefault() {
+ public void getIntro_faceAndFingerprintEnabled_returnsFaceAndFingerprint() {
ActiveUnlockTestUtils.enable(
mApplicationContext, ActiveUnlockStatusUtils.UNLOCK_INTENT_LAYOUT);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
@@ -167,7 +181,7 @@
assertThat(mActiveUnlockStatusUtils.getIntroForActiveUnlock())
.isEqualTo(mApplicationContext.getString(
- R.string.biometric_settings_intro));
+ R.string.biometric_settings_intro_with_activeunlock));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsFragmentTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsFragmentTest.java
index 8b70550..5e90e55 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintSettingsFragmentTest.java
@@ -72,6 +72,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -201,6 +202,7 @@
assertThat(mFingerprintAuthenticateSidecar.isCancelled()).isTrue();
}
+ @Ignore("b/313342682")
@Test
public void testGuestUserRequireScreenOnToAuth() {
Settings.Secure.putIntForUser(
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
index 1904cb5..cfd256f 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java
@@ -29,6 +29,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.companion.CompanionDeviceManager;
import android.content.Context;
import android.hardware.input.InputManager;
import android.os.Bundle;
@@ -49,8 +50,9 @@
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.google.common.collect.ImmutableList;
+
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -63,7 +65,6 @@
import org.robolectric.annotation.Config;
import org.robolectric.fakes.RoboMenu;
-@Ignore("b/313014781")
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowUserManager.class,
@@ -90,12 +91,17 @@
private UserManager mUserManager;
@Mock
private InputManager mInputManager;
+ @Mock
+ private CompanionDeviceManager mCompanionDeviceManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mInputManager).when(mContext).getSystemService(InputManager.class);
+ doReturn(mCompanionDeviceManager).when(mContext)
+ .getSystemService(CompanionDeviceManager.class);
+ when(mCompanionDeviceManager.getAllAssociations()).thenReturn(ImmutableList.of());
removeInputDeviceWithMatchingBluetoothAddress();
FakeFeatureFactory.setupForTest();
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
index 88ace91..853d2c48 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceControllerTest.java
@@ -33,7 +33,6 @@
import com.android.settingslib.widget.FooterPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -45,7 +44,7 @@
public class BluetoothSwitchPreferenceControllerTest {
private static final String BLUETOOTH_INFO_STRING = "When Bluetooth is turned on, your device"
- + " can communicate with other nearby Bluetooth devices.";
+ + " can communicate with other nearby Bluetooth devices";
@Mock
private RestrictionUtils mRestrictionUtils;
@Mock
@@ -83,7 +82,6 @@
assertThat(TextUtils.equals(mFooterPreference.getTitle(), text)).isTrue();
}
- @Ignore("b/313014781")
@Test
public void updateText_bluetoothOffScanningOff() {
Settings.Global.putInt(mContext.getContentResolver(),
@@ -93,7 +91,6 @@
assertThat(mFooterPreference.getTitle()).isEqualTo(BLUETOOTH_INFO_STRING);
}
- @Ignore("b/313014781")
@Test
public void updateText_bluetoothOnScanningOff() {
Settings.Global.putInt(mContext.getContentResolver(),
@@ -103,7 +100,6 @@
assertThat(mFooterPreference.getTitle()).isEqualTo(BLUETOOTH_INFO_STRING);
}
- @Ignore("b/313014781")
@Test
public void updateText_bluetoothOnScanningOn() {
Settings.Global.putInt(mContext.getContentResolver(),
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index 1d1f2f8..a3348ca 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -25,17 +25,23 @@
import android.content.Context;
import android.content.pm.PackageManager;
+import android.platform.test.annotations.RequiresFlagsDisabled;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerListHelper;
+import com.android.settings.flags.Flags;
import com.android.settings.slices.SlicePreferenceController;
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -50,11 +56,13 @@
@Config(shadows = {ShadowUserManager.class,
ShadowConnectivityManager.class, ShadowBluetoothAdapter.class})
public class ConnectedDeviceDashboardFragmentTest {
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
private static final String KEY_NEARBY_DEVICES = "bt_nearby_slice";
private static final String KEY_DISCOVERABLE_FOOTER = "discoverable_footer";
private static final String KEY_SAVED_DEVICE_SEE_ALL = "previously_connected_devices_see_all";
private static final String KEY_FAST_PAIR_DEVICE_SEE_ALL = "fast_pair_devices_see_all";
- private static final String KEY_FAST_PAIR_DEVICE_LIST = "fast_pair_devices";
private static final String KEY_ADD_BT_DEVICES = "add_bt_devices";
private static final String KEY_AUDIO_SHARING_DEVICE_LIST = "audio_sharing_device_list";
private static final String KEY_AUDIO_SHARING_SETTINGS =
@@ -65,9 +73,7 @@
private static final String TEST_APP_NAME = "com.testapp.settings";
private static final String TEST_ACTION = "com.testapp.settings.ACTION_START";
-
- @Mock
- private PackageManager mPackageManager;
+ @Mock private PackageManager mPackageManager;
private Context mContext;
private ConnectedDeviceDashboardFragment mFragment;
@@ -84,17 +90,19 @@
@Test
public void searchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
- ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
- .getXmlResourcesToIndex(mContext, true /* enabled */);
+ ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
+ mContext, true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.connected_devices);
}
@Test
+ @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
public void nonIndexableKeys_existInXmlLayout() {
- final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
- .getNonIndexableKeys(mContext);
+ final List<String> niks =
+ ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+ mContext);
assertThat(niks)
.containsExactly(
@@ -104,7 +112,24 @@
KEY_DISCOVERABLE_FOOTER,
KEY_SAVED_DEVICE_SEE_ALL,
KEY_FAST_PAIR_DEVICE_SEE_ALL,
- KEY_FAST_PAIR_DEVICE_LIST,
+ KEY_AUDIO_SHARING_SETTINGS);
+ }
+
+ @Test
+ @RequiresFlagsDisabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
+ public void nonIndexableKeys_existInXmlLayout_flagOff() {
+ final List<String> niks =
+ ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
+ mContext);
+
+ assertThat(niks)
+ .containsExactly(
+ KEY_CONNECTED_DEVICES,
+ KEY_AVAILABLE_DEVICES,
+ KEY_NEARBY_DEVICES,
+ KEY_DISCOVERABLE_FOOTER,
+ KEY_SAVED_DEVICE_SEE_ALL,
+ KEY_FAST_PAIR_DEVICE_SEE_ALL,
KEY_AUDIO_SHARING_DEVICE_LIST,
KEY_AUDIO_SHARING_SETTINGS);
}
@@ -132,8 +157,8 @@
@Test
public void getPreferenceControllers_containSlicePrefController() {
final List<BasePreferenceController> controllers =
- PreferenceControllerListHelper.getPreferenceControllersFromXml(mContext,
- R.xml.connected_devices);
+ PreferenceControllerListHelper.getPreferenceControllersFromXml(
+ mContext, R.xml.connected_devices);
assertThat(controllers
.stream()
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
new file mode 100644
index 0000000..0b94061
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2023 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.connecteddevice.audiosharing;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.robolectric.Shadows.shadowOf;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Looper;
+import android.platform.test.annotations.RequiresFlagsEnabled;
+import android.platform.test.flag.junit.CheckFlagsRule;
+import android.platform.test.flag.junit.DeviceFlagsValueProvider;
+import android.widget.Switch;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.flags.Flags;
+import com.android.settings.widget.SettingsMainSwitchBar;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class AudioSharingSwitchBarControllerTest {
+ @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+
+ @Rule
+ public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
+
+ @Spy Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock private Switch mSwitch;
+
+ private SettingsMainSwitchBar mSwitchBar;
+ private AudioSharingSwitchBarController mController;
+ private AudioSharingSwitchBarController.OnSwitchBarChangedListener mListener;
+ private boolean mOnSwitchBarChanged;
+
+ @Before
+ public void setUp() {
+ mSwitchBar = new SettingsMainSwitchBar(mContext);
+ mOnSwitchBarChanged = false;
+ mListener = () -> mOnSwitchBarChanged = true;
+ mController = new AudioSharingSwitchBarController(mContext, mSwitchBar, mListener);
+ }
+
+ @Test
+ @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
+ public void bluetoothOff_switchDisabled() {
+ mContext.registerReceiver(
+ mController.mReceiver,
+ mController.mIntentFilter,
+ Context.RECEIVER_EXPORTED_UNAUDITED);
+ Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
+ intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
+ mContext.sendBroadcast(intent);
+ shadowOf(Looper.getMainLooper()).idle();
+ verify(mSwitch).setEnabled(false);
+ assertThat(mOnSwitchBarChanged).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
index 8257b43..091abde 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
@@ -44,6 +44,7 @@
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -222,6 +223,7 @@
assertThat(prefs.get(3).isChecked()).isFalse();
}
+ @Ignore("b/313362757")
@Test
public void onClickNone_mtpEnabled_shouldDisableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsPowerRoleControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsPowerRoleControllerTest.java
index e793336..6be1bd5 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsPowerRoleControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsPowerRoleControllerTest.java
@@ -45,6 +45,7 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -100,6 +101,7 @@
mDetailsPowerRoleController.mHandler = mHandler;
}
+ @Ignore("b/313362757")
@Test
public void displayRefresh_sink_shouldUncheck() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -112,6 +114,7 @@
assertThat(pref.isChecked()).isFalse();
}
+ @Ignore("b/313362757")
@Test
public void displayRefresh_source_shouldCheck() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -149,6 +152,7 @@
mDetailsPowerRoleController.getPreferenceKey())).isNull();
}
+ @Ignore("b/313362757")
@Test
public void onClick_sink_shouldSetSource() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -162,6 +166,7 @@
.isEqualTo(mContext.getString(R.string.usb_switching));
}
+ @Ignore("b/313362757")
@Test
public void onClickTwice_sink_shouldSetSourceOnce() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -176,6 +181,7 @@
verify(mUsbBackend, times(1)).setPowerRole(POWER_ROLE_SOURCE);
}
+ @Ignore("b/313362757")
@Test
public void onClickDeviceAndRefresh_success_shouldClearSubtext() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -194,6 +200,7 @@
assertThat(pref.getSummary()).isEqualTo("");
}
+ @Ignore("b/313362757")
@Test
public void onClickDeviceAndRefresh_failed_shouldShowFailureText() {
mDetailsPowerRoleController.displayPreference(mScreen);
@@ -213,6 +220,7 @@
.isEqualTo(mContext.getString(R.string.usb_switching_failed));
}
+ @Ignore("b/313362757")
@Test
public void onClickDevice_timedOut_shouldShowFailureText() {
mDetailsPowerRoleController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsTranscodeMtpControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsTranscodeMtpControllerTest.java
index 7cf3ecc..51d2c16 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsTranscodeMtpControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsTranscodeMtpControllerTest.java
@@ -36,6 +36,7 @@
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -118,6 +119,7 @@
assertThat(mPreference.isEnabled()).isFalse();
}
+ @Ignore("b/313362757")
@Test
public void displayRefresh_fileTransfer_withAbsentProp_shouldCheck() {
mUnderTest.displayPreference(mScreen);
@@ -129,6 +131,7 @@
assertThat(getSwitchPreference().isChecked()).isFalse();
}
+ @Ignore("b/313362757")
@Test
public void displayRefresh_fileTransfer_withUnsetProp_shouldUncheck() {
mUnderTest.displayPreference(mScreen);
@@ -141,6 +144,7 @@
assertThat(getSwitchPreference().isChecked()).isFalse();
}
+ @Ignore("b/313362757")
@Test
public void displayRefresh_fileTransfer_withSetProp_shouldCheck() {
mUnderTest.displayPreference(mScreen);
@@ -153,6 +157,7 @@
assertThat(getSwitchPreference().isChecked()).isTrue();
}
+ @Ignore("b/313362757")
@Test
public void click_checked_shouldSetSystemProperty() {
mUnderTest.displayPreference(mScreen);
@@ -160,6 +165,7 @@
assertThat(SystemProperties.getBoolean(TRANSCODE_MTP_SYS_PROP_KEY, false)).isTrue();
}
+ @Ignore("b/313362757")
@Test
public void click_unChecked_shouldUnsetSystemProperty() {
mUnderTest.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
index 7f3ef9a..009f13a 100644
--- a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
+++ b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
@@ -52,6 +52,7 @@
new InstrumentableFragmentCodeInspector(mClasses).run();
}
+ @Ignore("b/313612087")
@Test
public void runSliceControllerInXmlInspection() throws Exception {
new SliceControllerInXmlCodeInspector(mClasses).run();
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index f7a940f..5317ce0 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -83,6 +83,7 @@
import com.android.settingslib.drawer.TileUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -236,6 +237,7 @@
assertThat(preference.getOrder()).isEqualTo(tile.getOrder());
}
+ @Ignore("b/313569889")
@Test
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
final Preference preference = new Preference(RuntimeEnvironment.application);
@@ -702,6 +704,7 @@
assertThat(nextStartedActivity).isNull();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_shouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -718,6 +721,7 @@
verify(mActivity).getSupportFragmentManager();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -735,6 +739,7 @@
verify(mActivity).getSupportFragmentManager();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_shouldNotShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -752,6 +757,7 @@
verify(mActivity, never()).getSupportFragmentManager();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
final int userId = 10;
@@ -774,6 +780,7 @@
verify(mActivity, never()).getSupportFragmentManager();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
@@ -792,6 +799,7 @@
verify(mActivity).getSupportFragmentManager();
}
+ @Ignore("b/313569889")
@Test
public void openTileIntent_profileSelectionDialog_unresolvableWorkProfileIntentShouldNotShow() {
final int userId = 10;
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index cfbdd75..449958c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -66,6 +66,7 @@
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -386,6 +387,7 @@
assertThat(mTestFragment.mBlockerController).isNull();
}
+ @Ignore("b/313569889")
@Test
public void createPreference_isProviderTile_returnSwitchPreference() {
final Preference pref = mTestFragment.createPreference(mProviderTile);
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
index e7e37d7..1eb2ea4 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
@@ -42,6 +42,7 @@
import com.google.android.collect.Lists;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -88,6 +89,7 @@
verify(mUserManager, never()).getUserInfo(NORMAL_USER.getIdentifier());
}
+ @Ignore("b/313569889")
@Test
public void updateUserHandlesIfNeeded_Remove() {
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
@@ -103,6 +105,7 @@
verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier());
}
+ @Ignore("b/313569889")
@Test
public void updateUserHandlesIfNeeded_removesCloneProfile() {
final UserInfo userInfo = new UserInfo(CLONE_USER.getIdentifier(), "clone_user", null,
@@ -119,6 +122,7 @@
verify(mUserManager, times(1)).getUserInfo(CLONE_USER.getIdentifier());
}
+ @Ignore("b/313569889")
@Test
public void updatePendingIntentsIfNeeded_removesUsersWithNoPendingIntentsAndCloneProfile() {
final UserInfo userInfo = new UserInfo(CLONE_USER.getIdentifier(), "clone_user", null,
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
index fa2782f..e30759a 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
@@ -21,11 +21,13 @@
import static com.google.common.truth.Truth.assertThat;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+@Ignore("b/313569889")
@RunWith(RobolectricTestRunner.class)
public class ProfileSelectLocationFragmentTest {
diff --git a/tests/robotests/src/com/android/settings/datausage/ChartDataUsagePreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/ChartDataUsagePreferenceTest.java
index 9c93606..205a600 100644
--- a/tests/robotests/src/com/android/settings/datausage/ChartDataUsagePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/ChartDataUsagePreferenceTest.java
@@ -36,6 +36,7 @@
import com.android.settings.widget.UsageView;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -92,6 +93,7 @@
assertThat(points.valueAt(1)).isNotEqualTo(-1);
}
+ @Ignore("b/313568482")
@Test
public void calcPoints_dataNotAvailableAtCycleStart_shouldIndicateStartOfData() {
final UsageView usageView = mock(UsageView.class);
@@ -112,6 +114,7 @@
assertThat(points.valueAt(1)).isEqualTo(-1);
}
+ @Ignore("b/313568482")
@Test
public void calcPoints_shouldNotDrawPointForFutureDate() {
final UsageView usageView = mock(UsageView.class);
diff --git a/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
index 183858e..f9b566e 100644
--- a/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/AutoTimeFormatPreferenceControllerTest.java
@@ -53,13 +53,13 @@
MockitoAnnotations.initMocks(this);
mApplication = ShadowApplication.getInstance();
mContext = RuntimeEnvironment.application;
+ mController = new TestAutoTimeFormatPreferenceController(mContext, "test_key");
+ mPreference = new SwitchPreference(mContext);
+ mPreference.setKey("test_key");
}
@Test
public void updateState_24HourSet_shouldCheckPreference() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
TimeFormatPreferenceController.HOURS_24);
@@ -70,9 +70,6 @@
@Test
public void updateState_12HourSet_shouldCheckPreference() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
TimeFormatPreferenceController.HOURS_12);
@@ -83,9 +80,6 @@
@Test
public void updateState_autoSet_shouldNotCheckPreference() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
mController.updateState(mPreference);
@@ -95,14 +89,7 @@
@Test
public void updatePreference_autoSet_shouldSendIntent_12HourLocale() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
- mPreference.setChecked(false);
-
- boolean result = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(result).isTrue();
+ mController.setChecked(false);
List<Intent> intentsFired = mApplication.getBroadcastIntents();
assertThat(intentsFired.size()).isEqualTo(1);
@@ -114,15 +101,9 @@
@Test
public void updatePreference_autoSet_shouldSendIntent_24HourLocale() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
- mPreference.setChecked(false);
-
mController.setIs24HourLocale(true);
- boolean result = mController.handlePreferenceTreeClick(mPreference);
- assertThat(result).isTrue();
+ mController.setChecked(false);
List<Intent> intentsFired = mApplication.getBroadcastIntents();
assertThat(intentsFired.size()).isEqualTo(1);
@@ -134,15 +115,9 @@
@Test
public void updatePreference_24HourSet_shouldSendIntent() {
- mController = new TestAutoTimeFormatPreferenceController(mContext, mCallback);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
- mPreference.setChecked(true);
-
mController.setIs24HourLocale(false);
- boolean result = mController.handlePreferenceTreeClick(mPreference);
- assertThat(result).isTrue();
+ mController.setChecked(true);
List<Intent> intentsFired = mApplication.getBroadcastIntents();
assertThat(intentsFired.size()).isEqualTo(1);
@@ -161,9 +136,8 @@
private boolean is24HourLocale = false;
- private TestAutoTimeFormatPreferenceController(Context context,
- UpdateTimeAndDateCallback callback) {
- super(context, callback);
+ TestAutoTimeFormatPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
}
void setIs24HourLocale(boolean value) {
diff --git a/tests/robotests/src/com/android/settings/datetime/AutoTimePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/AutoTimePreferenceControllerTest.java
index 022f5fe..9ac318a 100644
--- a/tests/robotests/src/com/android/settings/datetime/AutoTimePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/AutoTimePreferenceControllerTest.java
@@ -16,6 +16,8 @@
package com.android.settings.datetime;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@@ -59,7 +61,8 @@
mPreference = new Preference(mContext);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
- mController = new AutoTimePreferenceController(mContext, mCallback);
+ mController = new AutoTimePreferenceController(mContext, "test_key");
+ mController.setDateAndTimeCallback(mCallback);
}
@Test
@@ -68,7 +71,7 @@
/* autoSupported= */false, /* autoEnabled= */false);
when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@@ -81,24 +84,23 @@
}
@Test
- public void testIsEnabled_shouldReadFromTimeManagerConfig() {
- {
- // Disabled
- TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
- /* autoSupported= */true, /* autoEnabled= */false);
- when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
+ public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
+ // Disabled
+ TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
+ /* autoSupported= */true, /* autoEnabled= */false);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- assertThat(mController.isEnabled()).isFalse();
- }
+ assertThat(mController.isEnabled()).isFalse();
+ }
- {
- // Enabled
- TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
- /* autoSupported= */true, /* autoEnabled= */true);
- when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
+ @Test
+ public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
+ // Enabled
+ TimeCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
+ /* autoSupported= */true, /* autoEnabled= */true);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- assertThat(mController.isEnabled()).isTrue();
- }
+ assertThat(mController.isEnabled()).isTrue();
}
@Test
@@ -118,10 +120,10 @@
verify(mTimeManager).updateTimeConfiguration(timeConfiguration);
// Update the mTimeManager mock so that it now returns the expected updated config.
- TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
- createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */true);
- when(mTimeManager.getTimeCapabilitiesAndConfig())
- .thenReturn(capabilitiesAndConfigAfterUpdate);
+ TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate = createCapabilitiesAndConfig(
+ /* autoSupported= */true, /* autoEnabled= */true);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
+ capabilitiesAndConfigAfterUpdate);
assertThat(mController.isEnabled()).isTrue();
}
@@ -145,14 +147,14 @@
// Update the mTimeManager mock so that it now returns the expected updated config.
TimeCapabilitiesAndConfig capabilitiesAndConfigAfterUpdate =
createCapabilitiesAndConfig(/* autoSupported= */true, /* autoEnabled= */false);
- when(mTimeManager.getTimeCapabilitiesAndConfig())
- .thenReturn(capabilitiesAndConfigAfterUpdate);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(
+ capabilitiesAndConfigAfterUpdate);
assertThat(mController.isEnabled()).isFalse();
}
- private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
- boolean autoSupported, boolean autoEnabled) {
+ private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(boolean autoSupported,
+ boolean autoEnabled) {
int configureAutoDetectionEnabledCapability =
autoSupported ? Capabilities.CAPABILITY_POSSESSED
: Capabilities.CAPABILITY_NOT_SUPPORTED;
diff --git a/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
index 7685a5b..c2d0445 100644
--- a/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/AutoTimeZonePreferenceControllerTest.java
@@ -22,6 +22,8 @@
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@@ -62,6 +64,8 @@
@Mock
private TimeManager mTimeManager;
+ private AutoTimeZonePreferenceController mController;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -70,6 +74,9 @@
mPreference = new Preference(mContext);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
+
+ mController = new AutoTimeZonePreferenceController(mContext, "test_key");
+ mController.setFromSUW(false);
}
@Test
@@ -78,10 +85,9 @@
/* autoSupported= */true, /* autoEnabled= */false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, true /* isFromSUW */);
+ mController.setFromSUW(true);
- assertThat(controller.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@@ -90,10 +96,9 @@
/* autoSupported= */true, /* autoEnabled= */false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, false /* isFromSUW */);
+ mController.setFromSUW(false);
- assertThat(controller.isAvailable()).isTrue();
+ assertThat(mController.isAvailable()).isTrue();
}
@Test
@@ -102,10 +107,7 @@
/* autoSupported= */false, /* autoEnabled= */false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, false /* fromSUW */);
-
- assertThat(controller.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@@ -114,10 +116,9 @@
/* autoSupported= */false, /* autoEnabled= */false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, true /* fromSUW */);
+ mController.setFromSUW(true);
- assertThat(controller.isEnabled()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@@ -126,10 +127,9 @@
/* autoSupported= */false, /* autoEnabled= */true);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, true /* fromSUW */);
+ mController.setFromSUW(true);
- assertThat(controller.isEnabled()).isTrue();
+ assertThat(mController.isAvailable()).isTrue();
}
@Test
@@ -138,34 +138,27 @@
/* autoSupported= */false, /* autoEnabled= */false);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, false /* fromSUW */);
-
- assertThat(controller.isEnabled()).isFalse();
+ assertThat(mController.isEnabled()).isFalse();
}
@Test
- public void testIsEnabled_shouldReadFromTimeManagerConfig() {
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, null /* callback */, false /* fromSUW */);
+ public void isEnabled_autoEnabledIsFalse_shouldReadFromTimeManagerConfig() {
+ // Disabled
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
+ /* autoSupported= */true, /* autoEnabled= */false);
+ when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- {
- // Disabled
- TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
- /* autoSupported= */true, /* autoEnabled= */false);
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
+ assertThat(mController.isEnabled()).isFalse();
+ }
- assertThat(controller.isEnabled()).isFalse();
- }
+ @Test
+ public void isEnabled_autoEnabledIsTrue_shouldReadFromTimeManagerConfig() {
+ // Enabled
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
+ /* autoSupported= */true, /* autoEnabled= */true);
+ when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- {
- // Enabled
- TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
- /* autoSupported= */true, /* autoEnabled= */true);
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
-
- assertThat(controller.isEnabled()).isTrue();
- }
+ assertThat(mController.isEnabled()).isTrue();
}
@Test
@@ -175,10 +168,9 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, mCallback, false /* fromSUW */);
+ mController.setTimeAndDateCallback(mCallback);
- assertThat(controller.onPreferenceChange(mPreference, true)).isTrue();
+ assertThat(mController.onPreferenceChange(mPreference, true)).isTrue();
verify(mCallback).updateTimeAndDateDisplay(mContext);
// Check the service was asked to change the configuration correctly.
@@ -193,7 +185,7 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
.thenReturn(capabilitiesAndConfigAfterUpdate);
- assertThat(controller.isEnabled()).isTrue();
+ assertThat(mController.isEnabled()).isTrue();
}
@Test
@@ -203,10 +195,9 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, mCallback, false /* fromSUW */);
+ mController.setTimeAndDateCallback(mCallback);
- assertThat(controller.onPreferenceChange(mPreference, false)).isTrue();
+ assertThat(mController.onPreferenceChange(mPreference, false)).isTrue();
verify(mCallback).updateTimeAndDateDisplay(mContext);
// Check the service was asked to change the configuration correctly.
@@ -221,13 +212,12 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
.thenReturn(capabilitiesAndConfigAfterUpdate);
- assertThat(controller.isEnabled()).isFalse();
+ assertThat(mController.isEnabled()).isFalse();
}
@Test
public void getSummary() {
- AutoTimeZonePreferenceController controller = new AutoTimeZonePreferenceController(
- mContext, mCallback, false /* fromSUW */);
+ mController.setTimeAndDateCallback(mCallback);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
@@ -235,7 +225,7 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
- assertThat(controller.getSummary()).isEqualTo("");
+ assertThat(mController.getSummary()).isEqualTo("");
capabilitiesAndConfig = createCapabilitiesAndConfig(
/* autoSupported= */true, /* autoEnabled= */true, /* telephonySupported= */
@@ -243,7 +233,7 @@
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
when(mTimeManager.updateTimeZoneConfiguration(Mockito.any())).thenReturn(true);
- assertThat(controller.getSummary()).isEqualTo(
+ assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.auto_zone_requires_location_summary));
}
diff --git a/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
index ce9c701..b1996a6 100644
--- a/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/DatePreferenceControllerTest.java
@@ -74,12 +74,8 @@
when(mContext.getSystemService(TimeDetector.class)).thenReturn(mTimeDetector);
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
mPreference = new RestrictedPreference(RuntimeEnvironment.application);
- mController = new DatePreferenceController(mContext, mHost);
- }
-
- @Test
- public void isAlwaysAvailable() {
- assertThat(mController.isAvailable()).isTrue();
+ mController = new DatePreferenceController(mContext, "test_key");
+ mController.setHost(mHost);
}
@Test
@@ -147,7 +143,7 @@
assertEquals(2020, calendar.get(Calendar.YEAR));
}
- private static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
+ static TimeCapabilitiesAndConfig createCapabilitiesAndConfig(
boolean suggestManualAllowed) {
int suggestManualCapability = suggestManualAllowed ? Capabilities.CAPABILITY_POSSESSED
: Capabilities.CAPABILITY_NOT_SUPPORTED;
diff --git a/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
index ec47a54..e1ea8f9 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimeFormatPreferenceControllerTest.java
@@ -16,13 +16,15 @@
package com.android.settings.datetime;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
+
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
-import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import org.junit.Before;
@@ -52,27 +54,30 @@
MockitoAnnotations.initMocks(this);
mApplication = ShadowApplication.getInstance();
mContext = RuntimeEnvironment.application;
+ mController = new TimeFormatPreferenceController(mContext, "test_key");
+ mController.setTimeAndDateCallback(mCallback);
+ mController.setFromSUW(false);
+
+ mPreference = new SwitchPreference(mContext);
+ mPreference.setKey("test_key");
}
@Test
public void isCalledFromSUW_NotAvailable() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, true);
+ mController.setFromSUW(true);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
public void notCalledFromSUW_shouldBeAvailable() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
-
- assertThat(mController.isAvailable()).isTrue();
+ Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
+ TimeFormatPreferenceController.HOURS_24);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void updateState_24HourSet_shouldCheckPreference() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
TimeFormatPreferenceController.HOURS_24);
@@ -83,9 +88,6 @@
@Test
public void updateState_12HourSet_shouldNotCheckPreference() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24,
TimeFormatPreferenceController.HOURS_12);
@@ -96,10 +98,7 @@
@Test
public void updateState_autoSet_shouldNotEnablePreference() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
Settings.System.putString(mContext.getContentResolver(), Settings.System.TIME_12_24, null);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
mController.updateState(mPreference);
@@ -108,14 +107,7 @@
@Test
public void updatePreference_12HourSet_shouldSendIntent() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
- mPreference.setChecked(false);
-
- boolean result = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(result).isTrue();
+ mController.setChecked(false);
List<Intent> intentsFired = mApplication.getBroadcastIntents();
assertThat(intentsFired.size()).isEqualTo(1);
@@ -127,14 +119,7 @@
@Test
public void updatePreference_24HourSet_shouldSendIntent() {
- mController = new TimeFormatPreferenceController(mContext, mCallback, false);
- mPreference = new SwitchPreference(mContext);
- mPreference.setKey(mController.getPreferenceKey());
- mPreference.setChecked(true);
-
- boolean result = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(result).isTrue();
+ mController.setChecked(true);
List<Intent> intentsFired = mApplication.getBroadcastIntents();
assertThat(intentsFired.size()).isEqualTo(1);
diff --git a/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
index ebb56f4..ef0d69e 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimePreferenceControllerTest.java
@@ -18,9 +18,12 @@
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.TimeCapabilitiesAndConfig;
+import android.app.time.TimeManager;
import android.content.Context;
import com.android.settingslib.RestrictedPreference;
@@ -40,7 +43,7 @@
@Mock
private TimePreferenceController.TimePreferenceHost mHost;
@Mock
- private DatePreferenceController mDatePreferenceController;
+ private TimeManager mTimeManager;
private TimePreferenceController mController;
private RestrictedPreference mPreference;
@@ -48,14 +51,11 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- mPreference = new RestrictedPreference(RuntimeEnvironment.application);
- mController = new TimePreferenceController(mContext, mHost, mDatePreferenceController);
- }
-
- @Test
- public void isAlwaysAvailable() {
- assertThat(mController.isAvailable()).isTrue();
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
+ mPreference = new RestrictedPreference(mContext);
+ mController = new TimePreferenceController(mContext, "test_key");
+ mController.setHost(mHost);
}
@Test
@@ -63,7 +63,10 @@
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
- when(mDatePreferenceController.isEnabled()).thenReturn(false);
+ TimeCapabilitiesAndConfig capabilitiesAndConfig =
+ DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
+ false);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
@@ -74,7 +77,10 @@
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
- when(mDatePreferenceController.isEnabled()).thenReturn(true);
+ TimeCapabilitiesAndConfig capabilitiesAndConfig =
+ DatePreferenceControllerTest.createCapabilitiesAndConfig(/* suggestManualAllowed= */
+ true);
+ when(mTimeManager.getTimeCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isTrue();
diff --git a/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
index 10a5e5d..fec410b 100644
--- a/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/TimeZonePreferenceControllerTest.java
@@ -66,16 +66,11 @@
mPreference = new RestrictedPreference(mContext);
- mController = spy(new TimeZonePreferenceController(mContext));
+ mController = spy(new TimeZonePreferenceController(mContext, "test_key"));
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
}
@Test
- public void isAlwaysAvailable() {
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
public void updateState_suggestManualNotAllowed_shouldDisablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java
index 36c9231..d7f5db5 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothLeAudioDeviceDetailsPreferenceControllerTest.java
@@ -81,7 +81,6 @@
mController.onPreferenceChange(mPreference, true /* new value */);
final boolean isEnabled = SystemProperties.getBoolean(
LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, false);
-
assertThat(isEnabled).isTrue();
}
@@ -91,7 +90,6 @@
mController.onPreferenceChange(mPreference, false /* new value */);
final boolean isEnabled = SystemProperties.getBoolean(
LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, true);
-
assertThat(isEnabled).isFalse();
}
@@ -99,6 +97,7 @@
public void updateState_settingEnabled_preferenceShouldBeChecked() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "true");
+ mController.mLeAudioEnabledByDefault = false;
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
}
@@ -107,8 +106,8 @@
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
mController.sLeAudioSupportedStateCache = BluetoothStatusCodes.FEATURE_SUPPORTED;
SystemProperties.set(LE_AUDIO_TOGGLE_VISIBLE_PROPERTY, "false");
+ mController.mLeAudioEnabledByDefault = false;
mController.updateState(mPreference);
-
verify(mPreference).setChecked(false);
}
diff --git a/tests/robotests/src/com/android/settings/development/DevelopmentMemtagPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DevelopmentMemtagPreferenceControllerTest.java
index d4af470..229f2fa 100644
--- a/tests/robotests/src/com/android/settings/development/DevelopmentMemtagPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/DevelopmentMemtagPreferenceControllerTest.java
@@ -38,6 +38,7 @@
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,13 +47,14 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSystemProperties;
+@Ignore("b/313564061")
@RunWith(RobolectricTestRunner.class)
@Config(
shadows = {
- ZygoteShadow.class,
- ShadowDeviceConfig.class,
- ShadowInteractionJankMonitor.class,
- ShadowRestrictedLockUtilsInternal.class
+ ZygoteShadow.class,
+ ShadowDeviceConfig.class,
+ ShadowInteractionJankMonitor.class,
+ ShadowRestrictedLockUtilsInternal.class
})
public class DevelopmentMemtagPreferenceControllerTest {
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
diff --git a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
index dffd7fb..5a679ad 100644
--- a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
+++ b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
@@ -51,6 +51,7 @@
import com.android.settings.R;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -140,6 +141,7 @@
R.string.platform_compat_selected_app_summary, APP_NAME, 1));
}
+ @Ignore("b/313591873")
@Test
public void createPreferenceForChange_defaultEnabledChange_createCheckedEntry() {
CompatibilityChangeInfo enabledChange = mChanges[0];
@@ -158,6 +160,7 @@
assertThat(enabledSwitchPreference.isEnabled()).isTrue();
}
+ @Ignore("b/313591873")
@Test
public void createPreferenceForChange_defaultDisabledChange_createUncheckedEntry() {
CompatibilityChangeInfo disabledChange = mChanges[1];
@@ -174,6 +177,7 @@
assertThat(disabledSwitchPreference.isEnabled()).isTrue();
}
+ @Ignore("b/313591873")
@Test
public void createPreferenceForChange_cannotOverride_createDisabledEntry()
throws RemoteException {
@@ -195,6 +199,7 @@
assertThat(switchPreference.isEnabled()).isFalse();
}
+ @Ignore("b/313591873")
@Test
public void createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries() {
Set<Long> enabledChanges = new HashSet<>();
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
index a326061..a70753a 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
@@ -40,6 +40,7 @@
import androidx.preference.Preference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -114,6 +115,7 @@
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
+ @Ignore("b/313567396")
@Test
public void updateState_canHandleV2Intent_setIntentToPreference() throws Exception {
setupModulePackage("test version 123");
@@ -127,6 +129,7 @@
assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_V2_INTENT);
}
+ @Ignore("b/313567396")
@Test
public void updateState_canHandleV2Intent_preferenceShouldBeSelectable() throws Exception {
setupModulePackage("test version 123");
@@ -140,6 +143,7 @@
assertThat(mPreference.isSelectable()).isTrue();
}
+ @Ignore("b/313567396")
@RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT)
@Test
public void updateState_canHandleIntent_setIntentToPreference() throws Exception {
@@ -155,6 +159,7 @@
assertThat(mPreference.getIntent()).isEqualTo(MODULE_UPDATE_INTENT);
}
+ @Ignore("b/313567396")
@RequiresFlagsEnabled(com.android.settings.flags.Flags.FLAG_MAINLINE_MODULE_EXPLICIT_INTENT)
@Test
public void updateState_canHandleIntent_preferenceShouldBeSelectable() throws Exception {
diff --git a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
index 6302f80..5262a16 100644
--- a/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/LabeledSeekBarPreferenceTest.java
@@ -42,6 +42,7 @@
import com.android.settings.widget.LabeledSeekBarPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -150,6 +151,7 @@
assertThat(mLabelFrame.getVisibility()).isEqualTo(View.GONE);
}
+ @Ignore("b/313594999")
@Test
public void setIconAttributes_iconVisible() {
final AttributeSet attributeSet = Robolectric.buildAttributeSet()
@@ -204,6 +206,7 @@
new LabeledSeekBarPreference(mContext, attributeSet);
}
+ @Ignore("b/313594999")
@Test
public void setContentDescriptionWithIcon_success() {
final String startDescription =
diff --git a/tests/robotests/src/com/android/settings/gestures/OneHandedActionPullDownPrefControllerTest.java b/tests/robotests/src/com/android/settings/gestures/OneHandedActionPullDownPrefControllerTest.java
index e6b0343..de07fe0 100644
--- a/tests/robotests/src/com/android/settings/gestures/OneHandedActionPullDownPrefControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/OneHandedActionPullDownPrefControllerTest.java
@@ -26,6 +26,7 @@
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -76,6 +77,7 @@
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
+ @Ignore("b/313541907")
@Test
public void getAvailabilityStatus_setNavi3ButtonMode_shouldDisabled() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
diff --git a/tests/robotests/src/com/android/settings/gestures/OneHandedActionShowNotificationPrefControllerTest.java b/tests/robotests/src/com/android/settings/gestures/OneHandedActionShowNotificationPrefControllerTest.java
index da27191..6d13056 100644
--- a/tests/robotests/src/com/android/settings/gestures/OneHandedActionShowNotificationPrefControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/OneHandedActionShowNotificationPrefControllerTest.java
@@ -26,6 +26,7 @@
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -85,6 +86,7 @@
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
+ @Ignore("b/313541907")
@Test
public void getAvailabilityStatus_setNavi3ButtonMode_shouldDisabled() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
diff --git a/tests/robotests/src/com/android/settings/gestures/OneHandedMainSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/OneHandedMainSwitchPreferenceControllerTest.java
index 599d4e0..118c58a 100644
--- a/tests/robotests/src/com/android/settings/gestures/OneHandedMainSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/OneHandedMainSwitchPreferenceControllerTest.java
@@ -25,6 +25,7 @@
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -83,6 +84,7 @@
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
+ @Ignore("b/313541907")
@Test
public void getAvailabilityStatus_set3ButtonMode_shouldDisabled() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
diff --git a/tests/robotests/src/com/android/settings/gestures/OneHandedPreferenceCategoryControllerTest.java b/tests/robotests/src/com/android/settings/gestures/OneHandedPreferenceCategoryControllerTest.java
index 112e04a..b3d4934 100644
--- a/tests/robotests/src/com/android/settings/gestures/OneHandedPreferenceCategoryControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/OneHandedPreferenceCategoryControllerTest.java
@@ -30,6 +30,7 @@
import com.android.settings.R;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -61,6 +62,7 @@
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
+ @Ignore("b/313541907")
@Test
public void getTitle_set3ButtonMode_shouldReturnSetShortcutTo() {
mUtils.setNavigationBarMode(mContext, "0" /* 3 button */);
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
index 58a8d5b..9e83641 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/GrayscaleConditionControllerTest.java
@@ -29,6 +29,7 @@
import android.os.UserHandle;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -56,6 +57,7 @@
mController = new GrayscaleConditionController(mContext, mConditionManager);
}
+ @Ignore("b/313597163")
@Test
public void isDisplayable_noIntent_shouldReturnFalse() {
assertThat(mController.isDisplayable()).isFalse();
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/DarkThemeSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/DarkThemeSliceTest.java
index f5f3d59..4377ec0 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/DarkThemeSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/DarkThemeSliceTest.java
@@ -42,6 +42,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -129,6 +130,7 @@
assertThat(mDarkThemeSlice.isAvailable(mContext)).isTrue();
}
+ @Ignore("b/313598030")
@Test
public void getSlice_batterySaver_returnErrorSlice() {
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
@@ -138,6 +140,7 @@
assertThat(metadata.isErrorSlice()).isTrue();
}
+ @Ignore("b/313598030")
@Test
public void getSlice_notAvailable_returnErrorSlice() {
mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_YES;
@@ -147,6 +150,7 @@
assertThat(metadata.isErrorSlice()).isTrue();
}
+ @Ignore("b/313598030")
@Test
public void getSlice_newSession_notAvailable_returnErrorSlice() {
// previous displayed: yes
@@ -173,6 +177,7 @@
assertThat(mDarkThemeSlice.getSlice()).isNotNull();
}
+ @Ignore("b/313598030")
@Test
public void getSlice_sliceNotClicked_notAvailable_returnErrorSlice() {
mDarkThemeSlice.sSliceClicked = false;
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
index 8dad372..71c839d 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SliceContextualCardRendererTest.java
@@ -50,6 +50,7 @@
import com.android.settings.homepage.contextualcards.ControllerRendererPool;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -100,6 +101,7 @@
.isNull();
}
+ @Ignore("b/313598030")
@Test
public void bindView_viewTypeFullWidth_shouldSetCachedSlice() {
final RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
@@ -111,6 +113,7 @@
.isNotNull();
}
+ @Ignore("b/313598030")
@Test
public void bindView_viewTypeSticky_shouldSetCachedSlice() {
final RecyclerView.ViewHolder viewHolder = spy(getStickyViewHolder());
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java
index 3e5934b..89a9ca8 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/SwipeDismissalDelegateTest.java
@@ -36,6 +36,7 @@
import com.android.settings.homepage.contextualcards.slices.SliceFullCardRendererHelper.SliceViewHolder;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -67,12 +68,14 @@
mDismissalDelegate = new SwipeDismissalDelegate(mDismissalDelegateListener);
}
+ @Ignore("b/313598030")
@Test
public void getMovementFlags_conditionalViewHolder_shouldDisableSwipe() {
assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, getConditionalViewHolder()))
.isEqualTo(0);
}
+ @Ignore("b/313598030")
@Test
public void getMovementFlags_dismissalView_shouldDisableSwipe() {
final RecyclerView.ViewHolder holder = getSliceViewHolder();
@@ -81,6 +84,7 @@
assertThat(mDismissalDelegate.getMovementFlags(mRecyclerView, holder)).isEqualTo(0);
}
+ @Ignore("b/313598030")
@Test
public void getMovementFlags_SliceViewHolder_shouldEnableSwipe() {
final RecyclerView.ViewHolder holder = getSliceViewHolder();
@@ -90,6 +94,7 @@
.isNotEqualTo(0);
}
+ @Ignore("b/313598030")
@Test
public void onSwipe_shouldNotifyListener() {
mDismissalDelegate.onSwiped(getSliceViewHolder(), 1);
diff --git a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
index 817df4c..2ad24f2 100644
--- a/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/AppLocalePickerActivityTest.java
@@ -58,6 +58,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -202,6 +203,7 @@
assertThat(controller.get().isFinishing()).isTrue();
}
+ @Ignore("b/313604701")
@Test
public void onLocaleSelected_getLocaleNotNull_getLanguageTag() {
ActivityController<TestAppLocalePickerActivity> controller =
diff --git a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
index bed3346..8726fc3 100644
--- a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
@@ -44,6 +44,7 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -114,6 +115,7 @@
verify(mContext).unregisterReceiver(mController.mInjectedSettingsReceiver);
}
+ @Ignore("b/313540388")
@Test
public void workProfileDisallowShareLocationOn_getParentUserLocationServicesOnly() {
final int fakeWorkProfileId = 123;
@@ -166,6 +168,7 @@
verify(mSettingsInjector).reloadStatusMessages();
}
+ @Ignore("b/313540388")
@Test
public void withUserRestriction_shouldDisableLocationAccuracy() {
final List<Preference> preferences = new ArrayList<>();
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
index 7248ff6..a91f627 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
@@ -54,6 +54,7 @@
import com.android.settingslib.media.MediaOutputConstants;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -151,6 +152,7 @@
assertThat(metadata.isErrorSlice()).isFalse();
}
+ @Ignore("b/313605377")
@Test
public void getSlice_noConnectedDevice_returnErrorSlice() {
mDevices.clear();
@@ -163,6 +165,7 @@
assertThat(metadata.isErrorSlice()).isTrue();
}
+ @Ignore("b/313605377")
@Test
public void getSlice_audioModeIsInCommunication_returnErrorSlice() {
mDevices.add(mDevice1);
@@ -177,6 +180,7 @@
assertThat(metadata.isErrorSlice()).isTrue();
}
+ @Ignore("b/313605377")
@Test
public void getSlice_audioModeIsRingtone_returnErrorSlice() {
mDevices.add(mDevice1);
@@ -191,6 +195,7 @@
assertThat(metadata.isErrorSlice()).isTrue();
}
+ @Ignore("b/313605377")
@Test
public void getSlice_audioModeIsInCall_returnErrorSlice() {
mDevices.add(mDevice1);
diff --git a/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java
deleted file mode 100644
index 15e24e1..0000000
--- a/tests/robotests/src/com/android/settings/network/AllInOneTetherPreferenceControllerTest.java
+++ /dev/null
@@ -1,187 +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.network;
-
-import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
-import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
-
-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 static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.Context;
-
-import androidx.preference.PreferenceScreen;
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.settings.R;
-import com.android.settingslib.PrimarySwitchPreference;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.ParameterizedRobolectricTestRunner;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-
-@RunWith(ParameterizedRobolectricTestRunner.class)
-public class AllInOneTetherPreferenceControllerTest {
-
- @ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
- public static List params() {
- return Arrays.asList(new Object[][] {
- {TETHERING_OFF, R.string.tether_settings_summary_off},
- {TETHERING_WIFI_ON, R.string.tether_settings_summary_hotspot_only},
- {TETHERING_USB_ON, R.string.tether_settings_summary_usb_tethering_only},
- {TETHERING_BLUETOOTH_ON, R.string.tether_settings_summary_bluetooth_tethering_only},
- {TETHERING_ETHERNET_ON, R.string.tether_settings_summary_ethernet_tethering_only},
- {
- TETHERING_WIFI_ON | TETHERING_USB_ON,
- R.string.tether_settings_summary_hotspot_and_usb
- },
- {
- TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON,
- R.string.tether_settings_summary_hotspot_and_bluetooth
- },
- {
- TETHERING_WIFI_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_hotspot_and_ethernet
- },
- {
- TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
- R.string.tether_settings_summary_usb_and_bluetooth
- },
- {
- TETHERING_USB_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_usb_and_ethernet
- },
- {
- TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_bluetooth_and_ethernet
- },
- {
- TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
- R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth
- },
- {
- TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_hotspot_and_usb_and_ethernet
- },
- {
- TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet
- },
- {
- TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet
- },
- {
- TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
- | TETHERING_ETHERNET_ON,
- R.string.tether_settings_summary_all
- }
- });
- }
-
- private Context mContext;
- @Mock
- private BluetoothAdapter mBluetoothAdapter;
- @Mock
- private PrimarySwitchPreference mPreference;
-
- private static final String PREF_KEY = "tether";
- private AllInOneTetherPreferenceController mController;
- private final int mTetherState;
- private final int mSummaryResId;
-
- public AllInOneTetherPreferenceControllerTest(int tetherState, int summaryResId) {
- mTetherState = tetherState;
- mSummaryResId = summaryResId;
- }
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- MockitoAnnotations.initMocks(this);
- doReturn(null).when(mContext)
- .getSystemService(Context.DEVICE_POLICY_SERVICE);
- mController = spy(new AllInOneTetherPreferenceController(mContext, /* key= */ "test"));
- ReflectionHelpers.setField(mController, "mContext", mContext);
- ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
- ReflectionHelpers.setField(mController, "mPreferenceKey", PREF_KEY);
- PreferenceScreen screen = mock(PreferenceScreen.class);
- when(screen.findPreference(PREF_KEY)).thenReturn(mPreference);
- doReturn(mController.AVAILABLE).when(mController).getAvailabilityStatus();
- mController.displayPreference(screen);
- }
-
- @Test
- public void onCreate_shouldInitBluetoothPan() {
- when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
- mController.onCreate();
-
- verify(mBluetoothAdapter).getState();
- verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
-
- @Test
- public void onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
- when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
- mController.onCreate();
-
- verify(mBluetoothAdapter).getState();
- verifyNoMoreInteractions(mBluetoothAdapter);
- }
-
- @Test
- public void goThroughLifecycle_shouldDestroyBluetoothProfile() {
- final BluetoothPan pan = mock(BluetoothPan.class);
- final AtomicReference<BluetoothPan> panRef =
- ReflectionHelpers.getField(mController, "mBluetoothPan");
- panRef.set(pan);
-
- mController.onDestroy();
-
- verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
- }
-
- @Test
- public void getSummary_afterTetherStateChanged() {
- mController.onTetherStateUpdated(mTetherState);
- assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
-
- verify(mController).updateState(mPreference);
- verify(mPreference).setSummary(mContext.getString(mSummaryResId));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
deleted file mode 100644
index d3a3129..0000000
--- a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.bluetooth.BluetoothAdapter;
-import android.content.Context;
-import android.net.TetheringManager;
-
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-
-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;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-public class BluetoothTetherPreferenceControllerTest {
-
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private TetherEnabler mTetherEnabler;
-
- private SwitchPreference mSwitchPreference;
- private BluetoothTetherPreferenceController mController;
- private Context mContext;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(ApplicationProvider.getApplicationContext());
- mSwitchPreference = spy(SwitchPreference.class);
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
- when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
- mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
- mController.setTetherEnabler(mTetherEnabler);
- ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
- }
-
- @Test
- public void lifecycle_shouldRegisterReceiverOnStart() {
- mController.onStart();
-
- verify(mContext).registerReceiver(
- eq(mController.mBluetoothChangeReceiver),
- any());
- }
-
- @Test
- public void lifecycle_shouldAddListenerOnResume() {
- mController.onResume();
- verify(mTetherEnabler).addListener(mController);
- }
-
- @Test
- public void lifecycle_shouldRemoveListenrOnPause() {
- mController.onPause();
- verify(mTetherEnabler).removeListener(mController);
- }
-
- @Test
- public void lifecycle_shouldUnregisterReceiverOnStop() {
- mController.onStart();
- mController.onStop();
-
- verify(mContext).unregisterReceiver(
- eq(mController.mBluetoothChangeReceiver));
- }
-
- @Test
- public void shouldShow_noBluetoothTetherable() {
- when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
- assertThat(mController.isAvailable()).isFalse();
- }
-
- @Test
- public void shouldEnable_transientState() {
- ReflectionHelpers.setField(mController, "mBluetoothState",
- BluetoothAdapter.STATE_TURNING_OFF);
- assertThat(mController.shouldEnable()).isFalse();
- }
- @Test
- public void setChecked_shouldStartBluetoothTethering() {
- mController.setChecked(true);
- verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_BLUETOOTH);
- }
-
- @Test
- public void setUnchecked_shouldStopBluetoothTethering() {
- mController.setChecked(false);
- verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_BLUETOOTH);
- }
-
- @Test
- public void switch_shouldCheckedWhenBluetoothTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_BLUETOOTH_ON);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void switch_shouldUnCheckedWhenBluetoothNotTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
- assertThat(mController.isChecked()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
deleted file mode 100644
index 68d80d4..0000000
--- a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
+++ /dev/null
@@ -1,143 +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.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.EthernetManager;
-import android.net.TetheringManager;
-
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-
-import org.junit.Before;
-import org.junit.Ignore;
-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;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-public class EthernetTetherPreferenceControllerTest {
-
- @Rule
- public MockitoRule mocks = MockitoJUnit.rule();
-
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private EthernetManager mEthernetManager;
- @Mock
- private TetherEnabler mTetherEnabler;
-
- private Context mContext;
- private EthernetTetherPreferenceController mController;
- private SwitchPreference mPreference;
- private static final String ETHERNET_REGEX = "ethernet";
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
- mPreference = spy(SwitchPreference.class);
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
- when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
- when(mContext.getSystemService(EthernetManager.class)).thenReturn(mEthernetManager);
- mController = new EthernetTetherPreferenceController(mContext, "ethernet");
- mController.setTetherEnabler(mTetherEnabler);
- ReflectionHelpers.setField(mController, "mPreference", mPreference);
- }
-
- @Test
- @Ignore
- public void lifecycle_shouldRegisterReceiverOnStart() {
- mController.onStart();
-
- verify(mEthernetManager).addInterfaceStateListener(any(),
- eq(mController.mEthernetListener));
- }
-
- @Test
- public void lifecycle_shouldAddListenerOnResume() {
- mController.onResume();
- verify(mTetherEnabler).addListener(mController);
- }
-
- @Test
- public void lifecycle_shouldRemoveListenerOnPause() {
- mController.onPause();
- verify(mTetherEnabler).removeListener(mController);
- }
-
- @Test
- public void lifecycle_shouldUnregisterReceiverOnStop() {
- mController.onStart();
- EthernetManager.InterfaceStateListener listener = mController.mEthernetListener;
- mController.onStop();
-
- verify(mEthernetManager).removeInterfaceStateListener(eq(listener));
- }
-
- @Test
- public void shouldEnable_noTetherable() {
- when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
- assertThat(mController.shouldEnable()).isFalse();
- }
-
- @Test
- public void shouldShow_noEthernetInterface() {
- when(mContext.getSystemService(EthernetManager.class)).thenReturn(null);
-
- final EthernetTetherPreferenceController controller =
- new EthernetTetherPreferenceController(mContext, "ethernet");
- assertThat(controller.shouldShow()).isFalse();
- }
-
- @Test
- public void setChecked_shouldStartEthernetTethering() {
- mController.setChecked(true);
- verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_ETHERNET);
- }
-
- @Test
- public void setUnchecked_shouldStopEthernetTethering() {
- mController.setChecked(false);
- verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_ETHERNET);
- }
-
- @Test
- public void switch_shouldCheckedWhenEthernetTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_ETHERNET_ON);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void switch_shouldUnCheckedWhenEthernetNotTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
- assertThat(mController.isChecked()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index b1bd41d..fb29e05 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -82,6 +82,7 @@
import com.android.wifitrackerlib.WifiPickerTracker;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -397,6 +398,7 @@
verify(mContextMenu, never()).add(anyInt(), eq(MENU_ID_SHARE), anyInt(), anyInt());
}
+ @Ignore("b/313585353")
@Test
public void onWifiEntriesChanged_shouldChangeNextButtonState() {
mNetworkProviderSettings.onWifiEntriesChanged();
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
deleted file mode 100644
index 99869d8..0000000
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ /dev/null
@@ -1,212 +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.network;
-
-import static org.mockito.Mockito.any;
-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 static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
-
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothPan;
-import android.bluetooth.BluetoothProfile;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.database.ContentObserver;
-import android.net.TetheringManager;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-@RunWith(RobolectricTestRunner.class)
-public class TetherPreferenceControllerTest {
-
- @Mock
- private Context mContext;
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private BluetoothAdapter mBluetoothAdapter;
- @Mock
- private Preference mPreference;
-
- private TetherPreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- doReturn(null).when(mContext)
- .getSystemService(Context.DEVICE_POLICY_SERVICE);
- mController = spy(new TetherPreferenceController(mContext, /* lifecycle= */ null));
- ReflectionHelpers.setField(mController, "mContext", mContext);
- ReflectionHelpers.setField(mController, "mTetheringManager", mTetheringManager);
- ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
- ReflectionHelpers.setField(mController, "mPreference", mPreference);
- }
-
- @Test
- public void lifeCycle_onCreate_shouldInitBluetoothPan() {
- when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
- mController.onCreate(null);
-
- verify(mBluetoothAdapter).getState();
- verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
-
- @Test
- public void lifeCycle_onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
- when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
- mController.onCreate(null);
-
- verify(mBluetoothAdapter).getState();
- verifyNoMoreInteractions(mBluetoothAdapter);
- }
-
- @Test
- public void goThroughLifecycle_shouldDestoryBluetoothProfile() {
- final BluetoothPan pan = mock(BluetoothPan.class);
- final AtomicReference<BluetoothPan> panRef =
- ReflectionHelpers.getField(mController, "mBluetoothPan");
- panRef.set(pan);
-
- mController.onDestroy();
-
- verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
- }
-
- @Test
- public void updateSummary_noPreference_noInteractionWithTetheringManager() {
- ReflectionHelpers.setField(mController, "mPreference", null);
- mController.updateSummary();
- verifyNoMoreInteractions(mTetheringManager);
- }
-
- @Test
- public void updateSummary_wifiTethered_shouldShowHotspotMessage() {
- when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"123"});
-
- mController.updateSummary();
- verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_off);
- }
-
- @Test
- public void updateSummary_btThetherOn_shouldShowTetherMessage() {
- when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123"});
- when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
-
- mController.updateSummary();
- verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_off_tether_on);
- }
-
- @Ignore
- @Test
- public void updateSummary_tetherOff_shouldShowTetherOffMessage() {
- when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"123"});
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
-
- mController.updateSummary();
- verify(mPreference).setSummary(R.string.switch_off_text);
- }
-
- @Test
- public void updateSummary_wifiBtTetherOn_shouldShowHotspotAndTetherMessage() {
- when(mTetheringManager.getTetheredIfaces()).thenReturn(new String[]{"123", "456"});
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"456"});
- when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[]{"23"});
-
- mController.updateSummary();
- verify(mPreference).setSummary(R.string.tether_settings_summary_hotspot_on_tether_on);
- }
-
- @Ignore
- @Test
- public void airplaneModeOn_shouldUpdateSummaryToOff() {
- final Context context = RuntimeEnvironment.application;
- ReflectionHelpers.setField(mController, "mContext", context);
-
- Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
-
- mController.onResume();
-
- verifyNoInteractions(mPreference);
-
- Settings.Global.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
-
- final ContentObserver observer =
- ReflectionHelpers.getField(mController, "mAirplaneModeObserver");
- observer.onChange(true, Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON));
-
- verify(mPreference).setSummary(R.string.switch_off_text);
- }
-
- @Test
- public void onResume_shouldRegisterTetherReceiver() {
- when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
-
- mController.onResume();
-
- verify(mContext).registerReceiver(
- any(TetherPreferenceController.TetherBroadcastReceiver.class),
- any(IntentFilter.class));
- }
-
- @Test
- public void onPause_shouldUnregisterTetherReceiver() {
- when(mContext.getContentResolver()).thenReturn(mock(ContentResolver.class));
- mController.onResume();
-
- mController.onPause();
-
- verify(mContext)
- .unregisterReceiver(any(TetherPreferenceController.TetherBroadcastReceiver.class));
- }
-
- @Test
- public void tetherStatesChanged_shouldUpdateSummary() {
- final Context context = RuntimeEnvironment.application;
- ReflectionHelpers.setField(mController, "mContext", context);
- mController.onResume();
-
- context.sendBroadcast(new Intent(TetheringManager.ACTION_TETHER_STATE_CHANGED));
-
- shadowMainLooper().idle();
- verify(mController).updateSummary();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
deleted file mode 100644
index e02da90..0000000
--- a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.TetheringManager;
-
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-
-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;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-public class UsbTetherPreferenceControllerTest {
-
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private TetherEnabler mTetherEnabler;
-
- private Context mContext;
- private UsbTetherPreferenceController mController;
- private SwitchPreference mSwitchPreference;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
- when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
- mController = new UsbTetherPreferenceController(mContext, "USB");
- mController.setTetherEnabler(mTetherEnabler);
- mSwitchPreference = spy(SwitchPreference.class);
- ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
- }
-
- @Test
- public void lifecycle_shouldRegisterReceiverOnStart() {
- mController.onStart();
-
- verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
- }
-
- @Test
- public void lifecycle_shouldAddListenerOnResume() {
- mController.onResume();
- verify(mTetherEnabler).addListener(mController);
- }
-
- @Test
- public void lifecycle_shouldRemoveListenrOnPause() {
- mController.onPause();
- verify(mTetherEnabler).removeListener(mController);
- }
-
- @Test
- public void lifecycle_shouldUnregisterReceiverOnStop() {
- mController.onStart();
- mController.onStop();
-
- verify(mContext).unregisterReceiver(eq(mController.mUsbChangeReceiver));
- }
-
- @Test
- public void shouldShow_noTetherableUsb() {
- when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
- assertThat(mController.shouldShow()).isFalse();
- }
-
- @Test
- public void shouldEnable_noUsbConnected() {
- ReflectionHelpers.setField(mController, "mUsbConnected", false);
- assertThat(mController.shouldEnable()).isFalse();
- }
-
- @Test
- public void setChecked_shouldStartUsbTethering() {
- mController.setChecked(true);
- verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_USB);
- }
-
- @Test
- public void setUnchecked_shouldStopUsbTethering() {
- mController.setChecked(false);
- verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_USB);
- }
-
- @Test
- public void switch_shouldCheckedWhenUsbTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_USB_ON);
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void switch_shouldUnCheckedWhenUsbNotTethering() {
- mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
- assertThat(mController.isChecked()).isFalse();
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
deleted file mode 100644
index a82a71f..0000000
--- a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network;
-
-import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
-import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
-import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
-import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.TetheringManager;
-
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.ParameterizedRobolectricTestRunner;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.Arrays;
-import java.util.List;
-
-@RunWith(ParameterizedRobolectricTestRunner.class)
-public class WifiTetherDisablePreferenceControllerTest {
-
- @ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
- public static List params() {
- return Arrays.asList(new Object[][] {
- {TETHERING_OFF, R.string.summary_placeholder},
- {TETHERING_USB_ON, R.string.disable_wifi_hotspot_when_usb_on},
- {TETHERING_BLUETOOTH_ON, R.string.disable_wifi_hotspot_when_bluetooth_on},
- {TETHERING_ETHERNET_ON, R.string.disable_wifi_hotspot_when_ethernet_on},
- {
- TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
- R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on
- },
- {
- TETHERING_USB_ON | TETHERING_ETHERNET_ON,
- R.string.disable_wifi_hotspot_when_usb_and_ethernet_on
- },
- {
- TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
- R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on
- },
- {
- TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
- R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on
- }
- });
- }
-
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- @Mock
- private TetherEnabler mTetherEnabler;
-
- private SwitchPreference mPreference;
- private Context mContext;
- private WifiTetherDisablePreferenceController mController;
- private final int mTetherState;
- private final int mSummaryResId;
-
- public WifiTetherDisablePreferenceControllerTest(int tetherState, int summaryResId) {
- mTetherState = tetherState;
- mSummaryResId = summaryResId;
- }
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(ApplicationProvider.getApplicationContext());
- mPreference = spy(SwitchPreference.class);
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
- mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
- mController.setTetherEnabler(mTetherEnabler);
- ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
- ReflectionHelpers.setField(mController, "mPreference", mPreference);
- when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
- }
-
- @Test
- public void shouldShow_noTetherableWifi() {
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
- assertThat(mController.shouldShow()).isFalse();
- }
-
- @Test
- public void onTetherStateUpdated_visibilityChangeCorrectly() {
- int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
- mController.onTetherStateUpdated(state);
- assertThat(mController.shouldShow()).isTrue();
-
- state |= TetherEnabler.TETHERING_USB_ON;
- mController.onTetherStateUpdated(state);
- assertThat(mController.shouldShow()).isTrue();
-
- state = TetherEnabler.TETHERING_USB_ON;
- mController.onTetherStateUpdated(state);
- assertThat(mController.shouldShow()).isTrue();
-
- state = TetherEnabler.TETHERING_OFF;
- mController.onTetherStateUpdated(state);
- assertThat(mController.shouldShow()).isFalse();
- }
-
- @Test
- public void getSummary_onTetherStateUpdated() {
- mController.onTetherStateUpdated(mTetherState);
- assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/network/tether/TetherSettingsTest.java b/tests/robotests/src/com/android/settings/network/tether/TetherSettingsTest.java
index 9269754..4e0fb03 100644
--- a/tests/robotests/src/com/android/settings/network/tether/TetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/tether/TetherSettingsTest.java
@@ -48,7 +48,6 @@
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
-import android.util.FeatureFlagUtils;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
@@ -56,7 +55,6 @@
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -145,7 +143,6 @@
@Test
public void testTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
setupIsTetherAvailable(true);
@@ -190,7 +187,6 @@
@Test
public void testTetherNonIndexableKeys_usbAvailable_usbKeyNotReturned() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
// We can ignore the condition of Utils.isMonkeyRunning()
// In normal case, monkey and robotest should not execute at the same time
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
@@ -213,7 +209,6 @@
@Test
public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
when(mTetheringManager.getTetherableBluetoothRegexs())
.thenReturn(new String[]{"fakeRegex"});
diff --git a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
index e1687a0..090bcfb 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java
@@ -42,6 +42,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -54,6 +55,7 @@
import java.util.Objects;
+@Ignore("b/313576125")
@RunWith(RobolectricTestRunner.class)
@LooperMode(LooperMode.Mode.LEGACY)
@Config(shadows = {
diff --git a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
index 9322317..f177c19 100644
--- a/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/panel/PanelSlicesAdapterTest.java
@@ -50,6 +50,7 @@
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -125,6 +126,7 @@
/**
* ViewHolder should load and set the action label correctly.
*/
+ @Ignore("b/313576125")
@Test
public void setActionLabel_loadsActionLabel() {
addTestLiveData(VOLUME_NOTIFICATION_URI);
@@ -165,6 +167,7 @@
return foundLabel;
}
+ @Ignore("b/313576125")
@Test
public void sizeOfAdapter_shouldNotExceedMaxNum() {
for (int i = 0; i < MAX_NUM_OF_SLICES + 2; i++) {
@@ -183,6 +186,7 @@
assertThat(adapter.getData().size()).isEqualTo(MAX_NUM_OF_SLICES);
}
+ @Ignore("b/313576125")
@Test
public void mediaOutputIndicatorSlice_notSliderPanel_noSliderLayout() {
addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI);
@@ -199,6 +203,7 @@
assertThat(viewHolder.mSliceSliderLayout).isNull();
}
+ @Ignore("b/313576125")
@Test
public void onBindViewHolder_viewTypeSlider_verifyActionLabelSet() {
addTestLiveData(VOLUME_NOTIFICATION_URI);
diff --git a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
index 46c61e4..e550284 100644
--- a/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
+++ b/tests/robotests/src/com/android/settings/panel/SettingsPanelActivityTest.java
@@ -47,6 +47,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -101,6 +102,7 @@
mSettingsPanelActivity.getResources().getConfiguration().uiMode = mOriginalUiMode;
}
+ @Ignore("b/313576125")
@Test
public void onStart_isNotDebuggable_shouldHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
@@ -117,6 +119,7 @@
verify(window).addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
}
+ @Ignore("b/313576125")
@Test
public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
@@ -144,6 +147,7 @@
& SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(0);
}
+ @Ignore("b/313576125")
@Test
public void onStop_panelIsNotCreating_shouldForceUpdate() {
mSettingsPanelActivity.mForceCreation = false;
@@ -155,6 +159,7 @@
assertThat(mSettingsPanelActivity.mForceCreation).isTrue();
}
+ @Ignore("b/313576125")
@Test
public void onStop_panelIsCreating_shouldNotForceUpdate() {
mSettingsPanelActivity.mForceCreation = false;
diff --git a/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
index 7d2c6dd..cca88dd 100644
--- a/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/MemtagPreferenceControllerTest.java
@@ -43,6 +43,7 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSystemProperties;
+@Ignore("b/313564061")
@RunWith(RobolectricTestRunner.class)
@Config(
shadows = {
@@ -134,7 +135,6 @@
}
@Test
- @Ignore
public void setChecked_isChecked_doesNotShowDialog() {
ZygoteShadow.setSupportsMemoryTagging(false);
mController.setChecked(false);
@@ -142,7 +142,6 @@
}
@Test
- @Ignore
public void setChecked_isUnchecked_doesNotShowDialog() {
ZygoteShadow.setSupportsMemoryTagging(true);
mController.setChecked(true);
diff --git a/tests/robotests/src/com/android/settings/security/screenlock/PinPrivacyPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/screenlock/PinPrivacyPreferenceControllerTest.java
index 171fb44..4ee3b55 100644
--- a/tests/robotests/src/com/android/settings/security/screenlock/PinPrivacyPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/screenlock/PinPrivacyPreferenceControllerTest.java
@@ -32,6 +32,7 @@
import com.android.internal.widget.LockPatternUtils;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -66,6 +67,7 @@
assertThat(mController.isAvailable()).isTrue();
}
+ @Ignore("b/313612259")
@Test
public void isAvailable_lockSetToPinOrPw_shouldReturnTrue() {
when(mLockPatternUtils.getCredentialTypeForUser(TEST_USER_ID)).thenReturn(
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
index d7aa42c..8339798 100644
--- a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentsPreferenceControllerTest.java
@@ -40,6 +40,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -105,6 +106,7 @@
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(0);
}
+ @Ignore("b/313612480")
@Test
public void
onStart_hasAUninstalledTrustAgent_shouldRemoveOnePreferenceAndLeaveTwoPreferences() {
@@ -125,6 +127,7 @@
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(2);
}
+ @Ignore("b/313612480")
@Test
public void onStart_hasANewTrustAgent_shouldAddOnePreferenceAndHaveFourPreferences() {
final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
@@ -145,6 +148,7 @@
assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(4);
}
+ @Ignore("b/313612480")
@Test
public void onStart_hasUnrestrictedTrustAgent_shouldAddThreeChangeablePreferences() {
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(0);
@@ -165,6 +169,7 @@
}
}
+ @Ignore("b/313612480")
@Test
public void onStart_hasRestrictedTructAgent_shouldAddThreeUnchangeablePreferences() {
final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
diff --git a/tests/robotests/src/com/android/settings/theme/ContrastPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/theme/ContrastPreferenceControllerTest.java
index dbd3372..d74b6df 100644
--- a/tests/robotests/src/com/android/settings/theme/ContrastPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/theme/ContrastPreferenceControllerTest.java
@@ -38,6 +38,7 @@
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -73,6 +74,7 @@
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
+ @Ignore("b/313614100")
@Test
public void testHandlePreferenceTreeClick() {
Preference preference = new Preference(mContext);
diff --git a/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
index fe88148..7bc66c8 100644
--- a/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/TimeoutToDockUserPreferenceControllerTest.java
@@ -39,6 +39,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -125,6 +126,7 @@
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
+ @Ignore("b/313530297")
@Test
public void getAvailabilityStatus_isCurrentlyMainUser_returnDisabledForUser() {
when(mUserManager.getMainUser()).thenReturn(UserHandle.CURRENT);
@@ -134,6 +136,7 @@
BasePreferenceController.DISABLED_FOR_USER);
}
+ @Ignore("b/313530297")
@Test
public void getAvailabilityStatus_featureAndMultiUserEnabledAndNonMainUser_returnAvailable() {
when(mUserManager.isUserForeground()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/users/UserDetailsSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserDetailsSettingsTest.java
index b339052..874b978 100644
--- a/tests/robotests/src/com/android/settings/users/UserDetailsSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserDetailsSettingsTest.java
@@ -63,6 +63,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -264,6 +265,7 @@
verify(mSwitchUserPref).setEnabled(false);
}
+ @Ignore("b/313530297")
@Test
public void initialize_adminWithTelephony_shouldShowPhonePreference() {
setupSelectedUser();
@@ -309,6 +311,7 @@
verify(mFragment).removePreference(KEY_APP_AND_CONTENT_ACCESS);
}
+ @Ignore("b/313530297")
@Test
public void initialize_adminSelectsSecondaryUser_shouldShowRemovePreference() {
setupSelectedUser();
@@ -321,6 +324,7 @@
verify(mFragment, never()).removePreference(KEY_REMOVE_USER);
}
+ @Ignore("b/313530297")
@Test
public void initialize_adminSelectsNewRestrictedUser_shouldOpenAppContentScreen() {
setupSelectedRestrictedUser();
@@ -343,6 +347,7 @@
.isEqualTo(true);
}
+ @Ignore("b/313530297")
@Test
public void initialize_adminSelectsRestrictedUser_shouldSetupPreferences() {
setupSelectedRestrictedUser();
@@ -372,6 +377,7 @@
verify(mActivity, never()).startActivity(any(Intent.class));
}
+ @Ignore("b/313530297")
@Test
public void initialize_adminSelectsGuest_shouldShowRemovePreference() {
setupSelectedGuest();
@@ -415,6 +421,7 @@
verify(mFragment).removePreference(KEY_REMOVE_USER);
}
+ @Ignore("b/313530297")
@Test
public void initialize_userHasCallRestriction_shouldSetPhoneSwitchUnChecked() {
setupSelectedUser();
@@ -427,6 +434,7 @@
verify(mPhonePref).setChecked(false);
}
+ @Ignore("b/313530297")
@Test
public void initialize_noCallRestriction_shouldSetPhoneSwitchChecked() {
setupSelectedUser();
@@ -525,6 +533,7 @@
verify(mFragment, never()).switchUser();
}
+ @Ignore("b/313530297")
@Test
public void onPreferenceClick_removeGuestClicked_canDelete_shouldShowDialog() {
setupSelectedGuest();
@@ -542,6 +551,7 @@
verify(mFragment).showDialog(DIALOG_CONFIRM_RESET_GUEST);
}
+ @Ignore("b/313530297")
@Test
public void onPreferenceClick_removeRestrictedClicked_canDelete_shouldShowDialog() {
setupSelectedRestrictedUser();
@@ -560,6 +570,7 @@
verify(mFragment).showDialog(DIALOG_CONFIRM_REMOVE);
}
+ @Ignore("b/313530297")
@Test
public void onPreferenceClick_removeClicked_canDelete_shouldShowDialog() {
setupSelectedUser();
@@ -651,6 +662,7 @@
assertThat(result).isFalse();
}
+ @Ignore("b/313530297")
@Test
public void canDeleteUser_adminSelectsUser_noRestrictions_shouldReturnTrue() {
setupSelectedUser();
@@ -684,6 +696,7 @@
assertThat(result).isFalse();
}
+ @Ignore("b/313530297")
@Test
public void initialize_userSelected_shouldShowGrantAdminPref_MultipleAdminEnabled() {
setupSelectedUser();
@@ -693,6 +706,7 @@
verify(mFragment, never()).removePreference(KEY_GRANT_ADMIN);
}
+ @Ignore("b/313530297")
@Test
public void initialize_userSelected_shouldNotShowGrantAdminPref() {
setupSelectedUser();
@@ -700,6 +714,7 @@
verify(mFragment).removePreference(KEY_GRANT_ADMIN);
}
+ @Ignore("b/313530297")
@Test
public void initialize_restrictUserSelected_shouldNotShowGrantAdminPref_MultipleAdminEnabled() {
setupSelectedUser();
@@ -710,6 +725,7 @@
verify(mFragment).removePreference(KEY_GRANT_ADMIN);
}
+ @Ignore("b/313530297")
@Test
public void initialize_mainUserSelected_shouldShowGrantAdminPref_MultipleAdminEnabled() {
setupSelectedMainUser();
@@ -718,6 +734,7 @@
verify(mFragment).removePreference(KEY_GRANT_ADMIN);
}
+ @Ignore("b/313530297")
@Test
public void initialize_guestSelected_shouldNotShowGrantAdminPref_MultipleAdminEnabled() {
setupSelectedGuest();
diff --git a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
index 36eeac8..0f647aa 100644
--- a/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/users/UserSettingsTest.java
@@ -47,6 +47,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -211,7 +212,7 @@
public void testGetRawDataToIndex_returnAllIndexablePreferences() {
String[] expectedKeys = {KEY_ALLOW_MULTIPLE_USERS};
List<String> keysResultList = new ArrayList<>();
-
+ ShadowUserManager.getShadow().setSupportsMultipleUsers(true);
List<SearchIndexableRaw> rawData =
UserSettings.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, true);
@@ -719,6 +720,7 @@
doReturn(userIcon).when(mUserManager).getUserIcon(ACTIVE_USER_ID);
mFragment.updateUserList();
+ shadowOf(Looper.getMainLooper()).idle();
verify(mUserManager).getUserIcon(ACTIVE_USER_ID);
// updateUserList should be called another time after loading the icons
diff --git a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
index c693938..d35b608 100644
--- a/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
+++ b/tests/robotests/src/com/android/settings/webview/WebViewAppPickerTest.java
@@ -48,6 +48,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -207,6 +208,7 @@
verify(mActivity, times(1)).finish();
}
+ @Ignore("b/313615637")
@Test
public void testNotFinishedIfAdmin() {
mUserManager.setIsAdminUser(true);
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index 9ed6de3..c87aeea 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -45,6 +45,7 @@
import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -207,6 +208,7 @@
verify(activity, never()).startActivity(any(Intent.class));
}
+ @Ignore("b/313616350")
@Test
public void bindButton_hasAppInfo_shouldAttachClickListener() {
final View appLinks = mLayoutInflater.inflate(
diff --git a/tests/robotests/src/com/android/settings/widget/LinkifySummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/LinkifySummaryPreferenceTest.java
index e5ae840..f060588 100644
--- a/tests/robotests/src/com/android/settings/widget/LinkifySummaryPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/LinkifySummaryPreferenceTest.java
@@ -34,6 +34,7 @@
import androidx.preference.PreferenceViewHolder;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -42,6 +43,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+@Ignore("b/313563183")
@RunWith(RobolectricTestRunner.class)
public class LinkifySummaryPreferenceTest {
@Spy
diff --git a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
index 11d421c..3923cf8 100644
--- a/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2Test.java
@@ -94,6 +94,7 @@
import com.android.wifitrackerlib.WifiEntry.ConnectCallback;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -735,6 +736,7 @@
verify(mMockRxLinkSpeedPref).setSummary("100 Mbps");
}
+ @Ignore("b/313536962")
@Test
public void ssidPref_isSubscription_show() {
setUpForConnectedNetwork();
@@ -934,6 +936,7 @@
verify(mMockActivity, never()).finish();
}
+ @Ignore("b/313536962")
@Test
public void noLinkProperties_allIpDetailsHidden() {
setUpForConnectedNetwork();
@@ -956,6 +959,7 @@
verify(mMockDnsPref, never()).setVisible(true);
}
+ @Ignore("b/313536962")
@Test
public void disconnectedNetwork_allIpDetailsHidden() {
setUpForDisconnectedNetwork();
@@ -1005,6 +1009,7 @@
inOrder.verify(mMockIpv6AddressesPref).setSummary(text);
}
+ @Ignore("b/313536962")
@Test
public void onLinkPropertiesChanged_updatesFields() {
setUpForConnectedNetwork();
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
deleted file mode 100644
index d777a59..0000000
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherApBandPreferenceControllerTest.java
+++ /dev/null
@@ -1,171 +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.wifi.tether;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.net.TetheringManager;
-import android.net.wifi.SoftApConfiguration;
-import android.net.wifi.WifiManager;
-
-import androidx.preference.ListPreference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-
-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;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(RobolectricTestRunner.class)
-public class WifiTetherApBandPreferenceControllerTest {
-
- private static final String ALL_BANDS = "5.0 GHz Band preferred";
- private static final String TWO_GHZ_STRING = "2.4 GHz Band";
- private static final String FIVE_GHZ_STRING = "5.0 GHz Band";
- private static final String VAL_2GHZ_STR = "1";
- private static final String VAL_5GHZ_STR = "2";
- private static final String VAL_2_5_GHZ_STR = "3";
- private static final int VAL_2GHZ_INT = 1;
- private static final int VAL_5GHZ_INT = 2;
- private static final int VAL_2_5_GHZ_INT = 3;
-
- private Context mContext;
- @Mock
- private TetheringManager mTetheringManager;
- @Mock
- private WifiManager mWifiManager;
- @Mock
- private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
- @Mock
- private PreferenceScreen mScreen;
-
- private WifiTetherApBandPreferenceController mController;
- private ListPreference mPreference;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- mPreference = new ListPreference(RuntimeEnvironment.application);
- when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
- when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
- when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
- when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
- when(mScreen.findPreference(anyString())).thenReturn(mPreference);
- when(mWifiManager.getSoftApConfiguration()).thenReturn(
- new SoftApConfiguration.Builder().build());
-
- mController = new WifiTetherApBandPreferenceController(mContext, mListener);
- }
-
- @Test
- public void display_5GhzSupported_shouldDisplayFullList() {
- when(mWifiManager.getCountryCode()).thenReturn("US");
- when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
-
- // Create a new instance
- mController = new WifiTetherApBandPreferenceController(mContext, mListener);
-
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, VAL_2_5_GHZ_STR);
-
- assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
- }
-
- @Test
- public void display_noCountryCode_shouldDisable() {
- when(mWifiManager.getCountryCode()).thenReturn(null);
- when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
-
- mController.displayPreference(mScreen);
-
- assertThat(mPreference.isEnabled()).isFalse();
- assertThat(mPreference.getSummary())
- .isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
- }
-
- @Test
- public void display_5GhzNotSupported_shouldDisable() {
- when(mWifiManager.getCountryCode()).thenReturn("US");
- when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
-
- mController.displayPreference(mScreen);
-
- assertThat(mPreference.isEnabled()).isFalse();
- assertThat(mPreference.getSummary())
- .isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
- }
-
- @Test
- public void changePreference_With5G_shouldUpdateValue() {
- when(mWifiManager.getCountryCode()).thenReturn("US");
- when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
-
- // Create a new instance to pick the proper value of isDualModeSupported()
- mController = new WifiTetherApBandPreferenceController(mContext, mListener);
-
- mController.displayPreference(mScreen);
-
- // 'Auto' option
- mController.onPreferenceChange(mPreference, VAL_2_5_GHZ_STR);
- assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
- assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
- verify(mListener, times(1)).onTetherConfigUpdated(mController);
-
- // should revert to the default for 5 Ghz only since this is not supported with this config
- mController.onPreferenceChange(mPreference, VAL_5GHZ_STR);
- assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
- assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
- verify(mListener, times(2)).onTetherConfigUpdated(mController);
-
- // set to 2 Ghz
- mController.onPreferenceChange(mPreference, VAL_2GHZ_STR);
- assertThat(mController.getBandIndex()).isEqualTo(VAL_2GHZ_INT);
- assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
- verify(mListener, times(3)).onTetherConfigUpdated(mController);
- }
-
- @Test
- public void updateDisplay_shouldUpdateValue() {
- when(mWifiManager.getCountryCode()).thenReturn("US");
- when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
-
- // Set controller band index to 5GHz and verify is set.
- mController.displayPreference(mScreen);
- mController.onPreferenceChange(mPreference, VAL_5GHZ_STR);
- assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
-
- // Disable 5Ghz band
- when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
-
- // Call updateDisplay and verify it's changed.
- mController.updateDisplay();
- assertThat(mController.getBandIndex()).isEqualTo(VAL_2GHZ_INT);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index 84a7b36..28fb8b3 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -49,7 +49,6 @@
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserManager;
-import android.util.FeatureFlagUtils;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
@@ -60,7 +59,6 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
@@ -144,7 +142,6 @@
@Before
public void setUp() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
setCanShowWifiHotspotCached(true);
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mConnectivityManager)
diff --git a/tests/spa_unit/src/com/android/settings/network/TetherPreferenceControllerTest.kt b/tests/spa_unit/src/com/android/settings/network/TetherPreferenceControllerTest.kt
new file mode 100644
index 0000000..51d2c87
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/TetherPreferenceControllerTest.kt
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2023 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.Context
+import android.net.TetheringManager
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.dx.mockito.inline.extended.ExtendedMockito
+import com.android.settings.R
+import com.android.settings.core.BasePreferenceController
+import com.android.settingslib.TetherUtil
+import com.google.common.truth.Truth.assertThat
+import org.junit.After
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.MockitoSession
+import org.mockito.quality.Strictness
+
+@RunWith(AndroidJUnit4::class)
+class TetherPreferenceControllerTest {
+ private lateinit var mockSession: MockitoSession
+
+ private val context: Context = ApplicationProvider.getApplicationContext()
+
+ private val controller = TetherPreferenceController(context, TEST_KEY)
+
+ @Before
+ fun setUp() {
+ mockSession = ExtendedMockito.mockitoSession()
+ .initMocks(this)
+ .mockStatic(TetherUtil::class.java)
+ .strictness(Strictness.LENIENT)
+ .startMocking()
+
+ ExtendedMockito.doReturn(true).`when` { TetherUtil.isTetherAvailable(context) }
+ }
+
+ @After
+ fun tearDown() {
+ mockSession.finishMocking()
+ }
+
+ @Test
+ fun getAvailabilityStatus_whenTetherAvailable() {
+ ExtendedMockito.doReturn(true).`when` { TetherUtil.isTetherAvailable(context) }
+
+ val availabilityStatus = controller.availabilityStatus
+
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.AVAILABLE)
+ }
+
+ @Test
+ fun getAvailabilityStatus_whenTetherNotAvailable() {
+ ExtendedMockito.doReturn(false).`when` { TetherUtil.isTetherAvailable(context) }
+
+ val availabilityStatus = controller.availabilityStatus
+
+ assertThat(availabilityStatus).isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE)
+ }
+
+ @Test
+ fun getSummaryResId_bothWifiAndBluetoothOn() {
+ val summaryResId = controller.getSummaryResId(
+ setOf(TetheringManager.TETHERING_WIFI, TetheringManager.TETHERING_BLUETOOTH)
+ )
+
+ assertThat(summaryResId).isEqualTo(R.string.tether_settings_summary_hotspot_on_tether_on)
+ }
+
+ @Test
+ fun getSummaryResId_onlyWifiHotspotOn() {
+ val summaryResId = controller.getSummaryResId(setOf(TetheringManager.TETHERING_WIFI))
+
+ assertThat(summaryResId).isEqualTo(R.string.tether_settings_summary_hotspot_on_tether_off)
+ }
+
+ @Test
+ fun getSummaryResId_onlyBluetoothTetheringOn() {
+ val summaryResId = controller.getSummaryResId(setOf(TetheringManager.TETHERING_BLUETOOTH))
+
+ assertThat(summaryResId).isEqualTo(R.string.tether_settings_summary_hotspot_off_tether_on)
+ }
+
+ @Test
+ fun getSummaryResId_allOff() {
+ val summaryResId = controller.getSummaryResId(emptySet())
+
+ assertThat(summaryResId).isEqualTo(R.string.tether_preference_summary_off)
+ }
+
+ private companion object {
+ const val TEST_KEY = "test_key"
+ }
+}
diff --git a/tests/spa_unit/src/com/android/settings/network/TetheredRepositoryTest.kt b/tests/spa_unit/src/com/android/settings/network/TetheredRepositoryTest.kt
new file mode 100644
index 0000000..5bd5210
--- /dev/null
+++ b/tests/spa_unit/src/com/android/settings/network/TetheredRepositoryTest.kt
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2023 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.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothManager
+import android.bluetooth.BluetoothPan
+import android.bluetooth.BluetoothProfile
+import android.content.Context
+import android.net.TetheringInterface
+import android.net.TetheringManager
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.async
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.mapNotNull
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.doAnswer
+import org.mockito.kotlin.doReturn
+import org.mockito.kotlin.eq
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.stub
+
+@RunWith(AndroidJUnit4::class)
+class TetheredRepositoryTest {
+
+ private var tetheringInterfaces: Set<TetheringInterface> = emptySet()
+
+ private var tetheringEventCallback: TetheringManager.TetheringEventCallback? = null
+
+ private val mockTetheringManager = mock<TetheringManager> {
+ on { registerTetheringEventCallback(any(), any()) } doAnswer {
+ tetheringEventCallback = it.arguments[1] as TetheringManager.TetheringEventCallback
+ tetheringEventCallback?.onTetheredInterfacesChanged(tetheringInterfaces)
+ }
+ }
+
+ private val mockBluetoothPan = mock<BluetoothPan> {
+ on { isTetheringOn } doReturn false
+ }
+
+ private val mockBluetoothAdapter = mock<BluetoothAdapter> {
+ on { getProfileProxy(any(), any(), eq(BluetoothProfile.PAN)) } doAnswer {
+ val listener = it.arguments[1] as BluetoothProfile.ServiceListener
+ listener.onServiceConnected(BluetoothProfile.PAN, mockBluetoothPan)
+ true
+ }
+ }
+
+ private val mockBluetoothManager = mock<BluetoothManager> {
+ on { adapter } doReturn mockBluetoothAdapter
+ }
+
+ private val context = mock<Context> {
+ on { getSystemService(TetheringManager::class.java) } doReturn mockTetheringManager
+ on { getSystemService(BluetoothManager::class.java) } doReturn mockBluetoothManager
+ }
+
+ private val repository = TetheredRepository(context)
+
+ @Test
+ fun tetheredTypesFlow_allOff() = runBlocking {
+ val tetheredTypes = repository.tetheredTypesFlow().firstWithTimeoutOrNull()
+
+ assertThat(tetheredTypes).isEmpty()
+ }
+
+ @Test
+ fun tetheredTypesFlow_wifiHotspotOn(): Unit = runBlocking {
+ tetheringInterfaces = setOf(TetheringInterface(TetheringManager.TETHERING_WIFI, ""))
+
+ val tetheredTypes = repository.tetheredTypesFlow().firstWithTimeoutOrNull()
+
+ assertThat(tetheredTypes).containsExactly(TetheringManager.TETHERING_WIFI)
+ }
+
+ @Test
+ fun tetheredTypesFlow_usbTetheringTurnOnLater(): Unit = runBlocking {
+ val tetheredTypeDeferred = async {
+ repository.tetheredTypesFlow().mapNotNull {
+ it.singleOrNull()
+ }.firstWithTimeoutOrNull()
+ }
+ delay(100)
+
+ tetheringEventCallback?.onTetheredInterfacesChanged(
+ setOf(TetheringInterface(TetheringManager.TETHERING_USB, ""))
+ )
+
+ assertThat(tetheredTypeDeferred.await()).isEqualTo(TetheringManager.TETHERING_USB)
+ }
+
+ @Test
+ fun tetheredTypesFlow_bluetoothOff(): Unit = runBlocking {
+ mockBluetoothAdapter.stub {
+ on { state } doReturn BluetoothAdapter.STATE_OFF
+ }
+
+ val tetheredTypes = repository.tetheredTypesFlow().firstWithTimeoutOrNull()
+
+ assertThat(tetheredTypes).isEmpty()
+ }
+
+ @Test
+ fun tetheredTypesFlow_bluetoothOnTetheringOff(): Unit = runBlocking {
+ mockBluetoothAdapter.stub {
+ on { state } doReturn BluetoothAdapter.STATE_ON
+ }
+
+ val tetheredTypes = repository.tetheredTypesFlow().firstWithTimeoutOrNull()
+
+ assertThat(tetheredTypes).isEmpty()
+ }
+
+ @Test
+ fun tetheredTypesFlow_bluetoothTetheringOn(): Unit = runBlocking {
+ mockBluetoothAdapter.stub {
+ on { state } doReturn BluetoothAdapter.STATE_ON
+ }
+ mockBluetoothPan.stub {
+ on { isTetheringOn } doReturn true
+ }
+
+ val tetheredTypes = repository.tetheredTypesFlow().firstWithTimeoutOrNull()
+
+ assertThat(tetheredTypes).containsExactly(TetheringManager.TETHERING_BLUETOOTH)
+ }
+}
diff --git a/tests/unit/src/com/android/settings/network/InternetPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/InternetPreferenceControllerTest.java
index 5af2da0..4ba12cb 100644
--- a/tests/unit/src/com/android/settings/network/InternetPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/InternetPreferenceControllerTest.java
@@ -298,4 +298,11 @@
assertThat(mPreference.getSummary().toString()).isEqualTo(TEST_SUMMARY);
}
+
+ @Test
+ public void updateHotspotNetwork_hotspotNetworkNotEnabled_returnFalse() {
+ mController.mWifiPickerTrackerHelper = null;
+
+ assertThat(mController.updateHotspotNetwork()).isFalse();
+ }
}