Merge "Fix issues with SUW on fingerprint devices"
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index a258cc6..75f46e5 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -1417,6 +1417,262 @@
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_red">#d93025</color> <!-- Material Red 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="154"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_orange">#e8710a</color> <!-- Material Orange 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="155"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_yellow">#f9ab00</color> <!-- Material Yellow 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="156"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_green">#1e8e3e</color> <!-- Material Green 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="157"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_cyan">#12b5cb</color> <!-- Material Cyan 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="158"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_blue">#1a73e8</color> <!-- Material Blue 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="159"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_purple">#9334e6</color> <!-- Material Purple 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="160"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_color_pink">#e52592</color> <!-- Material Pink 600 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="161"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_red">#f28b82</color> <!-- Material Red 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="164"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_orange">#fcad70</color> <!-- Material Orange 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="165"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_yellow">#fdd663</color> <!-- Material Yellow 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="166"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_green">#81c995</color> <!-- Material Green 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="167"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_cyan">#78d9ec</color> <!-- Material Cyan 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="168"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_blue">#8AB4F8</color> <!-- Material Blue 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="169"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_purple">#c58af9</color> <!-- Material Purple 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="170"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" <color name="palette_list_dark_mode_color_pink">#ff8bcb</color> <!-- Material Pink 300 -->"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/values/colors.xml"
+ line="171"
+ column="5"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" android:background="@color/lock_pattern_background" />"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
@@ -2621,7 +2877,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rAU/strings.xml"
- line="2663"
+ line="2689"
column="64"/>
</issue>
@@ -2637,7 +2893,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rCA/strings.xml"
- line="2663"
+ line="2689"
column="64"/>
</issue>
@@ -2653,7 +2909,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rGB/strings.xml"
- line="2663"
+ line="2689"
column="64"/>
</issue>
@@ -2669,7 +2925,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rIN/strings.xml"
- line="2663"
+ line="2689"
column="64"/>
</issue>
@@ -2685,7 +2941,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values-en-rXC/strings.xml"
- line="2663"
+ line="2689"
column="170"/>
</issue>
@@ -2701,7 +2957,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="res/values/strings.xml"
- line="6183"
+ line="6228"
column="36"/>
</issue>
diff --git a/res/drawable/signal_strength_5g.xml b/res/drawable/signal_strength_5g.xml
index fdaea7e..dc89f9a 100644
--- a/res/drawable/signal_strength_5g.xml
+++ b/res/drawable/signal_strength_5g.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (C) 2018 The Android Open Source Project
+ Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index aca64fb..b8afd60 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -398,7 +398,8 @@
<dimen name="two_target_min_width">80dp</dimen>
<!-- Maximum height for SliceView, override on slices/view/src/main/res/values/dimens.xml -->
- <dimen name="abc_slice_large_height">480dp</dimen>
+ <!-- A single Row Slice height is 60dp -->
+ <dimen name="abc_slice_large_height">1200dp</dimen>
<!-- System navigation settings illustration height -->
<dimen name="system_navigation_illustration_height">320dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 968f650..d15bb93 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2824,7 +2824,7 @@
<!-- Display settings screen, summary of Dark UI when on and will turn off automatically at sunrise. [CHAR LIMIT=NONE] -->
<string name="dark_ui_summary_on_auto_mode_auto">Will turn off automatically at sunrise</string>
<!-- Dark theme screen, description of Dark theme feature. [CHAR LIMIT=NONE] -->
- <string name="dark_ui_text">Dark theme uses true black to help keep your battery alive longer. Dark theme schedules wait to turn on until your screen is off.</string>
+ <string name="dark_ui_text">Dark theme uses a black background to help keep battery alive longer on some screens. Dark theme schedules wait to turn on until your screen is off.</string>
<!-- Sound & display settings screen, setting option name to change screen timeout -->
<string name="screen_timeout">Screen timeout</string>
@@ -4771,7 +4771,7 @@
<!-- Title for the accessibility preference screen to enable video captioning. [CHAR LIMIT=35] -->
<string name="accessibility_captioning_title">Caption preferences</string>
<!-- Title for the accessibility preference screen to enable screen magnification. [CHAR LIMIT=35] -->
- <string name="accessibility_screen_magnification_title">Magnification</string>
+ <string name="accessibility_screen_magnification_title">Magnify</string>
<!-- Title for the accessibility preference screen to edit magnification area. [CHAR LIMIT=35] -->
<string name="accessibility_magnification_mode_title">Magnification area</string>
<!-- Message for the accessibility preference screen to edit magnification area dialog. [CHAR LIMIT=none] -->
@@ -4791,13 +4791,17 @@
<!-- Summary for the accessibility preference screen to show move controller. [CHAR LIMIT=none] -->
<string name="accessibility_magnification_window_control_switch_summary">Show a joystick-like controller to move the magnification area</string>
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
- <string name="accessibility_magnification_service_settings_title">Magnify settings</string>
+ <string name="accessibility_magnification_service_settings_title">Magnification settings</string>
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_gestures_title">Magnify with triple-tap</string>
<!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_navbar_title">Magnify with shortcut</string>
<!-- Summary for the accessibility magnification setting indicating both "Magnify with button" and "Magnify with triple-tap" are enabled [CHAR LIMIT=50] -->
<string name="accessibility_screen_magnification_state_navbar_gesture">Magnify with shortcut & triple-tap</string>
+ <!-- Title for the footer text to explain what Magnify does. [CHAR LIMIT=35] -->
+ <string name="accessibility_screen_magnification_about">About Magnify</string>
+ <!-- Title for the footer text to explain what option accessibility service does. [CHAR LIMIT=35] -->
+ <string name="accessibility_screen_option">Options</string>
<!-- Summary for the accessibility preference to enable screen magnification. [CHAR LIMIT=25] -->
<string name="accessibility_preference_magnification_summary">Zoom in on screen</string>
<!-- Short summary for Magnification gesture. Tells the user that this feature allows the user to magnify the screen by tapping 3 times. Appears in accessibility portion of setup wizard -->
@@ -6964,6 +6968,8 @@
<string name="help_uri_apps_photography" translatable="false"></string>
<!-- Help URI, manage apps wifi access [DO NOT TRANSLATE] -->
<string name="help_uri_apps_wifi_access" translatable="false"></string>
+ <!-- Help URI, manage apps that have access to all files [DO NOT TRANSLATE] -->
+ <string name="help_uri_manage_external_storage" translatable="false"></string>
<!-- Help URI, Storage [DO NOT TRANSLATE] -->
<string name="help_uri_storage" translatable="false"></string>
<!-- Help URI, Accessibility [DO NOT TRANSLATE] -->
@@ -9441,6 +9447,16 @@
<!-- Description of allowing overlay setting [CHAR LIMIT=NONE] -->
<string name="allow_overlay_description">Allow this app to display on top of other apps you\u2019re using. It may interfere with your use of those apps or change the way they seem to appear or behave.</string>
+ <!-- Manager External Storage settings title [CHAR LIMIT=30] -->
+ <string name="manage_external_storage_title">All files access</string>
+ <!-- Label for a setting which controls whether an app can manage external storage [CHAR LIMIT=45] -->
+ <string name="permit_manage_external_storage">Allow access to manage all files</string>
+ <!-- Description for a setting which controls whether an app can manage external storage
+ [CHAR LIMIT=NONE] -->
+ <string name="allow_manage_external_storage_description">Allow this app to read, modify and delete all files on this device or any connected storage volumes. If granted, app may access files without your explicit knowledge.</string>
+ <!-- Label for showing apps that can manage external storage[CHAR LIMIT=45] -->
+ <string name="filter_manage_external_storage">Can access all files</string>
+
<!-- Keyword for VR setting -->
<string name="keywords_vr_listener">vr virtual reality listener stereo helper service</string>
<!-- Main settings screen item's title to go into the overlay settings screen [CHAR LIMIT=30] -->
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index 738bb8e..1b9939a 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -15,47 +15,45 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- android:title="@string/vision_settings_title"
- android:persistent="true" >
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:persistent="true"
+ android:title="@string/vision_settings_title">
<com.android.settings.accessibility.DividerAllowedBelowPreference
android:key="vision_settings_summary"
- android:title="@string/vision_settings_description"
android:layout="@layout/preference_multiline_title"
- android:selectable="false" />
+ android:selectable="false"
+ android:title="@string/vision_settings_description" />
<Preference
- android:fragment=
- "com.android.settings.accessibility.MagnificationPreferenceFragment"
+ settings:controller="com.android.settings.accessibility.MagnificationPreferenceController"
+ android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
android:key="screen_magnification_preference"
- android:title="@string/accessibility_screen_magnification_title"
- android:summary="@string/accessibility_preference_magnification_summary" />
+ android:summary="@string/accessibility_preference_magnification_summary"
+ android:title="@string/accessibility_screen_magnification_title" />
<Preference
- android:fragment=
- "com.android.settings.display.FontSizePreferenceFragmentForSetupWizard"
+ android:fragment="com.android.settings.display.FontSizePreferenceFragmentForSetupWizard"
android:key="font_size_preference"
- android:title="@string/title_font_size"
- android:summary="@string/short_summary_font_size" />
+ android:summary="@string/short_summary_font_size"
+ android:title="@string/title_font_size" />
<com.android.settings.display.ScreenZoomPreference
android:fragment="com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard"
android:key="force_density_preference"
- android:title="@string/screen_zoom_title"
- android:summary="@string/screen_zoom_short_summary" />
+ android:summary="@string/screen_zoom_short_summary"
+ android:title="@string/screen_zoom_title" />
<Preference
- android:fragment=
- "com.android.settings.accessibility.ToggleSelectToSpeakPreferenceFragmentForSetupWizard"
+ android:fragment="com.android.settings.accessibility.ToggleSelectToSpeakPreferenceFragmentForSetupWizard"
android:key="select_to_speak_preference"
- android:summary="@string/select_to_speak_summary"
- android:persistent="true" />
+ android:persistent="true"
+ android:summary="@string/select_to_speak_summary" />
<Preference
- android:fragment=
- "com.android.settings.accessibility.ToggleScreenReaderPreferenceFragmentForSetupWizard"
+ android:fragment="com.android.settings.accessibility.ToggleScreenReaderPreferenceFragmentForSetupWizard"
android:key="screen_reader_preference"
- android:summary="@string/talkback_summary"
- android:persistent="true" />
+ android:persistent="true"
+ android:summary="@string/talkback_summary" />
</PreferenceScreen>
diff --git a/res/xml/accounts_dashboard_settings.xml b/res/xml/accounts_dashboard_settings.xml
index 6b5f825..d2affc7 100644
--- a/res/xml/accounts_dashboard_settings.xml
+++ b/res/xml/accounts_dashboard_settings.xml
@@ -36,6 +36,7 @@
android:key="auto_sync_work_account_data"
android:title="@string/account_settings_menu_auto_sync_work"
android:summary="@string/auto_sync_account_summary"
+ settings:forWork="true"
android:order="103"/>
<SwitchPreference
diff --git a/res/xml/manage_external_storage_permission_details.xml b/res/xml/manage_external_storage_permission_details.xml
new file mode 100644
index 0000000..b540ff6
--- /dev/null
+++ b/res/xml/manage_external_storage_permission_details.xml
@@ -0,0 +1,29 @@
+<?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"
+ android:key="manage_external_storage_permission_details"
+ android:title="@string/manage_external_storage_title">
+
+ <SwitchPreference
+ android:key="app_ops_settings_switch"
+ android:title="@string/permit_manage_external_storage"/>
+
+ <Preference
+ android:summary="@string/allow_manage_external_storage_description"
+ android:selectable="false"/>
+
+</PreferenceScreen>
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
index 25422bf..e511d17 100644
--- a/res/xml/special_access.xml
+++ b/res/xml/special_access.xml
@@ -21,6 +21,15 @@
android:title="@string/special_access">
<Preference
+ android:key="manage_external_storage"
+ android:title="@string/manage_external_storage_title"
+ android:fragment="com.android.settings.applications.manageapplications.ManageApplications">
+ <extra
+ android:name="classname"
+ android:value="com.android.settings.Settings$ManageExternalStorageActivity" />
+ </Preference>
+
+ <Preference
android:key="high_power_apps"
android:title="@string/high_power_apps"
android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java
index 5ac2c0b..e2adcc7 100644
--- a/src/com/android/settings/ResetNetwork.java
+++ b/src/com/android/settings/ResetNetwork.java
@@ -170,13 +170,13 @@
if (mSubscriptions != null && mSubscriptions.size() > 0) {
// Get the default subscription in the order of data, voice, sms, first up.
int defaultSubscription = SubscriptionManager.getDefaultDataSubscriptionId();
- if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
+ if (!SubscriptionManager.isUsableSubscriptionId(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultVoiceSubscriptionId();
}
- if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
+ if (!SubscriptionManager.isUsableSubscriptionId(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultSmsSubscriptionId();
}
- if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
+ if (!SubscriptionManager.isUsableSubscriptionId(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultSubscriptionId();
}
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index ee11ce0..f4b20eb 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -47,12 +47,10 @@
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
-import com.android.ims.ImsManager;
import com.android.internal.telephony.PhoneConstants;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.network.ApnSettings;
-import com.android.settings.network.SubscriptionUtil;
import com.android.settingslib.RestrictedLockUtilsInternal;
/**
@@ -127,8 +125,6 @@
}
}
- ImsManager.getInstance(mContext,
- SubscriptionUtil.getPhoneId(mContext, mSubId)).factoryReset();
restoreDefaultApn(mContext);
if (mEraseEsim) {
return RecoverySystem.wipeEuiccData(mContext, mPackageName);
@@ -203,7 +199,7 @@
private void restoreDefaultApn(Context context) {
Uri uri = Uri.parse(ApnSettings.RESTORE_CARRIERS_URI);
- if (SubscriptionManager.isUsableSubIdValue(mSubId)) {
+ if (SubscriptionManager.isUsableSubscriptionId(mSubId)) {
uri = Uri.withAppendedPath(uri, "subId/" + String.valueOf(mSubId));
}
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 50caf32..d5c0871 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -138,6 +138,7 @@
public static class MemorySettingsActivity extends SettingsActivity { /* empty */ }
public static class AppMemoryUsageActivity extends SettingsActivity { /* empty */ }
public static class OverlaySettingsActivity extends SettingsActivity { /* empty */ }
+ public static class ManageExternalStorageActivity extends SettingsActivity { /* empty */ }
public static class WriteSettingsActivity extends SettingsActivity { /* empty */ }
public static class ChangeWifiStateActivity extends SettingsActivity { /* empty */ }
public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 2f198cf..9b257b6 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -372,7 +372,7 @@
}
public static boolean hasMultipleUsers(Context context) {
- return ((UserManager) context.getSystemService(Context.USER_SERVICE))
+ return context.getSystemService(UserManager.class)
.getUsers().size() > 1;
}
@@ -666,7 +666,7 @@
* @throws SecurityException if the given userId does not belong to the current user group.
*/
public static int enforceSameOwner(Context context, int userId) {
- final UserManager um = UserManager.get(context);
+ final UserManager um = context.getSystemService(UserManager.class);
final int[] profileIds = um.getProfileIdsWithDisabled(UserHandle.myUserId());
if (ArrayUtils.contains(profileIds, userId)) {
return userId;
@@ -686,7 +686,7 @@
* Returns the user id of the credential owner of the given user id.
*/
public static int getCredentialOwnerUserId(Context context, int userId) {
- final UserManager um = UserManager.get(context);
+ final UserManager um = context.getSystemService(UserManager.class);
return um.getCredentialOwnerProfile(userId);
}
@@ -823,7 +823,8 @@
}
public static boolean isDemoUser(Context context) {
- return UserManager.isDeviceInDemoMode(context) && UserManager.get(context).isDemoUser();
+ return UserManager.isDeviceInDemoMode(context)
+ && context.getSystemService(UserManager.class).isDemoUser();
}
public static ComponentName getDeviceOwnerComponent(Context context) {
@@ -1051,7 +1052,7 @@
final boolean isWork = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
== ProfileSelectFragment.ProfileType.WORK : false;
if (FeatureFlagUtils.isEnabled(activity, FeatureFlags.PERSONAL_WORK_PROFILE)
- && UserManager.get(activity).getUserProfiles().size() > 1
+ && activity.getSystemService(UserManager.class).getUserProfiles().size() > 1
&& ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName) != null
&& !isWork && !isPersonal) {
f = Fragment.instantiate(activity, ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName),
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
index 64ed486..159e609 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
@@ -49,7 +49,6 @@
"screen_magnification_preference";
private static final String SCREEN_READER_PREFERENCE = "screen_reader_preference";
private static final String SELECT_TO_SPEAK_PREFERENCE = "select_to_speak_preference";
- private static final String FONT_SIZE_PREFERENCE = "font_size_preference";
// Package names and service names used to identify screen reader and SelectToSpeak services.
private static final String SCREEN_READER_PACKAGE_NAME = "com.google.android.marvin.talkback";
@@ -175,16 +174,11 @@
}
private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
- // Some devices support only a single magnification mode. In these cases, we redirect to
- // the magnification mode's UI directly, rather than showing a PreferenceScreen with a
- // single list item.
final Context context = preference.getContext();
- if (!MagnificationPreferenceFragment.isApplicable(context.getResources())) {
- preference.setFragment(
- ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
- final Bundle extras = preference.getExtras();
- MagnificationGesturesPreferenceController
- .populateMagnificationGesturesPreferenceExtras(extras, context);
- }
+ preference.setFragment(
+ ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
+ final Bundle extras = preference.getExtras();
+ MagnificationGesturesPreferenceController
+ .populateMagnificationGesturesPreferenceExtras(extras, context);
}
}
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceController.java b/src/com/android/settings/accessibility/MagnificationPreferenceController.java
index 58eb227..8b214a2 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceController.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceController.java
@@ -67,14 +67,9 @@
}
private void configureMagnificationPreferenceIfNeeded() {
- // Some devices support only a single magnification mode. In these cases, we redirect to
- // the magnification mode's UI directly, rather than showing a PreferenceScreen with a
- // single list item.
- if (!MagnificationPreferenceFragment.isApplicable(mContext.getResources())) {
- mPreference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
- final Bundle extras = mPreference.getExtras();
- MagnificationGesturesPreferenceController
- .populateMagnificationGesturesPreferenceExtras(extras, mContext);
- }
+ mPreference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
+ final Bundle extras = mPreference.getExtras();
+ MagnificationGesturesPreferenceController
+ .populateMagnificationGesturesPreferenceExtras(extras, mContext);
}
}
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 8693690..bfc2360 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -38,17 +38,16 @@
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;
-import android.widget.Switch;
import android.widget.VideoView;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutType;
-import com.android.settings.widget.SwitchBar;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -57,8 +56,7 @@
import java.util.StringJoiner;
public class ToggleScreenMagnificationPreferenceFragment extends
- ToggleFeaturePreferenceFragment implements SwitchBar.OnSwitchChangeListener,
- ShortcutPreference.OnClickListener {
+ ToggleFeaturePreferenceFragment implements ShortcutPreference.OnClickListener {
private static final String SETTINGS_KEY = "screen_magnification_settings";
private static final String EXTRA_SHORTCUT_TYPE = "shortcutType";
@@ -78,6 +76,8 @@
private static final TextUtils.SimpleStringSplitter sStringColonSplitter =
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
+ protected Preference mConfigWarningPreference;
+ protected VideoPreference mVideoPreference;
protected class VideoPreference extends Preference {
private ImageView mVideoBackgroundView;
private OnGlobalLayoutListener mLayoutListener;
@@ -154,25 +154,35 @@
}
}
- protected VideoPreference mVideoPreference;
- protected Preference mConfigWarningPreference;
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ getActivity().setTitle(R.string.accessibility_screen_magnification_title);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
mVideoPreference = new VideoPreference(getPrefContext());
mVideoPreference.setSelectable(false);
mVideoPreference.setPersistent(false);
mVideoPreference.setLayoutResource(R.layout.magnification_video_preference);
+ final PreferenceCategory optionCategory = new PreferenceCategory(getPrefContext());
+ optionCategory.setTitle(R.string.accessibility_screen_option);
+
+ initShortcutPreference(savedInstanceState);
+
final Preference settingsPreference = new Preference(getPrefContext());
- final String SettingsText = getString(R.string.settings_button);
- settingsPreference.setTitle(SettingsText);
+ settingsPreference.setTitle(R.string.accessibility_magnification_service_settings_title);
settingsPreference.setKey(SETTINGS_KEY);
settingsPreference.setFragment(MagnificationSettingsFragment.class.getName());
settingsPreference.setPersistent(false);
+ final PreferenceCategory aboutCategory = new PreferenceCategory(getPrefContext());
+ aboutCategory.setTitle(R.string.accessibility_screen_magnification_about);
+
mConfigWarningPreference = new Preference(getPrefContext());
mConfigWarningPreference.setSelectable(false);
mConfigWarningPreference.setPersistent(false);
@@ -182,17 +192,15 @@
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false);
mVideoPreference.setOrder(0);
- settingsPreference.setOrder(1);
- mConfigWarningPreference.setOrder(2);
+ optionCategory.setOrder(1);
+ aboutCategory.setOrder(2);
preferenceScreen.addPreference(mVideoPreference);
- preferenceScreen.addPreference(settingsPreference);
- preferenceScreen.addPreference(mConfigWarningPreference);
- }
+ preferenceScreen.addPreference(optionCategory);
+ optionCategory.addPreference(mShortcutPreference);
+ optionCategory.addPreference(settingsPreference);
+ preferenceScreen.addPreference(aboutCategory);
+ aboutCategory.addPreference(mConfigWarningPreference);
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- initShortcutPreference(savedInstanceState);
return super.onCreateView(inflater, container, savedInstanceState);
}
@@ -378,11 +386,6 @@
}
@Override
- public void onSwitchChanged(Switch switchView, boolean isChecked) {
- onPreferenceToggled(mPreferenceKey, isChecked);
- }
-
- @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
if (enabled && TextUtils.equals(
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
@@ -399,22 +402,8 @@
protected void onInstallSwitchBarToggleSwitch() {
super.onInstallSwitchBarToggleSwitch();
- mSwitchBar.setCheckedInternal(
- MagnificationPreferenceFragment.isChecked(getContentResolver(), mPreferenceKey));
- mSwitchBar.addOnSwitchChangeListener(this);
- }
-
- @Override
- protected void onRemoveSwitchBarToggleSwitch() {
- super.onRemoveSwitchBarToggleSwitch();
- mSwitchBar.removeOnSwitchChangeListener(this);
- }
-
- @Override
- protected void updateSwitchBarText(SwitchBar switchBar) {
- final String switchBarText = getString(R.string.accessibility_service_master_switch_title,
- getString(R.string.accessibility_screen_magnification_title));
- switchBar.setSwitchBarText(switchBarText, switchBarText);
+ // Magnify is temporary-use app which uses shortcut to magnify screen, not by toggle.
+ mSwitchBar.hide();
}
@Override
@@ -429,13 +418,6 @@
} else {
mVideoPreference.setVisible(false);
}
-
- if (arguments.containsKey(AccessibilitySettings.EXTRA_TITLE_RES)) {
- final int titleRes = arguments.getInt(AccessibilitySettings.EXTRA_TITLE_RES);
- if (titleRes > 0) {
- getActivity().setTitle(titleRes);
- }
- }
}
@Override
@@ -443,15 +425,35 @@
if (preference.getChecked()) {
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
// preferred key.
+ optInMagnificationValueToSettings(getContext(), PreferredShortcutType.SOFTWARE);
+
// TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
// as special case in this file.
- optInMagnificationValueToSettings(getContext(), PreferredShortcutType.SOFTWARE);
+ if ((mPreferredShortcutType & PreferredShortcutType.SOFTWARE)
+ == PreferredShortcutType.SOFTWARE) {
+ MagnificationPreferenceFragment.setChecked(getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
+ /* isChecked= */ true);
+ }
+ if ((mPreferredShortcutType & PreferredShortcutType.TRIPLETAP)
+ == PreferredShortcutType.TRIPLETAP) {
+ MagnificationPreferenceFragment.setChecked(getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
+ /* isChecked= */ true);
+ }
} else {
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
// preferred key.
+ optOutMagnificationValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE);
+
// TODO(b/142531156): ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED need to be treated
// as special case in this file.
- optOutMagnificationValueFromSettings(getContext(), PreferredShortcutType.SOFTWARE);
+ MagnificationPreferenceFragment.setChecked(getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
+ /* isChecked= */ false);
+ MagnificationPreferenceFragment.setChecked(getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
+ /* isChecked= */ false);
}
}
@@ -480,10 +482,7 @@
mShortcutPreference.setTitle(R.string.accessibility_magnification_shortcut_title);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
mShortcutPreference.setOnClickListener(this);
- // Put the shortcutPreference before videoPreference.
- mShortcutPreference.setOrder(mVideoPreference.getOrder() - 1);
// TODO(b/142530063): Check the new setting key to decide which summary should be shown.
- preferenceScreen.addPreference(mShortcutPreference);
}
private void updateShortcutPreference() {
diff --git a/src/com/android/settings/applications/AppStateAppOpsBridge.java b/src/com/android/settings/applications/AppStateAppOpsBridge.java
index 0e3ee2d..3dbdbe9 100755
--- a/src/com/android/settings/applications/AppStateAppOpsBridge.java
+++ b/src/com/android/settings/applications/AppStateAppOpsBridge.java
@@ -328,7 +328,7 @@
public boolean isPermissible() {
// defining the default behavior as permissible as long as the package requested this
// permission (this means pre-M gets approval during install time; M apps gets approval
- // during runtime.
+ // during runtime).
if (appOpMode == AppOpsManager.MODE_DEFAULT) {
return staticPermissionGranted;
}
diff --git a/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java b/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java
new file mode 100644
index 0000000..5a69035
--- /dev/null
+++ b/src/com/android/settings/applications/AppStateManageExternalStorageBridge.java
@@ -0,0 +1,72 @@
+/*
+ * 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.applications;
+
+import android.Manifest;
+import android.app.AppOpsManager;
+import android.content.Context;
+
+import com.android.settingslib.applications.ApplicationsState;
+
+/**
+ * Retrieves information from {@link AppOpsManager} and {@link android.content.pm.PackageManager}
+ * regarding {@link AppOpsManager#OP_MANAGE_EXTERNAL_STORAGE} and
+ * {@link Manifest.permission#MANAGE_EXTERNAL_STORAGE}.
+ */
+public class AppStateManageExternalStorageBridge extends AppStateAppOpsBridge {
+ private static final int APP_OPS_OP_CODE = AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE;
+ private static final String[] PERMISSIONS = {
+ Manifest.permission.MANAGE_EXTERNAL_STORAGE
+ };
+
+ public AppStateManageExternalStorageBridge(Context context, ApplicationsState appState,
+ Callback callback) {
+ super(context, appState, callback, APP_OPS_OP_CODE, PERMISSIONS);
+ }
+
+ @Override
+ protected void updateExtraInfo(ApplicationsState.AppEntry app, String pkg, int uid) {
+ app.extraInfo = getManageExternalStoragePermState(pkg, uid);
+ }
+
+ /**
+ * Returns the MANAGE_EXTERNAL_STORAGE {@link AppStateAppOpsBridge.PermissionState} object
+ * associated with the given package and user.
+ */
+ public PermissionState getManageExternalStoragePermState(String pkg, int uid) {
+ return getPermissionInfo(pkg, uid);
+ }
+
+ /**
+ * Used by {@link com.android.settings.applications.manageapplications.AppFilterRegistry} to
+ * determine which apps get to appear on the Special App Access list.
+ */
+ public static final ApplicationsState.AppFilter FILTER_MANAGE_EXTERNAL_STORAGE =
+ new ApplicationsState.AppFilter() {
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public boolean filterApp(ApplicationsState.AppEntry info) {
+ // If extraInfo != null, it means that the app has declared
+ // Manifest.permission.MANAGE_EXTERNAL_STORAGE and therefore it should appear on our
+ // list
+ return info.extraInfo != null;
+ }
+ };
+}
diff --git a/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java b/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java
new file mode 100644
index 0000000..63ce440
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/ManageExternalStorageDetails.java
@@ -0,0 +1,180 @@
+/*
+ * 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.applications.appinfo;
+
+import android.app.AppOpsManager;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.appcompat.app.AlertDialog;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+import androidx.preference.Preference.OnPreferenceClickListener;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.applications.AppInfoWithHeader;
+import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
+import com.android.settings.applications.AppStateManageExternalStorageBridge;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+
+/**
+ * Class for displaying app info related to {@link AppOpsManager#OP_MANAGE_EXTERNAL_STORAGE}.
+ */
+public class ManageExternalStorageDetails extends AppInfoWithHeader implements
+ OnPreferenceChangeListener, OnPreferenceClickListener {
+
+ private static final String KEY_APP_OPS_SETTINGS_SWITCH = "app_ops_settings_switch";
+
+ private AppStateManageExternalStorageBridge mBridge;
+ private AppOpsManager mAppOpsManager;
+ private SwitchPreference mSwitchPref;
+ private PermissionState mPermissionState;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Context context = getActivity();
+ mBridge = new AppStateManageExternalStorageBridge(context, mState, null);
+ mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+
+ // initialize preferences
+ addPreferencesFromResource(R.xml.manage_external_storage_permission_details);
+ mSwitchPref = findPreference(KEY_APP_OPS_SETTINGS_SWITCH);
+
+ // install event listeners
+ mSwitchPref.setOnPreferenceChangeListener(this);
+
+ mMetricsFeatureProvider =
+ FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater,
+ ViewGroup container,
+ Bundle savedInstanceState) {
+ // if we don't have a package info, show a page saying this is unsupported
+ if (mPackageInfo == null) {
+ return inflater.inflate(R.layout.manage_applications_apps_unsupported, null);
+ }
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mBridge.release();
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ return false;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mSwitchPref) {
+ if (mPermissionState != null && !newValue.equals(mPermissionState.isPermissible())) {
+ setManageExternalStorageState((Boolean) newValue);
+ refreshUi();
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Toggles {@link AppOpsManager#OP_MANAGE_EXTERNAL_STORAGE} for the app.
+ */
+ private void setManageExternalStorageState(boolean newState) {
+ logSpecialPermissionChange(newState, mPackageName);
+ mAppOpsManager.setMode(AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE,
+ mPackageInfo.applicationInfo.uid, mPackageName, newState
+ ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
+ }
+
+ private void logSpecialPermissionChange(boolean newState, String packageName) {
+ int logCategory = newState ? SettingsEnums.APP_SPECIAL_PERMISSION_MANAGE_EXT_STRG_ALLOW
+ : SettingsEnums.APP_SPECIAL_PERMISSION_MANAGE_EXT_STRG_DENY;
+
+ mMetricsFeatureProvider.action(
+ mMetricsFeatureProvider.getAttribution(getActivity()),
+ logCategory,
+ getMetricsCategory(),
+ packageName,
+ 0 /* value */);
+ }
+
+ @Override
+ protected boolean refreshUi() {
+ if (mPackageInfo == null) {
+ return true;
+ }
+
+ mPermissionState = mBridge.getManageExternalStoragePermState(mPackageName,
+ mPackageInfo.applicationInfo.uid);
+
+ mSwitchPref.setChecked(mPermissionState.isPermissible());
+
+ // you cannot ask a user to grant you a permission you did not have!
+ mSwitchPref.setEnabled(mPermissionState.permissionDeclared);
+
+ return true;
+ }
+
+ @Override
+ protected AlertDialog createDialog(int id, int errorCode) {
+ return null;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.MANAGE_EXTERNAL_STORAGE;
+ }
+
+ /**
+ * Returns the string that states whether whether the app has access to
+ * {@link AppOpsManager#OP_MANAGE_EXTERNAL_STORAGE}.
+ * <p>This string is used in the "All files access" page that displays all apps requesting
+ * {@link android.Manifest.permission#MANAGE_EXTERNAL_STORAGE}
+ */
+ public static CharSequence getSummary(Context context, AppEntry entry) {
+ final PermissionState state;
+ if (entry.extraInfo instanceof PermissionState) {
+ state = (PermissionState) entry.extraInfo;
+ } else {
+ state = new AppStateManageExternalStorageBridge(context, null, null)
+ .getManageExternalStoragePermState(entry.info.packageName, entry.info.uid);
+ }
+
+ return getSummary(context, state);
+ }
+
+ private static CharSequence getSummary(Context context, PermissionState state) {
+ return context.getString(state.isPermissible()
+ ? R.string.app_permission_summary_allowed
+ : R.string.app_permission_summary_not_allowed);
+ }
+}
diff --git a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
index 250dce0..58907a7 100644
--- a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
+++ b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
@@ -20,6 +20,7 @@
import com.android.settings.R;
import com.android.settings.applications.AppStateInstallAppsBridge;
+import com.android.settings.applications.AppStateManageExternalStorageBridge;
import com.android.settings.applications.AppStateNotificationBridge;
import com.android.settings.applications.AppStateOverlayBridge;
import com.android.settings.applications.AppStatePowerBridge;
@@ -71,14 +72,15 @@
public static final int FILTER_APPS_INSTALL_SOURCES = 13;
public static final int FILTER_APP_CAN_CHANGE_WIFI_STATE = 15;
public static final int FILTER_APPS_BLOCKED = 16;
- // Next id: 17
+ public static final int FILTER_MANAGE_EXTERNAL_STORAGE = 17;
+ // Next id: 18. If you add an entry here, length of mFilters should be updated
private static AppFilterRegistry sRegistry;
private final AppFilterItem[] mFilters;
private AppFilterRegistry() {
- mFilters = new AppFilterItem[17];
+ mFilters = new AppFilterItem[18];
// High power whitelist, on
mFilters[FILTER_APPS_POWER_WHITELIST] = new AppFilterItem(
@@ -178,6 +180,11 @@
AppStateNotificationBridge.FILTER_APP_NOTIFICATION_BLOCKED,
FILTER_APPS_BLOCKED,
R.string.filter_notif_blocked_apps);
+
+ mFilters[FILTER_MANAGE_EXTERNAL_STORAGE] = new AppFilterItem(
+ AppStateManageExternalStorageBridge.FILTER_MANAGE_EXTERNAL_STORAGE,
+ FILTER_MANAGE_EXTERNAL_STORAGE,
+ R.string.filter_manage_external_storage);
}
public static AppFilterRegistry getInstance() {
@@ -204,6 +211,8 @@
return FILTER_APP_CAN_CHANGE_WIFI_STATE;
case ManageApplications.LIST_TYPE_NOTIFICATION:
return FILTER_APPS_RECENT;
+ case ManageApplications.LIST_MANAGE_EXTERNAL_STORAGE:
+ return FILTER_MANAGE_EXTERNAL_STORAGE;
default:
return FILTER_APPS_ALL;
}
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 02e42e2..d38893f 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -88,6 +88,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
+import com.android.settings.applications.AppStateManageExternalStorageBridge;
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateBaseBridge;
import com.android.settings.applications.AppStateInstallAppsBridge;
@@ -100,6 +101,7 @@
import com.android.settings.applications.AppStateWriteSettingsBridge;
import com.android.settings.applications.AppStorageSettings;
import com.android.settings.applications.UsageAccessDetails;
+import com.android.settings.applications.appinfo.ManageExternalStorageDetails;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
import com.android.settings.applications.appinfo.DrawOverlayDetails;
import com.android.settings.applications.appinfo.ExternalSourcesDetails;
@@ -224,6 +226,7 @@
public static final int LIST_TYPE_MOVIES = 10;
public static final int LIST_TYPE_PHOTOGRAPHY = 11;
public static final int LIST_TYPE_WIFI_ACCESS = 13;
+ public static final int LIST_MANAGE_EXTERNAL_STORAGE = 14;
// List types that should show instant apps.
public static final Set<Integer> LIST_TYPES_WITH_INSTANT = new ArraySet<>(Arrays.asList(
@@ -311,6 +314,9 @@
} else if (className.equals(Settings.ChangeWifiStateActivity.class.getName())) {
mListType = LIST_TYPE_WIFI_ACCESS;
screenTitle = R.string.change_wifi_state_title;
+ } else if (className.equals(Settings.ManageExternalStorageActivity.class.getName())) {
+ mListType = LIST_MANAGE_EXTERNAL_STORAGE;
+ screenTitle = R.string.manage_external_storage_title;
} else if (className.equals(Settings.NotificationAppListActivity.class.getName())) {
mListType = LIST_TYPE_NOTIFICATION;
mUsageStatsManager = IUsageStatsManager.Stub.asInterface(
@@ -538,6 +544,8 @@
return SettingsEnums.MANAGE_EXTERNAL_SOURCES;
case LIST_TYPE_WIFI_ACCESS:
return SettingsEnums.CONFIGURE_WIFI;
+ case LIST_MANAGE_EXTERNAL_STORAGE:
+ return SettingsEnums.MANAGE_EXTERNAL_STORAGE;
default:
return SettingsEnums.PAGE_UNKNOWN;
}
@@ -640,6 +648,10 @@
startAppInfoFragment(ChangeWifiStateDetails.class,
R.string.change_wifi_state_title);
break;
+ case LIST_MANAGE_EXTERNAL_STORAGE:
+ startAppInfoFragment(ManageExternalStorageDetails.class,
+ R.string.manage_external_storage_title);
+ break;
// TODO: Figure out if there is a way where we can spin up the profile's settings
// process ahead of time, to avoid a long load of data when user clicks on a managed
// app. Maybe when they load the list of apps that contains managed profile apps.
@@ -713,6 +725,8 @@
return R.string.help_uri_apps_photography;
case LIST_TYPE_WIFI_ACCESS:
return R.string.help_uri_apps_wifi_access;
+ case LIST_MANAGE_EXTERNAL_STORAGE:
+ return R.string.help_uri_manage_external_storage;
default:
case LIST_TYPE_MAIN:
return R.string.help_uri_apps;
@@ -1031,6 +1045,8 @@
mExtraInfoBridge = new AppStateInstallAppsBridge(mContext, mState, this);
} else if (mManageApplications.mListType == LIST_TYPE_WIFI_ACCESS) {
mExtraInfoBridge = new AppStateChangeWifiStateBridge(mContext, mState, this);
+ } else if (mManageApplications.mListType == LIST_MANAGE_EXTERNAL_STORAGE) {
+ mExtraInfoBridge = new AppStateManageExternalStorageBridge(mContext, mState, this);
} else {
mExtraInfoBridge = null;
}
@@ -1486,6 +1502,9 @@
case LIST_TYPE_WIFI_ACCESS:
holder.setSummary(ChangeWifiStateDetails.getSummary(mContext, entry));
break;
+ case LIST_MANAGE_EXTERNAL_STORAGE:
+ holder.setSummary(ManageExternalStorageDetails.getSummary(mContext, entry));
+ break;
default:
holder.updateSizeText(entry, mManageApplications.mInvalidSizeStr, mWhichSize);
break;
diff --git a/src/com/android/settings/bugreporthandler/BugReportHandlerPicker.java b/src/com/android/settings/bugreporthandler/BugReportHandlerPicker.java
index e7adf7f..5839e3c 100644
--- a/src/com/android/settings/bugreporthandler/BugReportHandlerPicker.java
+++ b/src/com/android/settings/bugreporthandler/BugReportHandlerPicker.java
@@ -37,6 +37,7 @@
import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.applications.DefaultAppInfo;
+import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.widget.FooterPreference;
@@ -76,6 +77,14 @@
}
@Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ if (!DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context)) {
+ getActivity().finish();
+ }
+ }
+
+ @Override
protected int getPreferenceScreenResId() {
return R.xml.bug_report_handler_settings;
}
diff --git a/src/com/android/settings/datausage/BillingCyclePreference.java b/src/com/android/settings/datausage/BillingCyclePreference.java
index 8dea7de..47ef56b 100644
--- a/src/com/android/settings/datausage/BillingCyclePreference.java
+++ b/src/com/android/settings/datausage/BillingCyclePreference.java
@@ -96,7 +96,7 @@
}
/**
- * Implementation of MobileDataEnabledListener.Client
+ * Implementation of {@code MobileDataEnabledListener.Client}
*/
public void onMobileDataEnabledChange() {
updateEnabled();
diff --git a/src/com/android/settings/datausage/CellDataPreference.java b/src/com/android/settings/datausage/CellDataPreference.java
index f4f2be7..4a49f33 100644
--- a/src/com/android/settings/datausage/CellDataPreference.java
+++ b/src/com/android/settings/datausage/CellDataPreference.java
@@ -240,7 +240,7 @@
};
/**
- * Implementation of MobileDataEnabledListener.Client
+ * Implementation of {@code MobileDataEnabledListener.Client}
*/
@VisibleForTesting
public void onMobileDataEnabledChange() {
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index f747951..0cfb831 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -201,7 +201,6 @@
public void onDestroy() {
mUidDetailProvider.clearCache();
mUidDetailProvider = null;
- mDataStateListener.stop();
super.onDestroy();
}
@@ -232,7 +231,7 @@
}
/**
- * Implementation of MobileDataEnabledListener.Client
+ * Implementation of {@code MobileDataEnabledListener.Client}
*/
public void onMobileDataEnabledChange() {
updatePolicy();
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 0796e5a..1a83800 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -78,7 +78,7 @@
super.onCreate(icicle);
Context context = getContext();
- // enable ProxySubscriptionMgr with Lifecycle support for all controllers
+ // Enable ProxySubscriptionMgr with Lifecycle support for all controllers
// live within this fragment
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(context);
mProxySubscriptionMgr.setLifecycle(getLifecycle());
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 600b9e8..a26e359 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -19,8 +19,11 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.INetworkPolicyManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkTemplate;
+import android.os.ServiceManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionPlan;
@@ -296,12 +299,51 @@
mSnapshotTime = primaryPlan.getDataUsageTime();
}
}
- mManageSubscriptionIntent =
- mSubscriptionManager.createManageSubscriptionIntent(mSubscriptionId);
+ mManageSubscriptionIntent = createManageSubscriptionIntent(mSubscriptionId);
Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubscriptionId
+ ", intent " + mManageSubscriptionIntent);
}
+ /**
+ * Create an {@link Intent} that can be launched towards the carrier app
+ * that is currently defining the billing relationship plan through
+ * {@link INetworkPolicyManager#setSubscriptionPlans(int, SubscriptionPlan [], String)}.
+ *
+ * @return ready to launch Intent targeted towards the carrier app, or
+ * {@code null} if no carrier app is defined, or if the defined
+ * carrier app provides no management activity.
+ */
+ private Intent createManageSubscriptionIntent(int subId) {
+ final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
+ ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
+ String owner = "";
+ try {
+ owner = iNetPolicyManager.getSubscriptionPlansOwner(subId);
+ } catch (Exception ex) {
+ Log.w(TAG, "Fail to get subscription plan owner for subId " + subId, ex);
+ }
+
+ if (TextUtils.isEmpty(owner)) {
+ return null;
+ }
+
+ final List<SubscriptionPlan> plans = mSubscriptionManager.getSubscriptionPlans(subId);
+ if (plans.isEmpty()) {
+ return null;
+ }
+
+ final Intent intent = new Intent(SubscriptionManager.ACTION_MANAGE_SUBSCRIPTION_PLANS);
+ intent.setPackage(owner);
+ intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
+
+ if (mActivity.getPackageManager().queryIntentActivities(intent,
+ PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
+ return null;
+ }
+
+ return intent;
+ }
+
public static SubscriptionPlan getPrimaryPlan(SubscriptionManager subManager, int primaryId) {
List<SubscriptionPlan> plans = subManager.getSubscriptionPlans(primaryId);
if (CollectionUtils.isEmpty(plans)) {
diff --git a/src/com/android/settings/datausage/DataUsageUtils.java b/src/com/android/settings/datausage/DataUsageUtils.java
index ef3e7b6..0308cf7 100644
--- a/src/com/android/settings/datausage/DataUsageUtils.java
+++ b/src/com/android/settings/datausage/DataUsageUtils.java
@@ -159,11 +159,12 @@
* SubscriptionManager#INVALID_SUBSCRIPTION_ID
*/
public static int getDefaultSubscriptionId(Context context) {
- SubscriptionManager subManager = SubscriptionManager.from(context);
+ SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
if (subManager == null) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
- SubscriptionInfo subscriptionInfo = subManager.getDefaultDataSubscriptionInfo();
+ SubscriptionInfo subscriptionInfo =
+ subManager.getActiveSubscriptionInfo(subManager.getDefaultDataSubscriptionId());
if (subscriptionInfo == null) {
List<SubscriptionInfo> list = subManager.getAllSubscriptionInfoList();
if (list.size() == 0) {
diff --git a/src/com/android/settings/development/compat/PlatformCompatDashboard.java b/src/com/android/settings/development/compat/PlatformCompatDashboard.java
index 2b0c655..ffa5c29 100644
--- a/src/com/android/settings/development/compat/PlatformCompatDashboard.java
+++ b/src/com/android/settings/development/compat/PlatformCompatDashboard.java
@@ -16,7 +16,9 @@
package com.android.settings.development.compat;
+import static com.android.settings.development.AppPicker.EXTRA_DEBUGGABLE;
import static com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_COMPAT_CHANGE_APP;
+import static com.android.internal.compat.OverrideAllowedState.ALLOWED;
import android.app.Activity;
import android.app.settings.SettingsEnums;
@@ -25,7 +27,9 @@
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -37,9 +41,12 @@
import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreference;
+import com.android.internal.compat.AndroidBuildClassifier;
import com.android.internal.compat.CompatibilityChangeConfig;
import com.android.internal.compat.CompatibilityChangeInfo;
import com.android.internal.compat.IPlatformCompat;
+import com.android.internal.compat.IOverrideValidator;
+import com.android.internal.compat.OverrideAllowedState;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.development.AppPicker;
@@ -64,6 +71,8 @@
private CompatibilityChangeInfo[] mChanges;
+ private AndroidBuildClassifier mAndroidBuildClassifier = new AndroidBuildClassifier();
+
@VisibleForTesting
String mSelectedApp;
@@ -117,17 +126,21 @@
if (requestCode == REQUEST_COMPAT_CHANGE_APP) {
if (resultCode == Activity.RESULT_OK) {
mSelectedApp = data.getAction();
- addPreferences();
+ try {
+ final ApplicationInfo applicationInfo = getApplicationInfo();
+ addPreferences(applicationInfo);
+ } catch (PackageManager.NameNotFoundException e) {
+ startAppPicker();
+ }
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
- private void addPreferences() {
+ private void addPreferences(ApplicationInfo applicationInfo) {
getPreferenceScreen().removeAll();
- getPreferenceScreen().addPreference(
- createAppPreference(getApplicationInfo().loadIcon(getPackageManager())));
+ getPreferenceScreen().addPreference(createAppPreference(applicationInfo));
// Differentiate compatibility changes into default enabled, default disabled and enabled
// after target sdk.
final CompatibilityChangeConfig configMappings = getAppChangeMappings();
@@ -164,7 +177,7 @@
try {
final ApplicationInfo applicationInfo = getApplicationInfo();
return getPlatformCompat().getAppConfig(applicationInfo);
- } catch (RemoteException e) {
+ } catch (RemoteException | PackageManager.NameNotFoundException e) {
throw new RuntimeException("Could not get app config!", e);
}
}
@@ -183,7 +196,15 @@
change.getName() != null ? change.getName() : "Change_" + change.getId();
item.setSummary(changeName);
item.setKey(changeName);
- item.setEnabled(true);
+ boolean shouldEnable = true;
+ try {
+ shouldEnable = getPlatformCompat().getOverrideValidator()
+ .getOverrideAllowedState(change.getId(), mSelectedApp)
+ .state == ALLOWED;
+ } catch (RemoteException e) {
+ throw new RuntimeException("Could not check if change can be overridden for app.", e);
+ }
+ item.setEnabled(shouldEnable);
item.setChecked(currentValue);
item.setOnPreferenceChangeListener(
new CompatChangePreferenceChangeListener(change.getId()));
@@ -195,12 +216,8 @@
*
* @return an {@link ApplicationInfo} instance.
*/
- ApplicationInfo getApplicationInfo() {
- try {
- return getPackageManager().getApplicationInfo(mSelectedApp, 0);
- } catch (PackageManager.NameNotFoundException e) {
- throw new RuntimeException("Could not get ApplicationInfo for selected app!", e);
- }
+ ApplicationInfo getApplicationInfo() throws PackageManager.NameNotFoundException {
+ return getPackageManager().getApplicationInfo(mSelectedApp, 0);
}
/**
@@ -209,9 +226,10 @@
* <p>The {@link Preference} contains the icon, package name and target SDK for the selected
* app. Selecting this preference will also re-trigger the app selection dialog.</p>
*/
- Preference createAppPreference(Drawable icon) {
- final ApplicationInfo applicationInfo = getApplicationInfo();
- final Preference appPreference = new Preference(getPreferenceScreen().getContext());
+ Preference createAppPreference(ApplicationInfo applicationInfo) {
+ final Context context = getPreferenceScreen().getContext();
+ final Drawable icon = applicationInfo.loadIcon(context.getPackageManager());
+ final Preference appPreference = new Preference(context);
appPreference.setIcon(icon);
appPreference.setSummary(mSelectedApp
+ " SDK "
@@ -246,6 +264,11 @@
private void startAppPicker() {
final Intent intent = new Intent(getContext(), AppPicker.class);
+ // If build is neither userdebug nor eng, only include debuggable apps
+ final boolean debuggableBuild = mAndroidBuildClassifier.isDebuggableBuild();
+ if (!debuggableBuild) {
+ intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true /* value */);
+ }
startActivityForResult(intent, REQUEST_COMPAT_CHANGE_APP);
}
diff --git a/src/com/android/settings/network/BluetoothTetherPreferenceController.java b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
new file mode 100644
index 0000000..10849a0
--- /dev/null
+++ b/src/com/android/settings/network/BluetoothTetherPreferenceController.java
@@ -0,0 +1,141 @@
+/*
+ * 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.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * This controller helps to manage the switch state and visibility of bluetooth tether switch
+ * preference. It stores preference value when preference changed.
+ * TODO(b/147272749): Extend BasePreferenceController.java instead.
+ */
+public final class BluetoothTetherPreferenceController extends AbstractPreferenceController
+ implements LifecycleObserver, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "BluetoothTetherPreferenceController";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ @VisibleForTesting
+ static final String PREF_KEY = "enable_bluetooth_tethering";
+ private final ConnectivityManager mCm;
+ private int mBluetoothState;
+ private Preference mPreference;
+ private final SharedPreferences mSharedPreferences;
+
+ public BluetoothTetherPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context);
+ mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mSharedPreferences =
+ context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @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 isAvailable() {
+ final String[] bluetoothRegexs = mCm.getTetherableBluetoothRegexs();
+ return bluetoothRegexs != null && bluetoothRegexs.length > 0;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(PREF_KEY);
+ if (mPreference != null && mPreference instanceof SwitchPreference) {
+ ((SwitchPreference) mPreference)
+ .setChecked(mSharedPreferences.getBoolean(PREF_KEY, false));
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ switch (mBluetoothState) {
+ case BluetoothAdapter.STATE_ON:
+ case BluetoothAdapter.STATE_OFF:
+ // fall through.
+ case BluetoothAdapter.ERROR:
+ preference.setEnabled(true);
+ break;
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ case BluetoothAdapter.STATE_TURNING_ON:
+ // fall through.
+ default:
+ preference.setEnabled(false);
+ }
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY;
+ }
+
+ @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);
+ }
+ }
+ };
+
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object o) {
+ if (DEBUG) {
+ Log.d(TAG, "preference changing to " + o);
+ }
+ final SharedPreferences.Editor editor = mSharedPreferences.edit();
+ editor.putBoolean(PREF_KEY, (Boolean) o);
+ editor.apply();
+ return true;
+ }
+}
diff --git a/src/com/android/settings/network/MobileDataEnabledListener.java b/src/com/android/settings/network/MobileDataEnabledListener.java
index 4c04282..b030823 100644
--- a/src/com/android/settings/network/MobileDataEnabledListener.java
+++ b/src/com/android/settings/network/MobileDataEnabledListener.java
@@ -25,12 +25,12 @@
private Context mContext;
private Client mClient;
private int mSubId;
- /**
- * There're 2 listeners both activated at the same time.
- * For project that access MOBILE_DATA, only first listener is functional.
- * For project that access "MOBILE_DATA + subId", first listener will be stopped when receiving
- * any onChange from second listener.
- */
+
+ // There're 2 listeners both activated at the same time.
+ // For project that access MOBILE_DATA, only first listener is functional.
+ // For project that access "MOBILE_DATA + subId", first listener will be stopped when receiving
+ // any onChange from second listener.
+
private GlobalSettingsChangeListener mListener;
private GlobalSettingsChangeListener mListenerForSubId;
diff --git a/src/com/android/settings/network/TetherEnabler.java b/src/com/android/settings/network/TetherEnabler.java
index 9106aa1..6c6c959 100644
--- a/src/com/android/settings/network/TetherEnabler.java
+++ b/src/com/android/settings/network/TetherEnabler.java
@@ -32,11 +32,11 @@
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
+import android.util.Log;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.PreferenceManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.datausage.DataSaverBackend;
@@ -52,13 +52,20 @@
*/
public final class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListener,
- DataSaverBackend.Listener, LifecycleObserver {
+ DataSaverBackend.Listener, LifecycleObserver,
+ SharedPreferences.OnSharedPreferenceChangeListener {
+
+ private static final String TAG = "TetherEnabler";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+
+ public static final String SHARED_PREF = "tether_options";
+
@VisibleForTesting
- static final String WIFI_TETHER_KEY = "enable_wifi_tethering";
+ static final String WIFI_TETHER_KEY = WifiTetherDisablePreferenceController.PREF_KEY;
@VisibleForTesting
- static final String USB_TETHER_KEY = "enable_usb_tethering";
+ static final String USB_TETHER_KEY = UsbTetherPreferenceController.PREF_KEY;
@VisibleForTesting
- static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering";
+ static final String BLUETOOTH_TETHER_KEY = BluetoothTetherPreferenceController.PREF_KEY;
private final SwitchWidgetController mSwitchWidgetController;
private final WifiManager mWifiManager;
@@ -76,7 +83,6 @@
public void onTetheringFailed() {
super.onTetheringFailed();
mSwitchWidgetController.setChecked(false);
- setSwitchWidgetEnabled(true);
}
};
private final AtomicReference<BluetoothPan> mBluetoothPan;
@@ -84,12 +90,12 @@
private boolean mBluetoothEnableForTether;
private final BluetoothAdapter mBluetoothAdapter;
- TetherEnabler(Context context, SwitchWidgetController switchWidgetController,
+ public TetherEnabler(Context context, SwitchWidgetController switchWidgetController,
AtomicReference<BluetoothPan> bluetoothPan) {
mContext = context;
mSwitchWidgetController = switchWidgetController;
mDataSaverBackend = new DataSaverBackend(context);
- mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
+ mSharedPreferences = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
@@ -110,6 +116,16 @@
setSwitchWidgetEnabled(true);
}
+ @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
+ public void onResume() {
+ mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ public void onPause() {
+ mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
+ }
+
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onStop() {
mDataSaverBackend.remListener(this);
@@ -148,19 +164,16 @@
@VisibleForTesting
void stopTether() {
- setSwitchWidgetEnabled(false);
- // Wi-Fi tether is selected by default
+ // Wi-Fi tether is selected by default.
if (mSharedPreferences.getBoolean(WIFI_TETHER_KEY, true)) {
mConnectivityManager.stopTethering(TETHERING_WIFI);
}
- // USB tether is not selected by default
if (mSharedPreferences.getBoolean(USB_TETHER_KEY, false)) {
mConnectivityManager.stopTethering(TETHERING_USB);
}
- // Bluetooth tether is not selected by default
if (mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)) {
mConnectivityManager.stopTethering(TETHERING_BLUETOOTH);
}
@@ -168,19 +181,16 @@
@VisibleForTesting
void startTether() {
- setSwitchWidgetEnabled(false);
- // Wi-Fi tether is selected by default
+ // Wi-Fi tether is selected by default.
if (mSharedPreferences.getBoolean(WIFI_TETHER_KEY, true)) {
startTethering(TETHERING_WIFI);
}
- // USB tether is not selected by default
if (mSharedPreferences.getBoolean(USB_TETHER_KEY, false)) {
startTethering(TETHERING_USB);
}
- // Bluetooth tether is not selected by default
if (mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)) {
startTethering(TETHERING_BLUETOOTH);
}
@@ -188,18 +198,24 @@
@VisibleForTesting
void startTethering(int choice) {
+ if (choice == TETHERING_WIFI && mWifiManager.isWifiApEnabled()) {
+ if (DEBUG) {
+ Log.d(TAG, "Wifi tether already active!");
+ }
+ return;
+ }
+
if (choice == TETHERING_BLUETOOTH) {
- // Turn on Bluetooth first.
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
+ if (DEBUG) {
+ Log.d(TAG, "Turn on bluetooth first.");
+ }
mBluetoothEnableForTether = true;
mBluetoothAdapter.enable();
return;
}
- } else if (choice == TETHERING_WIFI && mWifiManager.isWifiApEnabled()) {
- return;
}
-
mConnectivityManager.startTethering(choice, true /* showProvisioningUi */,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
}
@@ -213,24 +229,21 @@
ConnectivityManager.EXTRA_ACTIVE_TETHER);
mSwitchWidgetController.setChecked(
isTethering(active.toArray(new String[active.size()])));
- setSwitchWidgetEnabled(true);
} else if (TextUtils.equals(BluetoothAdapter.ACTION_STATE_CHANGED, action)) {
- if (mBluetoothEnableForTether) {
- switch (intent
- .getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
- case BluetoothAdapter.STATE_ON:
+ switch (intent
+ .getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
+ case BluetoothAdapter.STATE_ON:
+ if (mBluetoothEnableForTether) {
startTethering(TETHERING_BLUETOOTH);
- mBluetoothEnableForTether = false;
- break;
-
- case BluetoothAdapter.STATE_OFF:
- case BluetoothAdapter.ERROR:
- mBluetoothEnableForTether = false;
- break;
-
- default:
- // ignore transition states
- }
+ }
+ // Fall through.
+ case BluetoothAdapter.STATE_OFF:
+ // Fall through.
+ case BluetoothAdapter.ERROR:
+ mBluetoothEnableForTether = false;
+ break;
+ default:
+ // ignore transition states
}
}
}
@@ -251,4 +264,30 @@
public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
// we don't care, since we just want to read the value
}
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (!mSwitchWidgetController.isChecked()) {
+ return;
+ }
+ if (TextUtils.equals(WIFI_TETHER_KEY, key)) {
+ if (sharedPreferences.getBoolean(key, true)) {
+ startTethering(TETHERING_WIFI);
+ } else {
+ mConnectivityManager.stopTethering(TETHERING_WIFI);
+ }
+ } else if (TextUtils.equals(USB_TETHER_KEY, key)) {
+ if (sharedPreferences.getBoolean(key, false)) {
+ startTethering(TETHERING_USB);
+ } else {
+ mConnectivityManager.stopTethering(TETHERING_USB);
+ }
+ } else if (TextUtils.equals(BLUETOOTH_TETHER_KEY, key)) {
+ if (sharedPreferences.getBoolean(key, false)) {
+ startTethering(TETHERING_BLUETOOTH);
+ } else {
+ mConnectivityManager.stopTethering(TETHERING_BLUETOOTH);
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/network/UsbTetherPreferenceController.java b/src/com/android/settings/network/UsbTetherPreferenceController.java
new file mode 100644
index 0000000..74e8be8
--- /dev/null
+++ b/src/com/android/settings/network/UsbTetherPreferenceController.java
@@ -0,0 +1,144 @@
+/*
+ * 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.content.SharedPreferences;
+import android.hardware.usb.UsbManager;
+import android.net.ConnectivityManager;
+import android.os.Environment;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.Utils;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+/**
+ * This controller helps to manage the switch state and visibility of USB tether switch
+ * preference. It stores preference values when preference changed.
+ * TODO(b/147272749): Extend BasePreferenceController.java instead.
+ *
+ */
+public final class UsbTetherPreferenceController extends AbstractPreferenceController implements
+ LifecycleObserver, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "UsbTetherPrefController";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ @VisibleForTesting
+ static final String PREF_KEY = "enable_usb_tethering";
+
+ private final ConnectivityManager mCm;
+ private boolean mUsbConnected;
+ private boolean mMassStorageActive;
+ private Preference mPreference;
+ private final SharedPreferences mSharedPreferences;
+
+ public UsbTetherPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context);
+ mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mSharedPreferences =
+ context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @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 isAvailable() {
+ String[] usbRegexs = mCm.getTetherableUsbRegexs();
+ return usbRegexs != null && usbRegexs.length > 0 && !Utils.isMonkeyRunning();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(PREF_KEY);
+ if (mPreference != null && mPreference instanceof SwitchPreference) {
+ ((SwitchPreference) mPreference)
+ .setChecked(mSharedPreferences.getBoolean(PREF_KEY, false));
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (preference != null) {
+ if (mUsbConnected && !mMassStorageActive) {
+ preference.setEnabled(true);
+ } else {
+ preference.setEnabled(false);
+ }
+ }
+ }
+
+ @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);
+ }
+ };
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object o) {
+ if (DEBUG) {
+ Log.d(TAG, "preference changing to " + o);
+ }
+ final SharedPreferences.Editor editor = mSharedPreferences.edit();
+ editor.putBoolean(PREF_KEY, (Boolean) o);
+ editor.apply();
+ return true;
+ }
+}
diff --git a/src/com/android/settings/network/WifiTetherDisablePreferenceController.java b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
new file mode 100644
index 0000000..bf0e208
--- /dev/null
+++ b/src/com/android/settings/network/WifiTetherDisablePreferenceController.java
@@ -0,0 +1,166 @@
+/*
+ * 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.Context;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleObserver;
+import androidx.lifecycle.OnLifecycleEvent;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+/**
+ * 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.
+ * It stores preference value when preference changed and listens to usb tether and bluetooth tether
+ * preferences.
+ *
+ * @see BluetoothTetherPreferenceController
+ * @see UsbTetherPreferenceController
+ * TODO(b/147272749): Extend BasePreferenceController.java instead.
+ *
+ */
+public final class WifiTetherDisablePreferenceController extends AbstractPreferenceController
+ implements LifecycleObserver, Preference.OnPreferenceChangeListener,
+ SharedPreferences.OnSharedPreferenceChangeListener {
+
+ private static final String TAG = "WifiTetherDisablePreferenceController";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ @VisibleForTesting
+ static final String PREF_KEY = "enable_wifi_tethering";
+ private final ConnectivityManager mCm;
+ private boolean mBluetoothTetherEnabled;
+ private boolean mUSBTetherEnabled;
+ private PreferenceScreen mScreen;
+ private Preference mPreference;
+ private final SharedPreferences mSharedPreferences;
+
+ public WifiTetherDisablePreferenceController(Context context, Lifecycle lifecycle) {
+ super(context);
+ mSharedPreferences =
+ context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
+ mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mUSBTetherEnabled = mSharedPreferences.getBoolean(
+ TetherEnabler.USB_TETHER_KEY, false);
+ mBluetoothTetherEnabled = mSharedPreferences.getBoolean(
+ TetherEnabler.BLUETOOTH_TETHER_KEY, false);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
+ public void onResume() {
+ mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
+ public void onPause() {
+ mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
+ return wifiRegexs != null && wifiRegexs.length > 0 && shouldShow();
+ }
+
+ @VisibleForTesting
+ boolean shouldShow() {
+ return mBluetoothTetherEnabled || mUSBTetherEnabled;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ // TODO(b/146818850): Update summary accordingly.
+ return super.getSummary();
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mScreen = screen;
+ mPreference = screen.findPreference(PREF_KEY);
+ if (mPreference != null && mPreference instanceof SwitchPreference) {
+ ((SwitchPreference) mPreference)
+ .setChecked(!mSharedPreferences.getBoolean(PREF_KEY, true));
+ mPreference.setOnPreferenceChangeListener(this);
+ }
+ updateState(mPreference);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ setVisible(mScreen, PREF_KEY, shouldShow());
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+ String key) {
+ if (TextUtils.equals(TetherEnabler.USB_TETHER_KEY, key)) {
+ mUSBTetherEnabled = sharedPreferences.getBoolean(key, false);
+ } else if (TextUtils.equals(TetherEnabler.BLUETOOTH_TETHER_KEY, key)) {
+ mBluetoothTetherEnabled = sharedPreferences.getBoolean(key, false);
+ }
+
+ // Check if we are hiding this preference. If so, make sure the preference is set to
+ // unchecked to enable wifi tether.
+ if (mPreference != null && mPreference instanceof SwitchPreference && !shouldShow()) {
+ final SwitchPreference switchPreference = (SwitchPreference) mPreference;
+ if (switchPreference.isChecked()) {
+ if (DEBUG) {
+ Log.d(TAG,
+ "All other types are unchecked, wifi tether enabled automatically");
+ }
+ // Need to call this method before internal state set.
+ if (switchPreference.callChangeListener(false)) {
+ switchPreference.setChecked(false);
+ }
+ }
+ }
+
+ updateState(mPreference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object o) {
+ // The shared preference's value is in the opposite of this preference's value.
+ final boolean enableWifi = !(boolean) o;
+ if (true) {
+ Log.d(TAG, "check state changing to " + o);
+ }
+ final SharedPreferences.Editor editor = mSharedPreferences.edit();
+ editor.putBoolean(PREF_KEY, enableWifi);
+ editor.apply();
+ return true;
+ }
+}
diff --git a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
index 2348f70..99009c9 100644
--- a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
@@ -28,7 +28,7 @@
@Override
protected SubscriptionInfo getDefaultSubscriptionInfo() {
- return mManager.getDefaultVoiceSubscriptionInfo();
+ return mManager.getActiveSubscriptionInfo(getDefaultSubscriptionId());
}
@Override
diff --git a/src/com/android/settings/network/telephony/CellInfoUtil.java b/src/com/android/settings/network/telephony/CellInfoUtil.java
index 3129694..ab172c8 100644
--- a/src/com/android/settings/network/telephony/CellInfoUtil.java
+++ b/src/com/android/settings/network/telephony/CellInfoUtil.java
@@ -52,7 +52,7 @@
/**
* Returns the title of the network obtained in the manual search.
*
- * @param cellId contains the information of the network.
+ * @param cellId contains the identity of the network.
* @param networkMccMnc contains the MCCMNC string of the network
* @return Long Name if not null/empty, otherwise Short Name if not null/empty,
* else MCCMNC string.
diff --git a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java
index cd51735..e6cace4 100644
--- a/src/com/android/settings/network/telephony/DisabledSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/DisabledSubscriptionController.java
@@ -73,7 +73,7 @@
return;
}
// TODO b/135222940: re-evaluate whether to use mSubscriptionManager#isSubscriptionEnabled
- mCategory.setVisible(mSubscriptionManager.isActiveSubId(mSubId));
+ mCategory.setVisible(mSubscriptionManager.isActiveSubscriptionId(mSubId));
}
@Override
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 675a1ba..f7ed1d0 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -26,12 +26,12 @@
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
-import android.telephony.RadioAccessFamily;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
+
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
@@ -42,6 +42,7 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import com.android.settings.R;
import java.util.ArrayList;
@@ -194,18 +195,18 @@
R.array.enabled_networks_cdma_values);
} else {
switch (settingsNetworkMode) {
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
- case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_EVDO_NO_CDMA:
preference.setEntries(
R.array.enabled_networks_cdma_no_lte_choices);
preference.setEntryValues(
R.array.enabled_networks_cdma_no_lte_values);
break;
- case TelephonyManager.NETWORK_MODE_GLOBAL:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_GLOBAL:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
preference.setEntries(
R.array.enabled_networks_cdma_only_lte_choices);
preference.setEntryValues(
@@ -279,7 +280,7 @@
}
/***
- * Preferred network list add 5G item.
+ * Generate preferred network choices list for 5G
*
* @string/enabled_networks_cdma_choices
* Before | After
@@ -364,9 +365,9 @@
new5gEntryValue = transformLteEntryValueTo5gEntryValue(oldEntryValue);
} else if (mContext.getString(R.string.network_global).equals(oldEntry)) {
//oldEntry: network_global
- //oldEntryValue: TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA
+ //oldEntryValue: TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA
oldEntryValue = Integer.toString(
- TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA);
}
if (!TextUtils.isEmpty(new5gEntry)) {
@@ -382,124 +383,151 @@
}
/**
- * LTE network mode transform to 5G network mode.
+ * transform LTE network mode to 5G network mode.
*
- * @param networkMode this is LTE network mode.
- * @return 5G network mode.
+ * @param networkMode an LTE network mode without 5G.
+ * @return the corresponding network mode with 5G.
*/
private CharSequence transformLteEntryValueTo5gEntryValue(CharSequence networkMode) {
int networkModeInt = Integer.valueOf(networkMode.toString());
- return Integer.toString(addNrToNetworkType(networkModeInt));
+ return Integer.toString(addNrToLteNetworkType(networkModeInt));
+ }
+ private int addNrToLteNetworkType(int networkType) {
+ switch(networkType) {
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_WCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA;
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ return TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
+ default:
+ return networkType; // not LTE
+ }
}
- private int addNrToNetworkType(int networkType) {
- long networkTypeBitmasks = RadioAccessFamily.getRafFromNetworkType(networkType);
- networkTypeBitmasks |= mTelephonyManager.NETWORK_TYPE_BITMASK_NR;
- return RadioAccessFamily.getNetworkTypeFromRaf((int) networkTypeBitmasks);
- }
-
+ /**
+ * Sets the display string for the network mode choice and selects the corresponding item
+ *
+ * @param preference ListPreference for selecting the preferred network mode.
+ * @param networkMode the current network mode. The current mode might not be an option in the
+ * choice list. The nearest choice is selected instead
+ */
private void updatePreferenceValueAndSummary(ListPreference preference, int networkMode) {
preference.setValue(Integer.toString(networkMode));
switch (networkMode) {
- case TelephonyManager.NETWORK_MODE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM:
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
preference.setSummary(R.string.network_3G);
break;
- case TelephonyManager.NETWORK_MODE_WCDMA_ONLY:
- case TelephonyManager.NETWORK_MODE_GSM_UMTS:
- case TelephonyManager.NETWORK_MODE_WCDMA_PREF:
+ case TelephonyManagerConstants.NETWORK_MODE_WCDMA_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_GSM_UMTS:
+ case TelephonyManagerConstants.NETWORK_MODE_WCDMA_PREF:
if (!mIsGlobalCdma) {
- preference.setValue(Integer.toString(TelephonyManager.NETWORK_MODE_WCDMA_PREF));
+ preference.setValue(Integer.toString(TelephonyManagerConstants.NETWORK_MODE_WCDMA_PREF));
preference.setSummary(R.string.network_3G);
} else {
- preference.setValue(Integer.toString(TelephonyManager
+ preference.setValue(Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
preference.setSummary(R.string.network_global);
}
break;
- case TelephonyManager.NETWORK_MODE_GSM_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY:
if (!mIsGlobalCdma) {
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_GSM_ONLY));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY));
preference.setSummary(R.string.network_2G);
} else {
preference.setValue(
- Integer.toString(TelephonyManager
+ Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
preference.setSummary(R.string.network_global);
}
break;
- case TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA:
if (MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
preference.setSummary(
R.string.preferred_network_mode_lte_gsm_umts_summary);
break;
}
- case TelephonyManager.NETWORK_MODE_LTE_ONLY:
- case TelephonyManager.NETWORK_MODE_LTE_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA:
if (!mIsGlobalCdma) {
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
preference.setSummary(
mShow4GForLTE ? R.string.network_4G : R.string.network_lte);
} else {
preference.setValue(
- Integer.toString(TelephonyManager
+ Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
preference.setSummary(R.string.network_global);
}
break;
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO:
if (MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
preference.setSummary(
R.string.preferred_network_mode_lte_cdma_summary);
} else {
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO));
preference.setSummary(
mDisplay5gList ? R.string.network_lte_pure : R.string.network_lte);
}
break;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- preference.setValue(Integer.toString(TelephonyManager
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ preference.setValue(Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
preference.setSummary(R.string.network_3G);
break;
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
- case TelephonyManager.NETWORK_MODE_GLOBAL:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_EVDO_NO_CDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_GLOBAL:
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_EVDO));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO));
preference.setSummary(R.string.network_3G);
break;
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO:
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO));
preference.setSummary(R.string.network_1x);
break;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_ONLY:
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_ONLY));
preference.setSummary(R.string.network_3G);
break;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
if (MobileNetworkUtils.isTdscdmaSupported(mContext, mSubId)) {
preference.setValue(
- Integer.toString(TelephonyManager
+ Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
preference.setSummary(
mDisplay5gList ? R.string.network_lte_pure : R.string.network_lte);
} else {
preference.setValue(
- Integer.toString(TelephonyManager
+ Integer.toString(TelephonyManagerConstants
.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
if (mTelephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
|| mIsGlobalCdma
@@ -516,15 +544,15 @@
}
}
break;
- case TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
preference.setValue(Integer.toString(networkMode));
preference.setSummary(mContext.getString(R.string.network_5G)
+ mContext.getString(R.string.network_recommended));
break;
- case TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA:
preference.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
+ Integer.toString(TelephonyManagerConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA));
if (mTelephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
|| mIsGlobalCdma
|| MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
diff --git a/src/com/android/settings/network/telephony/MobileDataDialogFragment.java b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
index a6183e9..c8a1e98 100644
--- a/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
+++ b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
@@ -86,7 +86,8 @@
final SubscriptionInfo currentSubInfo =
mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
final SubscriptionInfo nextSubInfo =
- mSubscriptionManager.getDefaultDataSubscriptionInfo();
+ mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubscriptionManager.getDefaultDataSubscriptionId());
final String previousName = (nextSubInfo == null)
? getContext().getResources().getString(
diff --git a/src/com/android/settings/network/telephony/MobileDataSlice.java b/src/com/android/settings/network/telephony/MobileDataSlice.java
index c70ae1a..40c747c 100644
--- a/src/com/android/settings/network/telephony/MobileDataSlice.java
+++ b/src/com/android/settings/network/telephony/MobileDataSlice.java
@@ -147,8 +147,8 @@
}
protected static int getDefaultSubscriptionId(SubscriptionManager subscriptionManager) {
- final SubscriptionInfo defaultSubscription =
- subscriptionManager.getDefaultDataSubscriptionInfo();
+ final SubscriptionInfo defaultSubscription = subscriptionManager.getActiveSubscriptionInfo(
+ subscriptionManager.getDefaultDataSubscriptionId());
if (defaultSubscription == null) {
return SubscriptionManager.INVALID_SUBSCRIPTION_ID; // No default subscription
}
@@ -157,8 +157,8 @@
}
private CharSequence getSummary() {
- final SubscriptionInfo defaultSubscription =
- mSubscriptionManager.getDefaultDataSubscriptionInfo();
+ final SubscriptionInfo defaultSubscription = mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubscriptionManager.getDefaultDataSubscriptionId());
if (defaultSubscription == null) {
return null; // no summary text
}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
index 9d5c7cb..a498d47 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java
@@ -78,7 +78,7 @@
mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> {
// TODO b/135222940: re-evaluate whether to use
// mSubscriptionManager#isSubscriptionEnabled
- if (mSubscriptionManager.isActiveSubId(mSubId) != isChecked
+ if (mSubscriptionManager.isActiveSubscriptionId(mSubId) != isChecked
&& (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) {
mSwitchBar.setChecked(!isChecked);
}
@@ -106,7 +106,7 @@
mSwitchBar.hide();
} else {
mSwitchBar.show();
- mSwitchBar.setChecked(mSubscriptionManager.isActiveSubId(mSubId));
+ mSwitchBar.setChecked(mSubscriptionManager.isActiveSubscriptionId(mSubId));
}
}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index c439f75..75e0bb1 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -56,6 +56,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.graph.SignalDrawable;
@@ -99,12 +100,12 @@
* Returns true if Wifi calling is enabled for at least one subscription.
*/
public static boolean isWifiCallingEnabled(Context context) {
- final SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class);
- if (subManager == null) {
- Log.e(TAG, "isWifiCallingEnabled: couldn't get system service.");
+ final int[] subIds = getActiveSubscriptionIdList(context);
+ if (ArrayUtils.isEmpty(subIds)) {
+ Log.d(TAG, "isWifiCallingEnabled: subIds is empty");
return false;
}
- for (int subId : subManager.getActiveSubscriptionIdList()) {
+ for (int subId : subIds) {
if (isWifiCallingEnabled(context, subId)) {
return true;
}
@@ -312,8 +313,8 @@
context.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
Phone.PREFERRED_NT_MODE);
- if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA
- || settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO) {
+ if (settingsNetworkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA
+ || settingsNetworkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO) {
return true;
}
@@ -340,8 +341,8 @@
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
Phone.PREFERRED_NT_MODE);
if (isWorldMode(context, subId)) {
- if (networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
+ if (networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA) {
return true;
} else if (shouldSpeciallyUpdateGsmCdma(context, subId)) {
return true;
@@ -404,7 +405,7 @@
context.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
Phone.PREFERRED_NT_MODE);
- if (networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO
+ if (networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO
&& isWorldMode(context, subId)) {
return false;
}
@@ -417,7 +418,7 @@
}
if (isWorldMode(context, subId)) {
- if (networkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA) {
+ if (networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA) {
return true;
}
}
@@ -465,9 +466,7 @@
* otherwise return {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}
*/
public static int getSearchableSubscriptionId(Context context) {
- final SubscriptionManager subscriptionManager = context.getSystemService(
- SubscriptionManager.class);
- final int subIds[] = subscriptionManager.getActiveSubscriptionIdList();
+ final int[] subIds = getActiveSubscriptionIdList(context);
return subIds.length >= 1 ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
@@ -484,14 +483,12 @@
*/
public static int getAvailability(Context context, int defSubId,
TelephonyAvailabilityCallback callback) {
- final SubscriptionManager subscriptionManager = context.getSystemService(
- SubscriptionManager.class);
if (defSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
// If subId has been set, return the corresponding status
return callback.getAvailabilityStatus(defSubId);
} else {
// Otherwise, search whether there is one subId in device that support this preference
- final int[] subIds = subscriptionManager.getActiveSubscriptionIdList();
+ final int[] subIds = getActiveSubscriptionIdList(context);
if (ArrayUtils.isEmpty(subIds)) {
return callback.getAvailabilityStatus(
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
@@ -522,12 +519,12 @@
context.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
Phone.PREFERRED_NT_MODE);
- if (networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA
- || networkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA) {
+ if (networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA
+ || networkMode == TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA) {
if (!isTdscdmaSupported(context, subId) && isWorldMode(context, subId)) {
return true;
}
@@ -639,4 +636,21 @@
Arrays.asList(TextUtils.split(countriesListString.toLowerCase(), ","));
return unsupportedCountries.contains(country);
}
+
+ private static int[] getActiveSubscriptionIdList(Context context) {
+ final SubscriptionManager subscriptionManager = context.getSystemService(
+ SubscriptionManager.class);
+ final List<SubscriptionInfo> subInfoList =
+ subscriptionManager.getActiveSubscriptionInfoList();
+ if (subInfoList == null) {
+ return new int[0];
+ }
+ int[] activeSubIds = new int[subInfoList.size()];
+ int i = 0;
+ for (SubscriptionInfo subInfo : subInfoList) {
+ activeSubIds[i] = subInfo.getSubscriptionId();
+ i++;
+ }
+ return activeSubIds;
+ }
}
diff --git a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
index 89e2d5b8..72be4f4 100644
--- a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
@@ -29,6 +29,7 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.settings.R;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
/**
* Preference controller for "Preferred network mode"
@@ -113,48 +114,48 @@
private int getPreferredNetworkModeSummaryResId(int NetworkMode) {
switch (NetworkMode) {
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
return R.string.preferred_network_mode_tdscdma_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM:
return R.string.preferred_network_mode_tdscdma_gsm_summary;
- case TelephonyManager.NETWORK_MODE_WCDMA_PREF:
+ case TelephonyManagerConstants.NETWORK_MODE_WCDMA_PREF:
return R.string.preferred_network_mode_wcdma_perf_summary;
- case TelephonyManager.NETWORK_MODE_GSM_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY:
return R.string.preferred_network_mode_gsm_only_summary;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_WCDMA:
return R.string.preferred_network_mode_tdscdma_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_WCDMA_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_WCDMA_ONLY:
return R.string.preferred_network_mode_wcdma_only_summary;
- case TelephonyManager.NETWORK_MODE_GSM_UMTS:
+ case TelephonyManagerConstants.NETWORK_MODE_GSM_UMTS:
return R.string.preferred_network_mode_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_EVDO:
switch (mTelephonyManager.getLteOnCdmaMode()) {
case PhoneConstants.LTE_ON_CDMA_TRUE:
return R.string.preferred_network_mode_cdma_summary;
default:
return R.string.preferred_network_mode_cdma_evdo_summary;
}
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_CDMA_NO_EVDO:
return R.string.preferred_network_mode_cdma_only_summary;
- case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_EVDO_NO_CDMA:
return R.string.preferred_network_mode_evdo_only_summary;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA:
return R.string.preferred_network_mode_lte_tdscdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_ONLY:
return R.string.preferred_network_mode_lte_summary;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
return R.string.preferred_network_mode_lte_tdscdma_gsm_summary;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
return R.string.preferred_network_mode_lte_tdscdma_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA:
return R.string.preferred_network_mode_lte_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO:
return R.string.preferred_network_mode_lte_cdma_evdo_summary;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_ONLY:
return R.string.preferred_network_mode_tdscdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
return R.string.preferred_network_mode_lte_tdscdma_cdma_evdo_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
if (mTelephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
|| mIsGlobalCdma
|| MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
@@ -162,13 +163,13 @@
} else {
return R.string.preferred_network_mode_lte_summary;
}
- case TelephonyManager.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
return R.string.preferred_network_mode_tdscdma_cdma_evdo_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_GLOBAL:
+ case TelephonyManagerConstants.NETWORK_MODE_GLOBAL:
return R.string.preferred_network_mode_cdma_evdo_gsm_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
return R.string.preferred_network_mode_lte_tdscdma_wcdma_summary;
- case TelephonyManager.NETWORK_MODE_LTE_WCDMA:
+ case TelephonyManagerConstants.NETWORK_MODE_LTE_WCDMA:
return R.string.preferred_network_mode_lte_wcdma_summary;
default:
return R.string.preferred_network_mode_global_summary;
diff --git a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
index b999219..96ed771 100644
--- a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
@@ -28,7 +28,7 @@
@Override
protected SubscriptionInfo getDefaultSubscriptionInfo() {
- return mManager.getDefaultSmsSubscriptionInfo();
+ return mManager.getActiveSubscriptionInfo(getDefaultSubscriptionId());
}
@Override
diff --git a/src/com/android/settings/network/telephony/TelephonyConstants.java b/src/com/android/settings/network/telephony/TelephonyConstants.java
new file mode 100644
index 0000000..cfae572
--- /dev/null
+++ b/src/com/android/settings/network/telephony/TelephonyConstants.java
@@ -0,0 +1,139 @@
+/*
+ * 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.telephony;
+
+
+/**
+ * Contains hidden constants copied from the platform.
+ */
+public class TelephonyConstants {
+
+ /**
+ * Copied from {@link android.telephony.TelephonyManager}
+ */
+ public static class TelephonyManagerConstants {
+
+ // Network modes are in turn copied from RILConstants
+ // with one difference: NETWORK_MODE_CDMA is named NETWORK_MODE_CDMA_EVDO
+
+ /** GSM, WCDMA (WCDMA preferred) */
+ public static final int NETWORK_MODE_WCDMA_PREF = 0;
+
+ /** GSM only */
+ public static final int NETWORK_MODE_GSM_ONLY = 1;
+
+ /** WCDMA only */
+ public static final int NETWORK_MODE_WCDMA_ONLY = 2;
+
+ /** GSM, WCDMA (auto mode, according to PRL) */
+ public static final int NETWORK_MODE_GSM_UMTS = 3;
+
+ /** CDMA and EvDo (auto mode, according to PRL)
+ * this is NETWORK_MODE_CDMA in RILConstants.java
+ */
+ public static final int NETWORK_MODE_CDMA_EVDO = 4;
+
+ /** CDMA only */
+ public static final int NETWORK_MODE_CDMA_NO_EVDO = 5;
+
+ /** EvDo only */
+ public static final int NETWORK_MODE_EVDO_NO_CDMA = 6;
+
+ /** GSM, WCDMA, CDMA, and EvDo (auto mode, according to PRL) */
+ public static final int NETWORK_MODE_GLOBAL = 7;
+
+ /** LTE, CDMA and EvDo */
+ public static final int NETWORK_MODE_LTE_CDMA_EVDO = 8;
+
+ /** LTE, GSM and WCDMA */
+ public static final int NETWORK_MODE_LTE_GSM_WCDMA = 9;
+
+ /** LTE, CDMA, EvDo, GSM, and WCDMA */
+ public static final int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 10;
+
+ /** LTE only mode. */
+ public static final int NETWORK_MODE_LTE_ONLY = 11;
+
+ /** LTE and WCDMA */
+ public static final int NETWORK_MODE_LTE_WCDMA = 12;
+
+ /** TD-SCDMA only */
+ public static final int NETWORK_MODE_TDSCDMA_ONLY = 13;
+
+ /** TD-SCDMA and WCDMA */
+ public static final int NETWORK_MODE_TDSCDMA_WCDMA = 14;
+
+ /** LTE and TD-SCDMA*/
+ public static final int NETWORK_MODE_LTE_TDSCDMA = 15;
+
+ /** TD-SCDMA and GSM */
+ public static final int NETWORK_MODE_TDSCDMA_GSM = 16;
+
+ /** TD-SCDMA, GSM and LTE */
+ public static final int NETWORK_MODE_LTE_TDSCDMA_GSM = 17;
+
+ /** TD-SCDMA, GSM and WCDMA */
+ public static final int NETWORK_MODE_TDSCDMA_GSM_WCDMA = 18;
+
+ /** LTE, TD-SCDMA and WCDMA */
+ public static final int NETWORK_MODE_LTE_TDSCDMA_WCDMA = 19;
+
+ /** LTE, TD-SCDMA, GSM, and WCDMA */
+ public static final int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA = 20;
+
+ /** TD-SCDMA, CDMA, EVDO, GSM and WCDMA */
+ public static final int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 21;
+
+ /** LTE, TDCSDMA, CDMA, EVDO, GSM and WCDMA */
+ public static final int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 22;
+
+ /** NR 5G only mode */
+ public static final int NETWORK_MODE_NR_ONLY = 23;
+
+ /** NR 5G, LTE */
+ public static final int NETWORK_MODE_NR_LTE = 24;
+
+ /** NR 5G, LTE, CDMA and EvDo */
+ public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO = 25;
+
+ /** NR 5G, LTE, GSM and WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_GSM_WCDMA = 26;
+
+ /** NR 5G, LTE, CDMA, EvDo, GSM and WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = 27;
+
+ /** NR 5G, LTE and WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_WCDMA = 28;
+
+ /** NR 5G, LTE and TDSCDMA */
+ public static final int NETWORK_MODE_NR_LTE_TDSCDMA = 29;
+
+ /** NR 5G, LTE, TD-SCDMA and GSM */
+ public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM = 30;
+
+ /** NR 5G, LTE, TD-SCDMA, WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA = 31;
+
+ /** NR 5G, LTE, TD-SCDMA, GSM and WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = 32;
+
+ /** NR 5G, LTE, TD-SCDMA, CDMA, EVDO, GSM and WCDMA */
+ public static final int NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 33;
+ }
+
+
+}
diff --git a/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java b/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java
index 5f259f8..c988bf8 100644
--- a/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java
+++ b/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java
@@ -24,6 +24,7 @@
import androidx.preference.Preference;
import com.android.internal.telephony.Phone;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
/**
* Preference controller for "System Select"
@@ -54,7 +55,7 @@
Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
Phone.PREFERRED_NT_MODE);
listPreference.setEnabled(
- settingsNetworkMode != TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ settingsNetworkMode != TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
}
@Override
diff --git a/src/com/android/settings/panel/PanelSlicesAdapter.java b/src/com/android/settings/panel/PanelSlicesAdapter.java
index 60c434d..779c582 100644
--- a/src/com/android/settings/panel/PanelSlicesAdapter.java
+++ b/src/com/android/settings/panel/PanelSlicesAdapter.java
@@ -51,7 +51,7 @@
* Maximum number of slices allowed on the panel view.
*/
@VisibleForTesting
- static final int MAX_NUM_OF_SLICES = 5;
+ static final int MAX_NUM_OF_SLICES = 6;
private final List<LiveData<Slice>> mSliceLiveData;
private final int mMetricsCategory;
diff --git a/src/com/android/settings/security/SimLockPreferenceController.java b/src/com/android/settings/security/SimLockPreferenceController.java
index 3b23daa..ffc1d6b 100644
--- a/src/com/android/settings/security/SimLockPreferenceController.java
+++ b/src/com/android/settings/security/SimLockPreferenceController.java
@@ -77,7 +77,7 @@
*/
private boolean isSimReady() {
final List<SubscriptionInfo> subInfoList =
- mSubscriptionManager.getActiveSubscriptionInfoList(true);
+ mSubscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
final int simState = mTelephonyManager.getSimState(subInfo.getSimSlotIndex());
@@ -95,7 +95,7 @@
*/
private boolean isSimIccReady() {
final List<SubscriptionInfo> subInfoList =
- mSubscriptionManager.getActiveSubscriptionInfoList(true);
+ mSubscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java
index 0b7e652..ae36f35 100644
--- a/src/com/android/settings/sim/SimSelectNotification.java
+++ b/src/com/android/settings/sim/SimSelectNotification.java
@@ -103,7 +103,7 @@
SubscriptionManager subscriptionManager = ((SubscriptionManager) context.getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE));
- if (!subscriptionManager.isActiveSubId(subId)) {
+ if (!subscriptionManager.isActiveSubscriptionId(subId)) {
Log.w(TAG, "onEnableMmsDataRequest invalid sub ID " + subId);
return;
}
diff --git a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
index 659ddbe..eab50a6 100644
--- a/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
+++ b/src/com/android/settings/wifi/CellularFallbackPreferenceController.java
@@ -68,8 +68,7 @@
@VisibleForTesting
Resources getResourcesForSubId(int subscriptionId) {
- return SubscriptionManager.getResourcesForSubId(mContext, subscriptionId,
- false /* useRootLocale */);
+ return SubscriptionManager.getResourcesForSubId(mContext, subscriptionId);
}
private boolean avoidBadWifiCurrentSettings() {
diff --git a/src/com/android/settings/wifi/WifiSettings2.java b/src/com/android/settings/wifi/WifiSettings2.java
index a1f1ad9..5bedb70 100644
--- a/src/com/android/settings/wifi/WifiSettings2.java
+++ b/src/com/android/settings/wifi/WifiSettings2.java
@@ -564,6 +564,15 @@
if (preference instanceof LongPressWifiEntryPreference) {
final WifiEntry selectedEntry =
((LongPressWifiEntryPreference) preference).getWifiEntry();
+
+ if (selectedEntry.isSaved()) {
+ if (!selectedEntry.getWifiConfiguration().getNetworkSelectionStatus()
+ .getHasEverConnected()) {
+ launchConfigNewNetworkFragment(selectedEntry);
+ return true;
+ }
+ }
+
connect(selectedEntry, true /* editIfNoConfig */, true /* fullScreenEdit */);
} else if (preference == mAddWifiNetworkPreference) {
onAddNetworkPressed();
diff --git a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
index d180df7..c925e7b 100644
--- a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
+++ b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java
@@ -62,12 +62,6 @@
public class AddAppNetworksFragment extends InstrumentedFragment {
public static final String TAG = "AddAppNetworksFragment";
- // Security types of a requested or saved network.
- private static final String SECURITY_NO_PASSWORD = "nopass";
- private static final String SECURITY_WEP = "wep";
- private static final String SECURITY_WPA_PSK = "wpa";
- private static final String SECURITY_SAE = "sae";
-
// Possible result values in each item of the returned result list, which is used
// to inform the caller APP the processed result of each specified network.
@VisibleForTesting
@@ -269,25 +263,9 @@
}
}
- /**
- * Classify security type into following types:
- * 1. {@Code SECURITY_NO_PASSWORD}: No password network or OWE network.
- * 2. {@Code SECURITY_WEP}: Traditional WEP encryption network.
- * 3. {@Code SECURITY_WPA_PSK}: WPA/WPA2 preshare key type.
- * 4. {@Code SECURITY_SAE}: SAE type network.
- */
- private String getSecurityType(WifiConfiguration config) {
- if (config.allowedKeyManagement.get(KeyMgmt.SAE)) {
- return SECURITY_SAE;
- }
- if (config.allowedKeyManagement.get(KeyMgmt.OWE)) {
- return SECURITY_NO_PASSWORD;
- }
- if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK) || config.allowedKeyManagement.get(
- KeyMgmt.WPA2_PSK)) {
- return SECURITY_WPA_PSK;
- }
- return (config.wepKeys[0] == null) ? SECURITY_NO_PASSWORD : SECURITY_WEP;
+ private String getWepKey(WifiConfiguration config) {
+ return (config.wepTxKeyIndex >= 0 && config.wepTxKeyIndex < config.wepKeys.length)
+ ? config.wepKeys[config.wepTxKeyIndex] : null;
}
/**
@@ -306,41 +284,40 @@
boolean foundInSavedList;
int networkPositionInBundle = 0;
- for (WifiConfiguration specifiecConfig : mAllSpecifiedNetworksList) {
+ for (WifiConfiguration specifiedConfig : mAllSpecifiedNetworksList) {
foundInSavedList = false;
- final String displayedSsid = removeDoubleQuotes(specifiecConfig.SSID);
- final String ssidWithQuotation = addQuotationIfNeeded(specifiecConfig.SSID);
- final String securityType = getSecurityType(specifiecConfig);
+ final String displayedSsid = removeDoubleQuotes(specifiedConfig.SSID);
+ final String ssidWithQuotation = addQuotationIfNeeded(specifiedConfig.SSID);
+ final int authType = specifiedConfig.getAuthType();
for (WifiConfiguration privilegedWifiConfiguration : savedWifiConfigurations) {
- final String savedSecurityType = getSecurityType(privilegedWifiConfiguration);
-
// If SSID or security type is different, should be new network or need to be
// updated network.
if (!ssidWithQuotation.equals(privilegedWifiConfiguration.SSID)
- || !securityType.equals(savedSecurityType)) {
+ || authType != privilegedWifiConfiguration.getAuthType()) {
continue;
}
// If specified network and saved network have same security types, we'll check
// more information according to their security type to judge if they are same.
- switch (securityType) {
- case SECURITY_NO_PASSWORD:
+ switch (authType) {
+ case KeyMgmt.NONE:
+ final String wep = getWepKey(specifiedConfig);
+ final String savedWep = getWepKey(privilegedWifiConfiguration);
+ foundInSavedList = TextUtils.equals(wep, savedWep);
+ break;
+ case KeyMgmt.OWE:
foundInSavedList = true;
break;
- case SECURITY_WEP:
- if (specifiecConfig.wepKeys[0].equals(
- privilegedWifiConfiguration.wepKeys[0])) {
- foundInSavedList = true;
- }
- break;
- case SECURITY_WPA_PSK:
- case SECURITY_SAE:
- if (specifiecConfig.preSharedKey.equals(
+ case KeyMgmt.WPA_PSK:
+ case KeyMgmt.WPA2_PSK:
+ case KeyMgmt.SAE:
+ if (specifiedConfig.preSharedKey.equals(
privilegedWifiConfiguration.preSharedKey)) {
foundInSavedList = true;
}
break;
+ // TODO: Check how to judge enterprise type.
default:
break;
}
@@ -353,7 +330,7 @@
} else {
// Prepare to add to UI list to show to user
UiConfigurationItem uiConfigurationIcon = new UiConfigurationItem(displayedSsid,
- specifiecConfig, networkPositionInBundle);
+ specifiedConfig, networkPositionInBundle);
mUiToRequestedList.add(uiConfigurationIcon);
}
networkPositionInBundle++;
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 5f26e2d..ea34fce 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -639,6 +639,6 @@
@VisibleForTesting
Resources getResourcesForSubId() {
- return SubscriptionManager.getResourcesForSubId(getContext(), mSubId, false);
+ return SubscriptionManager.getResourcesForSubId(getContext(), mSubId);
}
}
diff --git a/tests/robotests/src/com/android/settings/LinkifyUtilsTest.java b/tests/robotests/src/com/android/settings/LinkifyUtilsTest.java
new file mode 100644
index 0000000..de06302
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/LinkifyUtilsTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.google.common.truth.Truth.assertThat;
+
+import android.text.Spannable;
+import android.text.style.ClickableSpan;
+import android.widget.TextView;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class LinkifyUtilsTest {
+ private static final String TEST_STRING = "to LINK_BEGINscanning settingsLINK_END.";
+ private static final String WRONG_STRING = "to scanning settingsLINK_END.";
+ private final LinkifyUtils.OnClickListener mClickListener = () -> { /* Do nothing */ };
+
+ private StringBuilder mSpanStringBuilder;
+ private StringBuilder mWrongSpanStringBuilder;
+ TextView mTextView;
+
+ @Before
+ public void setUp() throws Exception {
+ mSpanStringBuilder = new StringBuilder(TEST_STRING);
+ mWrongSpanStringBuilder = new StringBuilder(WRONG_STRING);
+ mTextView = new TextView(RuntimeEnvironment.application);
+ }
+
+ @Test
+ public void linkify_whenSpanStringCorrect_shouldReturnTrue() {
+ final boolean linkifyResult = LinkifyUtils.linkify(mTextView, mSpanStringBuilder,
+ mClickListener);
+
+ assertThat(linkifyResult).isTrue();
+ }
+
+ @Test
+ public void linkify_whenSpanStringWrong_shouldReturnFalse() {
+ final boolean linkifyResult = LinkifyUtils.linkify(mTextView, mWrongSpanStringBuilder,
+ mClickListener);
+
+ assertThat(linkifyResult).isFalse();
+ }
+
+ @Test
+ public void linkify_whenSpanStringCorrect_shouldContainClickableSpan() {
+ LinkifyUtils.linkify(mTextView, mSpanStringBuilder, mClickListener);
+ final Spannable spannableContent = (Spannable) mTextView.getText();
+ final int len = spannableContent.length();
+ final Object[] spans = spannableContent.getSpans(0, len, Object.class);
+
+ assertThat(spans[1] instanceof ClickableSpan).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/ManageExternalStorageDetailsTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/ManageExternalStorageDetailsTest.java
new file mode 100644
index 0000000..ed85c01
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/ManageExternalStorageDetailsTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.applications.appinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.app.AppOpsManager;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
+import com.android.settings.applications.AppStateManageExternalStorageBridge;
+import com.android.settings.testutils.shadow.ShadowUserManager;
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.HashMap;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowUserManager.class})
+public class ManageExternalStorageDetailsTest {
+
+ @Mock
+ private AppOpsManager mAppOpsManager;
+ @Mock
+ private SwitchPreference mSwitchPref;
+ @Mock
+ private MetricsFeatureProvider mMetricsFeatureProvider;
+ @Mock
+ private AppStateManageExternalStorageBridge mBridge;
+
+ private ManageExternalStorageDetails mFragment;
+
+ private final HashMap<String, Integer> mPkgToOpModeMap = new HashMap<>();
+ private final HashMap<Integer, Integer> mUidToOpModeMap = new HashMap<>();
+
+ @Before
+ public void setUp() {
+ // Reset the global trackers
+ mPkgToOpModeMap.clear();
+ mUidToOpModeMap.clear();
+
+ //Start the mockin'
+ MockitoAnnotations.initMocks(this);
+
+ mFragment = new ManageExternalStorageDetails();
+ ReflectionHelpers.setField(mFragment, "mAppOpsManager", mAppOpsManager);
+ ReflectionHelpers.setField(mFragment, "mSwitchPref", mSwitchPref);
+ ReflectionHelpers.setField(mFragment, "mBridge", mBridge);
+ ReflectionHelpers.setField(mFragment, "mMetricsFeatureProvider",
+ mMetricsFeatureProvider);
+
+ mockAppOpsOperations();
+ }
+
+ @Test
+ public void onPreferenceChange_enableManageExternalStorage_shouldTriggerAppOpsManager() {
+ // Inject mock package details
+ final int mockUid = 23333;
+ final String mockPkgName = "com.mock.pkg.1";
+ PackageInfo pkgInfo = mock(PackageInfo.class);
+ pkgInfo.applicationInfo = new ApplicationInfo();
+ pkgInfo.applicationInfo.uid = mockUid;
+
+ ReflectionHelpers.setField(mFragment, "mPackageInfo", pkgInfo);
+ ReflectionHelpers.setField(mFragment, "mPackageName", mockPkgName);
+
+ // Set the initial state to be disabled
+ injectPermissionState(false);
+
+ // Simulate a preference change
+ mFragment.onPreferenceChange(mSwitchPref, /* newValue */ true);
+
+ // Verify that mAppOpsManager was called to allow the app-op
+ verify(mAppOpsManager, times(1))
+ .setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
+ assertThat(mPkgToOpModeMap).containsExactly(mockPkgName, AppOpsManager.MODE_ALLOWED);
+ assertThat(mUidToOpModeMap).containsExactly(mockUid, AppOpsManager.MODE_ALLOWED);
+
+ // Verify the mSwitchPref was enabled
+ ArgumentCaptor<Boolean> acSetEnabled = ArgumentCaptor.forClass(Boolean.class);
+ verify(mSwitchPref, times(1)).setEnabled(acSetEnabled.capture());
+ assertThat(acSetEnabled.getAllValues()).containsExactly(true);
+
+ // Verify that mSwitchPref was toggled to on
+ ArgumentCaptor<Boolean> acSetChecked = ArgumentCaptor.forClass(Boolean.class);
+ verify(mSwitchPref, times(1)).setChecked(acSetChecked.capture());
+ assertThat(acSetChecked.getAllValues()).containsExactly(true);
+ }
+
+ @Test
+ public void onPreferenceChange_disableManageExternalStorage_shouldTriggerAppOpsManager() {
+ // Inject mock package details
+ final int mockUid = 24444;
+ final String mockPkgName = "com.mock.pkg.2";
+ PackageInfo pkgInfo = mock(PackageInfo.class);
+ pkgInfo.applicationInfo = new ApplicationInfo();
+ pkgInfo.applicationInfo.uid = mockUid;
+
+ ReflectionHelpers.setField(mFragment, "mPackageInfo", pkgInfo);
+ ReflectionHelpers.setField(mFragment, "mPackageName", mockPkgName);
+
+ // Set the initial state to be enabled
+ injectPermissionState(true);
+
+ // Simulate a preference change
+ mFragment.onPreferenceChange(mSwitchPref, /* newValue */ false);
+
+ // Verify that mAppOpsManager was called to deny the app-op
+ verify(mAppOpsManager, times(1))
+ .setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
+ assertThat(mPkgToOpModeMap).containsExactly(mockPkgName, AppOpsManager.MODE_ERRORED);
+ assertThat(mUidToOpModeMap).containsExactly(mockUid, AppOpsManager.MODE_ERRORED);
+
+ // Verify the mSwitchPref was enabled
+ ArgumentCaptor<Boolean> acSetEnabled = ArgumentCaptor.forClass(Boolean.class);
+ verify(mSwitchPref, times(1)).setEnabled(acSetEnabled.capture());
+ assertThat(acSetEnabled.getAllValues()).containsExactly(true);
+
+ // Verify that mSwitchPref was toggled to off
+ ArgumentCaptor<Boolean> acSetChecked = ArgumentCaptor.forClass(Boolean.class);
+ verify(mSwitchPref, times(1)).setChecked(acSetChecked.capture());
+ assertThat(acSetChecked.getAllValues()).containsExactly(false);
+ }
+
+ private void injectPermissionState(boolean enabled) {
+ PermissionState state = new PermissionState(null, null);
+ state.permissionDeclared = true;
+ state.appOpMode = enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED;
+ ReflectionHelpers.setField(mFragment, "mPermissionState", state);
+ }
+
+ private void mockAppOpsOperations() {
+ Answer<Void> answerSetMode = invocation -> {
+ int code = invocation.getArgument(0);
+ int uid = invocation.getArgument(1);
+ String packageName = invocation.getArgument(2);
+ int mode = invocation.getArgument(3);
+
+ if (code != AppOpsManager.OP_MANAGE_EXTERNAL_STORAGE) {
+ return null;
+ }
+
+ mPkgToOpModeMap.put(packageName, mode);
+ mUidToOpModeMap.put(uid, mode);
+
+ return null;
+ };
+
+ doAnswer(answerSetMode).when(mAppOpsManager)
+ .setMode(anyInt(), anyInt(), nullable(String.class), anyInt());
+
+ Answer<PermissionState> answerPermState = invocation -> {
+ String packageName = invocation.getArgument(0);
+ PermissionState res = new PermissionState(packageName, null);
+ res.permissionDeclared = false;
+
+ if (mPkgToOpModeMap.containsKey(packageName)) {
+ res.permissionDeclared = true;
+ res.appOpMode = mPkgToOpModeMap.get(packageName);
+ }
+ return res;
+ };
+
+ doAnswer(answerPermState).when(mBridge)
+ .getManageExternalStoragePermState(nullable(String.class), anyInt());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
index 6894d38..9aca92e 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageListTest.java
@@ -93,7 +93,7 @@
}
@Test
- public void resumePause_shouldListenUnlistenDataStateChange() {
+ public void resume_shouldListenDataStateChange() {
ReflectionHelpers.setField(
mDataUsageList, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
ReflectionHelpers.setField(
@@ -104,6 +104,17 @@
verify(mMobileDataEnabledListener).start(anyInt());
mDataUsageList.onPause();
+ }
+
+ @Test
+ public void pause_shouldUnlistenDataStateChange() {
+ ReflectionHelpers.setField(
+ mDataUsageList, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
+ ReflectionHelpers.setField(
+ mDataUsageList, "mPreferenceManager", mock(PreferenceManager.class));
+
+ mDataUsageList.onResume();
+ mDataUsageList.onPause();
verify(mMobileDataEnabledListener).stop();
}
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 693ed45..d0cb97a 100644
--- a/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
+++ b/tests/robotests/src/com/android/settings/development/compat/PlatformCompatDashboardTest.java
@@ -16,16 +16,23 @@
package com.android.settings.development.compat;
+import static com.android.internal.compat.OverrideAllowedState.ALLOWED;
+import static com.android.internal.compat.OverrideAllowedState.DISABLED_NOT_DEBUGGABLE;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
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.compat.Compatibility.ChangeConfig;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.RemoteException;
@@ -38,7 +45,9 @@
import com.android.internal.compat.CompatibilityChangeConfig;
import com.android.internal.compat.CompatibilityChangeInfo;
+import com.android.internal.compat.IOverrideValidator;
import com.android.internal.compat.IPlatformCompat;
+import com.android.internal.compat.OverrideAllowedState;
import com.android.settings.R;
import org.junit.Before;
@@ -66,6 +75,10 @@
private ApplicationInfo mApplicationInfo;
@Mock
private PreferenceManager mPreferenceManager;
+ @Mock
+ private IOverrideValidator mOverrideValidator;
+ @Mock
+ private PackageManager mPackageManager;
private Context mContext;
private CompatibilityChangeInfo[] mChanges;
@@ -81,7 +94,11 @@
mChanges[3] = new CompatibilityChangeInfo(4L, "Enabled_After_SDK_1_2", 1, false, "");
mChanges[4] = new CompatibilityChangeInfo(5L, "Enabled_After_SDK_2", 2, false, "");
when(mPlatformCompat.listAllChanges()).thenReturn(mChanges);
- mContext = RuntimeEnvironment.application;
+ when(mPlatformCompat.getOverrideValidator()).thenReturn(mOverrideValidator);
+ // By default, allow any change
+ when(mOverrideValidator.getOverrideAllowedState(anyLong(),anyString()))
+ .thenReturn(new OverrideAllowedState(ALLOWED, -1, -1));
+ mContext = spy(RuntimeEnvironment.application);
mPreferenceManager = new PreferenceManager(mContext);
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
mApplicationInfo.packageName = APP_NAME;
@@ -91,6 +108,7 @@
doReturn(mPlatformCompat).when(mDashboard).getPlatformCompat();
doReturn(mPreferenceScreen).when(mDashboard).getPreferenceScreen();
doReturn(mPreferenceManager).when(mDashboard).getPreferenceManager();
+ doReturn(mPackageManager).when(mContext).getPackageManager();
}
@Test
@@ -107,8 +125,10 @@
@Test
public void createAppPreference_targetSdkEquals1_summaryReturnsAppNameAndTargetSdk() {
mApplicationInfo.targetSdkVersion = 1;
+ Drawable icon = mock(Drawable.class);
+ when(mApplicationInfo.loadIcon(any(PackageManager.class))).thenReturn(icon);
- Preference appPreference = mDashboard.createAppPreference(any(Drawable.class));
+ Preference appPreference = mDashboard.createAppPreference(mApplicationInfo);
assertThat(appPreference.getSummary()).isEqualTo(APP_NAME + " SDK 1");
}
@@ -128,6 +148,7 @@
assertThat(enabledPreference.getSummary()).isEqualTo(mChanges[0].getName());
assertThat(enabledPreference instanceof SwitchPreference).isTrue();
assertThat(enabledSwitchPreference.isChecked()).isTrue();
+ assertThat(enabledSwitchPreference.isEnabled()).isTrue();
}
@Test
@@ -139,10 +160,32 @@
Preference disabledPreference = mDashboard.createPreferenceForChange(mContext,
disabledChange, config);
-
+
assertThat(disabledPreference.getSummary()).isEqualTo(mChanges[1].getName());
SwitchPreference disabledSwitchPreference = (SwitchPreference) disabledPreference;
assertThat(disabledSwitchPreference.isChecked()).isFalse();
+ assertThat(disabledSwitchPreference.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void createPreferenceForChange_cannotOverride_createDisabledEntry()
+ throws RemoteException {
+ CompatibilityChangeInfo enabledChange = mChanges[0];
+ CompatibilityChangeConfig config = new CompatibilityChangeConfig(
+ new ChangeConfig(new HashSet<Long>(Arrays.asList(enabledChange.getId())),
+ new HashSet<Long>()));
+ when(mOverrideValidator.getOverrideAllowedState(anyLong(),anyString()))
+ .thenReturn(new OverrideAllowedState(DISABLED_NOT_DEBUGGABLE, -1, -1));
+
+ Preference preference = mDashboard.createPreferenceForChange(mContext, enabledChange,
+ config);
+
+ SwitchPreference switchPreference = (SwitchPreference) preference;
+
+ assertThat(preference.getSummary()).isEqualTo(mChanges[0].getName());
+ assertThat(preference instanceof SwitchPreference).isTrue();
+ assertThat(switchPreference.isChecked()).isTrue();
+ assertThat(switchPreference.isEnabled()).isFalse();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
new file mode 100644
index 0000000..c76e234
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/BluetoothTetherPreferenceControllerTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.mock;
+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.ConnectivityManager;
+
+import androidx.lifecycle.Lifecycle;
+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;
+
+@RunWith(RobolectricTestRunner.class)
+public class BluetoothTetherPreferenceControllerTest {
+
+ @Mock
+ private ConnectivityManager mConnectivityManager;
+
+ private BluetoothTetherPreferenceController mController;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
+ mConnectivityManager);
+ when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
+ mController = new BluetoothTetherPreferenceController(mContext, mock(Lifecycle.class));
+ }
+
+ @Test
+ public void lifecycle_shouldRegisterReceiverOnStart() {
+ mController.onStart();
+
+ verify(mContext).registerReceiver(
+ eq(mController.mBluetoothChangeReceiver),
+ any());
+ }
+
+ @Test
+ public void lifecycle_shouldUnregisterReceiverOnStop() {
+ mController.onStart();
+ mController.onStop();
+
+ verify(mContext).unregisterReceiver(
+ eq(mController.mBluetoothChangeReceiver));
+ }
+
+ @Test
+ public void display_availableChangedCorrectly() {
+ when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
+ assertThat(mController.isAvailable()).isTrue();
+
+ when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
index 06f3893..9dcfa89 100644
--- a/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherEnablerTest.java
@@ -26,7 +26,6 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -83,10 +82,23 @@
mNetworkPolicyManager);
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
panReference.set(mBluetoothPan);
+ when(context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
+ .thenReturn(mSharedPreferences);
mEnabler = new TetherEnabler(context, new SwitchBarController(mSwitchBar), panReference);
}
@Test
+ public void lifecycle_onPause_unRegisterSharedPreferenceListener() {
+ mEnabler.onResume();
+ verify(mSharedPreferences).registerOnSharedPreferenceChangeListener(
+ eq(mEnabler));
+
+ mEnabler.onPause();
+ verify(mSharedPreferences).unregisterOnSharedPreferenceChangeListener(
+ eq(mEnabler));
+ }
+
+ @Test
public void lifecycle_onStart_setCheckedCorrectly() {
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[]{""});
@@ -122,29 +134,27 @@
@Test
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
+ when(mSharedPreferences.getBoolean(TetherEnabler.WIFI_TETHER_KEY, true)).thenReturn(true);
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
mEnabler.onSwitchToggled(true);
-
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
doReturn(false).when(mWifiManager).isWifiApEnabled();
mEnabler.onSwitchToggled(true);
-
- verify(mConnectivityManager, times(1))
- .startTethering(anyInt(), anyBoolean(), any(), any());
+ verify(mConnectivityManager).startTethering(anyInt(), anyBoolean(), any(), any());
}
@Test
public void onSwitchToggled_shouldStartUSBTetherWhenSelected() {
SharedPreferences preference = mock(SharedPreferences.class);
ReflectionHelpers.setField(mEnabler, "mSharedPreferences", preference);
- when(preference.getBoolean(mEnabler.WIFI_TETHER_KEY, true)).thenReturn(false);
- when(preference.getBoolean(mEnabler.USB_TETHER_KEY, false)).thenReturn(true);
- when(preference.getBoolean(mEnabler.BLUETOOTH_TETHER_KEY, true)).thenReturn(false);
+ when(preference.getBoolean(TetherEnabler.WIFI_TETHER_KEY, true)).thenReturn(false);
+ when(preference.getBoolean(TetherEnabler.USB_TETHER_KEY, false)).thenReturn(true);
+ when(preference.getBoolean(TetherEnabler.BLUETOOTH_TETHER_KEY, true)).thenReturn(false);
mEnabler.startTether();
- verify(mConnectivityManager, times(1))
- .startTethering(eq(ConnectivityManager.TETHERING_USB), anyBoolean(), any(), any());
+ verify(mConnectivityManager).startTethering(
+ eq(ConnectivityManager.TETHERING_USB), anyBoolean(), any(), any());
verify(mConnectivityManager, never())
.startTethering(eq(ConnectivityManager.TETHERING_WIFI), anyBoolean(), any(), any());
verify(mConnectivityManager, never()).startTethering(
@@ -158,11 +168,11 @@
when(adapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
- verify(adapter, times(1)).enable();
+ verify(adapter).enable();
when(adapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
- verify(mConnectivityManager, times(1)).startTethering(
+ verify(mConnectivityManager).startTethering(
eq(ConnectivityManager.TETHERING_BLUETOOTH), anyBoolean(), any(), any());
}
}
diff --git a/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
new file mode 100644
index 0000000..9127e4b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/UsbTetherPreferenceControllerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.mock;
+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.ConnectivityManager;
+
+import androidx.lifecycle.Lifecycle;
+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;
+
+@RunWith(RobolectricTestRunner.class)
+public class UsbTetherPreferenceControllerTest {
+
+ @Mock
+ private ConnectivityManager mConnectivityManager;
+
+ private Context mContext;
+ private UsbTetherPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
+ mConnectivityManager);
+ when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[] {""});
+ mController = new UsbTetherPreferenceController(mContext, mock(Lifecycle.class));
+ }
+
+ @Test
+ public void lifecycle_shouldRegisterReceiverOnStart() {
+ mController.onStart();
+
+ verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
+ }
+
+ @Test
+ public void lifecycle_shouldUnregisterReceiverOnStop() {
+ mController.onStart();
+ mController.onStop();
+
+ verify(mContext).unregisterReceiver(eq(mController.mUsbChangeReceiver));
+ }
+
+ @Test
+ public void display_availableChangedCorrectly() {
+ when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[] {""});
+ assertThat(mController.isAvailable()).isTrue();
+
+ when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
new file mode 100644
index 0000000..e42c477
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/WifiTetherDisablePreferenceControllerTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.WifiTetherDisablePreferenceController.PREF_KEY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+
+import androidx.lifecycle.Lifecycle;
+import androidx.preference.PreferenceScreen;
+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 WifiTetherDisablePreferenceControllerTest {
+
+ @Mock
+ private ConnectivityManager mConnectivityManager;
+ @Mock
+ private SharedPreferences mSharedPreferences;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ private SwitchPreference mPreference;
+ private Context mContext;
+ private WifiTetherDisablePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mPreference = spy(SwitchPreference.class);
+ when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
+ mConnectivityManager);
+ when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
+ when(mContext.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
+ .thenReturn(mSharedPreferences);
+ mController = new WifiTetherDisablePreferenceController(mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
+ ReflectionHelpers.setField(mController, "mPreference", mPreference);
+ when(mPreferenceScreen.findPreference(PREF_KEY)).thenReturn(mPreference);
+ }
+
+ @Test
+
+ public void lifecycle_shouldRegisterReceiverOnResume() {
+ mController.onResume();
+
+ verify(mSharedPreferences).registerOnSharedPreferenceChangeListener(eq(mController));
+ }
+
+ @Test
+ public void lifecycle_shouldUnregisterReceiverOnStop() {
+ mController.onResume();
+ mController.onPause();
+
+ verify(mSharedPreferences).unregisterOnSharedPreferenceChangeListener(eq(mController));
+ }
+
+ @Test
+ public void display_availableChangedCorrectly() {
+ when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
+ assertThat(mController.isAvailable()).isFalse();
+
+ when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"test"});
+ ReflectionHelpers.setField(mController, "mBluetoothTetherEnabled", false);
+ ReflectionHelpers.setField(mController, "mUSBTetherEnabled", false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void switch_shouldListenToUsbAndBluetooth() {
+ when(mSharedPreferences.getBoolean(
+ BluetoothTetherPreferenceController.PREF_KEY, false)).thenReturn(true);
+ mController.onSharedPreferenceChanged(mSharedPreferences,
+ BluetoothTetherPreferenceController.PREF_KEY);
+ verify(mPreference).setVisible(eq(true));
+
+ when(mSharedPreferences.getBoolean(
+ UsbTetherPreferenceController.PREF_KEY, false)).thenReturn(true);
+ mController.onSharedPreferenceChanged(mSharedPreferences,
+ UsbTetherPreferenceController.PREF_KEY);
+ assertThat(mController.shouldShow()).isTrue();
+
+ when(mSharedPreferences.getBoolean(
+ UsbTetherPreferenceController.PREF_KEY, false)).thenReturn(false);
+ mController.onSharedPreferenceChanged(mSharedPreferences,
+ UsbTetherPreferenceController.PREF_KEY);
+ assertThat(mController.shouldShow()).isTrue();
+
+ when(mSharedPreferences.getBoolean(
+ BluetoothTetherPreferenceController.PREF_KEY, false)).thenReturn(false);
+ when(mSharedPreferences.edit()).thenReturn(mock(SharedPreferences.Editor.class));
+ when(mPreference.isChecked()).thenReturn(true);
+ mController.onSharedPreferenceChanged(mSharedPreferences,
+ BluetoothTetherPreferenceController.PREF_KEY);
+ verify(mPreference).setChecked(eq(false));
+ verify(mPreference).setVisible(eq(false));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java
index f25ffa4..38223b8 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/DisabledSubscriptionControllerTest.java
@@ -69,32 +69,32 @@
@Test
public void displayPreference_subscriptionEnabled_categoryIsVisible() {
- doReturn(true).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.displayPreference(mScreen);
assertThat(mCategory.isVisible()).isTrue();
}
@Test
public void displayPreference_subscriptionDisabled_categoryIsNotVisible() {
- doReturn(false).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.displayPreference(mScreen);
assertThat(mCategory.isVisible()).isFalse();
}
@Test
public void onSubscriptionsChanged_subscriptionBecomesDisabled_categoryIsNotVisible() {
- doReturn(true).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.displayPreference(mScreen);
- doReturn(false).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.onSubscriptionsChanged();
assertThat(mCategory.isVisible()).isFalse();
}
@Test
public void onSubscriptionsChanged_subscriptionBecomesEnabled_categoryIsVisible() {
- doReturn(false).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.displayPreference(mScreen);
- doReturn(true).when(mSubscriptionManager).isActiveSubId(SUB_ID);
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(SUB_ID);
mController.onSubscriptionsChanged();
assertThat(mCategory.isVisible()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
index 35e1d1d..ea96e29 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceControllerTest.java
@@ -44,6 +44,7 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
@@ -171,12 +172,12 @@
public void updateState_updateByNetworkMode() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
- String.valueOf(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
assertThat(mPreference.getSummary()).isEqualTo("3G");
}
@@ -184,12 +185,12 @@
public void updateState_updateByNetworkMode_useDefaultValue() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
- String.valueOf(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
}
/**
@@ -392,27 +393,27 @@
@Test
public void onPreferenceChange_updateSuccess() {
doReturn(true).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
mController.onPreferenceChange(mPreference,
- String.valueOf(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isEqualTo(
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
}
@Test
public void onPreferenceChange_updateFail() {
doReturn(false).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
mController.onPreferenceChange(mPreference,
- String.valueOf(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isNotEqualTo(
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
}
@Test
@@ -421,24 +422,24 @@
doReturn(mPreference).when(screen).findPreference(KEY);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
mController.displayPreference(screen);
mController.updateState(mPreference);
mLifecycle.handleLifecycleEvent(ON_START);
assertThat(Integer.parseInt(mPreference.getValue())).isEqualTo(
- TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
assertThat(mPreference.getSummary()).isEqualTo("3G");
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_GSM_ONLY);
+ TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY);
final Uri uri = Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID);
mContext.getContentResolver().notifyChange(uri, null);
assertThat(Integer.parseInt(mPreference.getValue())).isEqualTo(
- TelephonyManager.NETWORK_MODE_GSM_ONLY);
+ TelephonyManagerConstants.NETWORK_MODE_GSM_ONLY);
assertThat(mPreference.getSummary()).isEqualTo("2G");
}
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
index 8c22d69..29f0f25 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
@@ -98,7 +98,6 @@
public void isDialogNeeded_disableSingleSim_returnFalse() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
- doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(1).when(mTelephonyManager).getActiveModemCount();
assertThat(mController.isDialogNeeded()).isFalse();
@@ -130,7 +129,6 @@
public void onPreferenceChange_singleSim_On_shouldEnableData() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
- doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(1).when(mTelephonyManager).getActiveModemCount();
mController.onPreferenceChange(mPreference, true);
@@ -142,7 +140,6 @@
public void onPreferenceChange_multiSim_On_shouldEnableData() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
- doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(2).when(mTelephonyManager).getActiveModemCount();
mController.onPreferenceChange(mPreference, true);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
index c66f75f..4cc8f36 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataSliceTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -76,7 +77,7 @@
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
- doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
doReturn(SUB_ID).when(mSubscriptionInfo).getSubscriptionId();
doReturn(new ArrayList<>(Arrays.asList(mSubscriptionInfo)))
.when(mSubscriptionManager).getSelectableSubscriptionInfoList();
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
index 04e3df8..ba839c6 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java
@@ -113,7 +113,7 @@
@Test
public void displayPreference_oneEnabledSubscription_switchBarNotHidden() {
- doReturn(true).when(mSubscriptionManager).isActiveSubId(mSubId);
+ doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(mSubId);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
@@ -121,7 +121,7 @@
@Test
public void displayPreference_oneDisabledSubscription_switchBarNotHidden() {
- doReturn(false).when(mSubscriptionManager).isActiveSubId(mSubId);
+ doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(mSubId);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
@@ -129,7 +129,7 @@
@Test
public void displayPreference_subscriptionEnabled_switchIsOn() {
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
assertThat(mSwitchBar.isChecked()).isTrue();
@@ -137,7 +137,7 @@
@Test
public void displayPreference_subscriptionDisabled_switchIsOff() {
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
assertThat(mSwitchBar.isChecked()).isFalse();
@@ -145,7 +145,7 @@
@Test
public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledCalledCorrectly() {
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
assertThat(mSwitchBar.isChecked()).isTrue();
@@ -157,7 +157,7 @@
public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledFailed() {
when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean()))
.thenReturn(false);
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
assertThat(mSwitchBar.isChecked()).isTrue();
@@ -168,7 +168,7 @@
@Test
public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() {
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isTrue();
assertThat(mSwitchBar.isChecked()).isFalse();
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
index bf1ee8a..da3a7c4 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
@@ -21,7 +21,6 @@
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -41,6 +40,7 @@
import android.telephony.TelephonyManager;
import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import org.junit.Before;
import org.junit.Test;
@@ -181,7 +181,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
}
@@ -198,14 +198,14 @@
@Test
public void getSearchableSubscriptionId_oneActive_returnValid() {
- when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID_1});
-
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo1));
assertThat(MobileNetworkUtils.getSearchableSubscriptionId(mContext)).isEqualTo(SUB_ID_1);
}
@Test
public void getSearchableSubscriptionId_nonActive_returnInvalid() {
- when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[0]);
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(new ArrayList<>());
assertThat(MobileNetworkUtils.getSearchableSubscriptionId(mContext))
.isEqualTo(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
@@ -255,7 +255,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
@@ -266,7 +266,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
@@ -277,7 +277,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
@@ -288,7 +288,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
@@ -299,7 +299,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
@@ -310,7 +310,7 @@
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
- TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA);
assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceControllerTest.java
index 9e13597..0d50e9e 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceControllerTest.java
@@ -36,6 +36,7 @@
import androidx.preference.ListPreference;
import com.android.settings.R;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import org.junit.Before;
import org.junit.Test;
@@ -127,12 +128,12 @@
public void updateState_updateByNetworkMode() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
mController.updateState(mPreference);
assertThat(mPreference.getValue()).isEqualTo(
- String.valueOf(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
assertThat(mPreference.getSummary()).isEqualTo(
mContext.getString(R.string.preferred_network_mode_tdscdma_gsm_wcdma_summary));
}
@@ -140,26 +141,26 @@
@Test
public void onPreferenceChange_updateSuccess() {
doReturn(true).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
mController.onPreferenceChange(mPreference,
- String.valueOf(TelephonyManager.NETWORK_MODE_LTE_TDSCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isEqualTo(
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
}
@Test
public void onPreferenceChange_updateFail() {
doReturn(false).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
mController.onPreferenceChange(mPreference,
- String.valueOf(TelephonyManager.NETWORK_MODE_LTE_TDSCDMA));
+ String.valueOf(TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA));
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isNotEqualTo(
- TelephonyManager.NETWORK_MODE_LTE_TDSCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_TDSCDMA);
}
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/TelephonyBasePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/TelephonyBasePreferenceControllerTest.java
index 886ea17..6ba2ffa 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/TelephonyBasePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/TelephonyBasePreferenceControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import org.junit.Before;
@@ -32,12 +33,16 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import java.util.Arrays;
+
@RunWith(RobolectricTestRunner.class)
public class TelephonyBasePreferenceControllerTest {
private static final int VALID_SUB_ID = 1;
@Mock
private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo;
private TestPreferenceController mPreferenceController;
private Context mContext;
@@ -49,7 +54,7 @@
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(SubscriptionManager.class))
.thenReturn(mSubscriptionManager);
- when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{});
+ when(mSubscriptionInfo.getSubscriptionId()).thenReturn(VALID_SUB_ID);
mPreferenceController = new TestPreferenceController(mContext, "prefKey");
}
@@ -62,8 +67,8 @@
@Test
public void isAvailable_noIdSetHoweverHasDefaultOne_returnTrue() {
- when(mSubscriptionManager.getActiveSubscriptionIdList())
- .thenReturn(new int[]{VALID_SUB_ID});
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
+ Arrays.asList(mSubscriptionInfo));
assertThat(mPreferenceController.isAvailable()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceControllerTest.java
index fee6099..1a7fd86 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceControllerTest.java
@@ -33,6 +33,8 @@
import androidx.preference.ListPreference;
import androidx.preference.PreferenceManager;
+import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -118,7 +120,7 @@
mTelephonyManager).getCdmaRoamingMode();
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
- TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ TelephonyManagerConstants.NETWORK_MODE_LTE_GSM_WCDMA);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java
index ebafceb..89be17a 100644
--- a/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/SimLockPreferenceControllerTest.java
@@ -21,7 +21,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -143,7 +142,7 @@
subscriptionInfoList.add(info);
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mTelephonyManager.hasIccCard()).thenReturn(true);
- when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true)))
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
.thenReturn(subscriptionInfoList);
}
@@ -152,7 +151,7 @@
SubscriptionInfo info = mock(SubscriptionInfo.class);
subscriptionInfoList.add(info);
when(mTelephonyManager.getSimState(anyInt())).thenReturn(SIM_STATE_READY);
- when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true)))
+ when(mSubscriptionManager.getActiveSubscriptionInfoList())
.thenReturn(subscriptionInfoList);
}
}
diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
index 9b53636..8f861eb 100644
--- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
+++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java
@@ -117,7 +117,7 @@
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false);
- when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true);
+ when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
when(mSubscriptionManager.getActiveSubscriptionInfo(mSubId)).thenReturn(mSubInfo);
when(mSubInfo.getDisplayName()).thenReturn(mFakeDisplayName);
when(mContext.getResources()).thenReturn(mResources);