Merge "Also all EXTRA_USER as input for ACTION_SHOW_ADMIN_SUPPORT_DETAILS"
diff --git a/Android.mk b/Android.mk
index f10b3ec..ca2ad4a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -32,7 +32,6 @@
com.google.android.material_material \
LOCAL_JAVA_LIBRARIES := \
- bouncycastle \
telephony-common \
ims-common
@@ -41,6 +40,7 @@
androidx.lifecycle_lifecycle-extensions \
guava \
jsr305 \
+ settings-contextual-card-protos-lite \
contextualcards \
settings-logtags \
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ec34514..109f2b9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -131,7 +131,7 @@
android:launchMode="singleTask">
</activity>
- <activity android:name=".mobilenetwork.MobileSettingsActivity"
+ <activity android:name=".network.telephony.MobileSettingsActivity"
android:label="@string/network_settings_title"
android:theme="@style/Theme.Settings.Home"
android:launchMode="singleTask">
@@ -1560,7 +1560,7 @@
android:enabled="false"
android:exported="true"
android:taskAffinity="com.android.wizard"
- android:theme="@style/SuwThemeGlif.Light"
+ android:theme="@style/SuwThemeGlif.DayNight"
android:label="@string/lock_screen_notifications_interstitial_title"
android:icon="@drawable/ic_suggested_notifications">
<intent-filter>
diff --git a/libs/contextualcards.aar b/libs/contextualcards.aar
index a44a26c..5e855fa 100755
--- a/libs/contextualcards.aar
+++ b/libs/contextualcards.aar
Binary files differ
diff --git a/protos/Android.bp b/protos/Android.bp
new file mode 100644
index 0000000..533dbca
--- /dev/null
+++ b/protos/Android.bp
@@ -0,0 +1,8 @@
+java_library_static {
+ name: "settings-contextual-card-protos-lite",
+ host_supported: true,
+ proto: {
+ type: "lite",
+ },
+ srcs: ["contextual_card_list.proto"],
+}
\ No newline at end of file
diff --git a/protos/contextual_card_list.proto b/protos/contextual_card_list.proto
new file mode 100644
index 0000000..89e6c13
--- /dev/null
+++ b/protos/contextual_card_list.proto
@@ -0,0 +1,19 @@
+syntax = "proto2";
+
+package com.android.settings.intelligence;
+option java_outer_classname = "ContextualCardProto";
+
+message ContextualCardList {
+ repeated ContextualCard card = 1;
+}
+
+message ContextualCard {
+ // Slice uri of the contextual card
+ optional string sliceUri = 1;
+
+ // {@link ContextualCardCategory}.
+ optional int32 category = 2;
+
+ // Name of the card. It should be identical in every app
+ optional string cardName = 3;
+}
\ No newline at end of file
diff --git a/res/layout/condition_tile.xml b/res/layout/condition_tile.xml
index 9fe83dc..dd87be5 100644
--- a/res/layout/condition_tile.xml
+++ b/res/layout/condition_tile.xml
@@ -15,7 +15,8 @@
limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -35,7 +36,7 @@
android:layout_marginTop="12dp"
android:layout_marginStart="14dp"
android:layout_marginEnd="24dp"
- android:tint="?android:attr/colorAccent" />
+ android:tint="?android:attr/colorAccent"/>
<TextView
android:id="@android:id/title"
@@ -43,7 +44,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/textColorPrimary" />
+ android:textColor="?android:attr/textColorPrimary"/>
</LinearLayout>
@@ -56,7 +57,7 @@
android:paddingBottom="8dp"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:alpha=".7"
- android:textColor="?android:attr/textColorPrimary" />
+ android:textColor="?android:attr/textColorPrimary"/>
<androidx.appcompat.widget.ButtonBarLayout
android:id="@+id/buttonBar"
@@ -76,20 +77,15 @@
android:alpha=".8"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorPrimary"
- style="?android:attr/buttonBarButtonStyle" />
+ style="?android:attr/buttonBarButtonStyle"/>
- <Button
- android:id="@+id/second_action"
+ <Space
android:layout_width="0dp"
android:layout_height="wrap_content"
- android:layout_weight="1"
- android:alpha=".8"
- android:textAlignment="viewStart"
- android:textColor="?android:attr/textColorPrimary"
- style="?android:attr/buttonBarButtonStyle" />
+ android:layout_weight="1"/>
</androidx.appcompat.widget.ButtonBarLayout>
- <include layout="@layout/horizontal_divider" />
+ <include layout="@layout/horizontal_divider"/>
</LinearLayout>
diff --git a/res/layout/lockscreen_remote_input.xml b/res/layout/lockscreen_remote_input.xml
index 68b35f9..4fa44ce 100644
--- a/res/layout/lockscreen_remote_input.xml
+++ b/res/layout/lockscreen_remote_input.xml
@@ -36,8 +36,8 @@
<ImageView
android:id="@+id/restricted_lock_icon_remote_input"
- android:layout_width="@*android:dimen/config_restricted_icon_size"
- android:layout_height="@*android:dimen/config_restricted_icon_size"
+ android:layout_width="@*android:dimen/config_restrictedIconSize"
+ android:layout_height="@*android:dimen/config_restrictedIconSize"
android:tint="?android:attr/colorAccent"
android:src="@*android:drawable/ic_info"
android:layout_marginEnd="?android:attr/dialogPreferredPadding"
diff --git a/res/layout/master_clear.xml b/res/layout/master_clear.xml
index 247eedc..8d4d623 100644
--- a/res/layout/master_clear.xml
+++ b/res/layout/master_clear.xml
@@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:theme="@style/SuwThemeGlifV3.Light"
+ android:theme="@style/SuwThemeGlifV3.DayNight"
android:icon="@drawable/ic_delete_accent"
app:suwHeaderText="@string/master_clear_title">
diff --git a/res/layout/master_clear_confirm.xml b/res/layout/master_clear_confirm.xml
index 146fb77..d513dbb 100644
--- a/res/layout/master_clear_confirm.xml
+++ b/res/layout/master_clear_confirm.xml
@@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:theme="@style/SuwThemeGlifV3.Light"
+ android:theme="@style/SuwThemeGlifV3.DayNight"
android:id="@+id/setup_wizard_layout"
android:icon="@drawable/ic_delete_accent"
app:suwHeaderText="@string/master_clear_confirm_title">
diff --git a/res/layout/restricted_dialog_singlechoice.xml b/res/layout/restricted_dialog_singlechoice.xml
index 48f62ce..a9984a8 100644
--- a/res/layout/restricted_dialog_singlechoice.xml
+++ b/res/layout/restricted_dialog_singlechoice.xml
@@ -37,8 +37,8 @@
android:ellipsize="marquee" />
<ImageView
android:id="@+id/restricted_lock_icon"
- android:layout_width="@*android:dimen/config_restricted_icon_size"
- android:layout_height="@*android:dimen/config_restricted_icon_size"
+ android:layout_width="@*android:dimen/config_restrictedIconSize"
+ android:layout_height="@*android:dimen/config_restrictedIconSize"
android:tint="?android:attr/colorAccent"
android:src="@*android:drawable/ic_info"
android:layout_marginLeft="@dimen/restricted_icon_padding"
diff --git a/res/layout/restricted_popup_menu_item.xml b/res/layout/restricted_popup_menu_item.xml
index 9f6da73..636e3f9 100644
--- a/res/layout/restricted_popup_menu_item.xml
+++ b/res/layout/restricted_popup_menu_item.xml
@@ -34,8 +34,8 @@
android:layout_alignParentLeft="true" />
<ImageView
android:id="@+id/restricted_icon"
- android:layout_width="@*android:dimen/config_restricted_icon_size"
- android:layout_height="@*android:dimen/config_restricted_icon_size"
+ android:layout_width="@*android:dimen/config_restrictedIconSize"
+ android:layout_height="@*android:dimen/config_restrictedIconSize"
android:scaleType="centerInside"
android:tint="?android:attr/colorAccent"
android:src="@*android:drawable/ic_info"
diff --git a/res/layout/restricted_radio_with_summary.xml b/res/layout/restricted_radio_with_summary.xml
index 4808460..5e7fcd8 100644
--- a/res/layout/restricted_radio_with_summary.xml
+++ b/res/layout/restricted_radio_with_summary.xml
@@ -41,7 +41,7 @@
android:ellipsize="marquee" />
<ImageView
android:id="@+id/restricted_icon"
- android:layout_width="@*android:dimen/config_restricted_icon_size"
+ android:layout_width="@*android:dimen/config_restrictedIconSize"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:tint="?android:attr/colorAccent"
diff --git a/res/layout/settings_homepage.xml b/res/layout/settings_homepage.xml
index 035e8b4..83c771c 100644
--- a/res/layout/settings_homepage.xml
+++ b/res/layout/settings_homepage.xml
@@ -19,4 +19,4 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_container"
android:layout_width="match_parent"
- android:layout_height="wrap_content" />
+ android:layout_height="match_parent" />
diff --git a/res/layout/settings_homepage_container.xml b/res/layout/settings_homepage_container.xml
index b35b4ce..ba8b48a 100644
--- a/res/layout/settings_homepage_container.xml
+++ b/res/layout/settings_homepage_container.xml
@@ -15,11 +15,34 @@
limitations under the License.
-->
-<RelativeLayout
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <androidx.coordinatorlayout.widget.CoordinatorLayout
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/homepage_appbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:elevation="0dp">
+
+ <include layout="@layout/search_bar"/>
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <FrameLayout
+ android:id="@id/main_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
+ </androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
@@ -28,25 +51,8 @@
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
- android:layout_alignParentBottom="true"
app:itemIconTint="@color/bottom_navigation_colors"
app:itemTextColor="@color/bottom_navigation_colors"
- app:menu="@menu/home_bottom_navigation" />
+ app:menu="@menu/home_bottom_navigation"/>
- <FrameLayout
- android:id="@id/main_content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_above="@+id/bottom_nav" />
-
- <com.google.android.material.floatingactionbutton.FloatingActionButton
- android:id="@+id/search_fab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_search_24dp"
- android:layout_margin="24dp"
- android:layout_above="@id/bottom_nav"
- android:layout_alignParentRight="true"
- app:backgroundTint="?android:attr/colorAccent"
- app:tint="@android:color/white" />
-</RelativeLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/res/layout/spinner_dropdown_restricted_item.xml b/res/layout/spinner_dropdown_restricted_item.xml
index be85966..d95e4be 100644
--- a/res/layout/spinner_dropdown_restricted_item.xml
+++ b/res/layout/spinner_dropdown_restricted_item.xml
@@ -26,8 +26,8 @@
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:ellipsize="marquee" />
<ImageView android:id="@+id/restricted_icon"
- android:layout_width="@*android:dimen/config_restricted_icon_size"
- android:layout_height="@*android:dimen/config_restricted_icon_size"
+ android:layout_width="@*android:dimen/config_restrictedIconSize"
+ android:layout_height="@*android:dimen/config_restrictedIconSize"
android:tint="?android:attr/colorAccent"
android:src="@*android:drawable/ic_info"
android:baselineAlignBottom="true"
diff --git a/res/values-night/themes.xml b/res/values-night/themes.xml
index eb0a749..725fe17 100644
--- a/res/values-night/themes.xml
+++ b/res/values-night/themes.xml
@@ -18,6 +18,7 @@
<resources>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">
+ <item name="colorPrimary">@*android:color/primary_device_default_settings</item>
<item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings</item>
</style>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index a11dd5f..2d2bfb7 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -267,7 +267,7 @@
<!-- Restricted icon in switch bar -->
<dimen name="restricted_icon_margin_end">16dp</dimen>
<!-- Restricted icon size in switch bar -->
- <dimen name="restricted_icon_size">@*android:dimen/config_restricted_icon_size</dimen>
+ <dimen name="restricted_icon_size">@*android:dimen/config_restrictedIconSize</dimen>
<!-- Display Size and Font Size preview screen -->
<dimen name="preview_pager_padding">8dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9843b80..9ed8417 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2768,6 +2768,10 @@
<string name="sim_change_succeeded">SIM PIN changed successfully</string>
<!-- SIM card lock settings screen, toast after not entering correct SIM PIN [CHAR LIMIT=40] -->
<string name="sim_lock_failed">Can\u2019t change SIM card lock state.\nPossibly incorrect PIN.</string>
+ <!-- SIM card lock settings screen, toast after disabling PIN failed from modem -->
+ <string name="sim_pin_disable_failed">Can\'t disable PIN.</string>
+ <!-- SIM card lock settings screen, toast after enabling PIN failed from modem -->
+ <string name="sim_pin_enable_failed">Can\'t enable PIN.</string>
<!-- SIM card lock settings screen, SIM PIN dialog button labels: [CHAR LIMIT=40] -->
<string name="sim_enter_ok">OK</string>
<!-- SIM card lock settings screen, SIM PIN dialog button labels: [CHAR LIMIT=40] -->
@@ -10088,7 +10092,7 @@
<string name="homepage_all_settings">All Settings</string>
<!-- Homepage bottom menu. Title for display personalized Settings [CHAR LIMIT=30] -->
- <string name="homepage_personal_settings">Your Settings</string>
+ <string name="homepage_personal_settings">Suggestions</string>
<!-- Setting Checkbox title whether to enable CBRS data. [CHAR LIMIT=40] -->
<string name="cbrs_data_switch">CBRS Data</string>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index df490f2..4050cb2 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -170,6 +170,9 @@
<item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
<item name="colorAccent">@*android:color/accent_device_default_light</item>
<item name="preferenceTheme">@style/PreferenceTheme</item>
+
+ <!-- action bar, needed for search bar icon tinting -->
+ <item name="android:actionBarTheme">@*android:style/ThemeOverlay.DeviceDefault.ActionBar.Accent</item>
</style>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">
diff --git a/res/values/themes_suw.xml b/res/values/themes_suw.xml
index f09b2b1..d66f917 100644
--- a/res/values/themes_suw.xml
+++ b/res/values/themes_suw.xml
@@ -17,7 +17,7 @@
<!-- SUW related themes -->
<resources>
- <style name="GlifTheme" parent="SuwThemeGlif">
+ <style name="GlifTheme" parent="SuwThemeGlif.DayNight">
<!-- For all AndroidX Alert Dialogs -->
<item name="alertDialogTheme">@style/ThemeOverlay.AlertDialog</item>
<item name="android:windowBackground">?android:attr/colorBackground</item>
@@ -55,7 +55,7 @@
<item name="*android:colorError">@color/glif_error_color</item>
</style>
- <style name="GlifV2Theme" parent="SuwThemeGlifV2">
+ <style name="GlifV2Theme" parent="SuwThemeGlifV2.DayNight">
<!-- For all AndroidX Alert Dialogs -->
<item name="alertDialogTheme">@style/GlifV2ThemeAlertDialog</item>
<item name="android:windowBackground">?android:attr/colorBackground</item>
@@ -93,7 +93,7 @@
<item name="*android:colorError">@color/glif_error_color</item>
</style>
- <style name="GlifV3Theme" parent="SuwThemeGlifV3">
+ <style name="GlifV3Theme" parent="SuwThemeGlifV3.DayNight">
<!-- For all AndroidX Alert Dialogs -->
<item name="alertDialogTheme">@style/GlifV2ThemeAlertDialog</item>
<item name="android:windowBackground">?android:attr/colorBackground</item>
diff --git a/res/xml/cdma_options.xml b/res/xml/cdma_options.xml
index 046d16f..9226588 100644
--- a/res/xml/cdma_options.xml
+++ b/res/xml/cdma_options.xml
@@ -17,15 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <com.android.settings.mobilenetwork.CdmaSystemSelectListPreference
- android:key="cdma_system_select_key"
- android:title="@string/cdma_system_select_title"
- android:summary="@string/cdma_system_select_summary"
- android:entries="@array/cdma_system_select_choices"
- android:entryValues="@array/cdma_system_select_values"
- android:dialogTitle="@string/cdma_system_select_dialogtitle" />
-
- <com.android.settings.mobilenetwork.CdmaSubscriptionListPreference
+ <com.android.settings.network.telephony.CdmaSubscriptionListPreference
android:key="cdma_subscription_key"
android:title="@string/cdma_subscription_title"
android:summary="@string/cdma_subscription_summary"
diff --git a/res/xml/gsm_umts_options.xml b/res/xml/gsm_umts_options.xml
index 6ca9ad6..f5439a4 100644
--- a/res/xml/gsm_umts_options.xml
+++ b/res/xml/gsm_umts_options.xml
@@ -17,7 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <com.android.settings.mobilenetwork.NetworkOperators
+ <com.android.settings.network.telephony.NetworkOperators
android:key="network_operators_category_key"
android:title="@string/network_operator_category"
android:persistent="false">
@@ -36,7 +36,7 @@
android:key="button_choose_network_key"
android:title="@string/choose_network_title"
android:fragment="com.android.phone.NetworkSelectSetting" />
- </com.android.settings.mobilenetwork.NetworkOperators>
+ </com.android.settings.network.telephony.NetworkOperators>
<!--We want separate APN setting from reset of settings because-->
<!--we want user to change it with caution.-->
diff --git a/res/xml/network_setting_fragment.xml b/res/xml/network_setting_fragment.xml
index c383ab6..255c498 100644
--- a/res/xml/network_setting_fragment.xml
+++ b/res/xml/network_setting_fragment.xml
@@ -16,6 +16,8 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="mobile_network_pref_screen"
+ android:title="@string/network_settings_title"
settings:initialExpandedChildrenCount="4">
<PreferenceScreen
@@ -23,10 +25,11 @@
android:title="@string/cdma_lte_data_service">
</PreferenceScreen>
- <com.android.settings.mobilenetwork.MobileDataPreference
+ <SwitchPreference
android:key="mobile_data_enable"
android:title="@string/mobile_data_settings_title"
- android:summary="@string/mobile_data_settings_summary"/>
+ android:summary="@string/mobile_data_settings_summary"
+ settings:controller="com.android.settings.network.telephony.MobileDataPreferenceController"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="button_roaming_key"
@@ -35,7 +38,7 @@
android:summaryOn="@string/roaming_enable"
android:summaryOff="@string/roaming_disable"/>
- <com.android.settings.mobilenetwork.DataUsagePreference
+ <com.android.settings.network.telephony.DataUsagePreference
android:key="data_usage_summary"
android:title="@string/data_usage_title" />
@@ -88,4 +91,13 @@
</PreferenceCategory>
+ <ListPreference
+ android:key="cdma_system_select_key"
+ android:title="@string/cdma_system_select_title"
+ android:summary="@string/cdma_system_select_summary"
+ android:entries="@array/cdma_system_select_choices"
+ android:entryValues="@array/cdma_system_select_values"
+ android:dialogTitle="@string/cdma_system_select_dialogtitle"
+ settings:controller="com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController"/>
+
</PreferenceScreen>
diff --git a/src/com/android/settings/IccLockSettings.java b/src/com/android/settings/IccLockSettings.java
index 437f42e..2cb4904 100644
--- a/src/com/android/settings/IccLockSettings.java
+++ b/src/com/android/settings/IccLockSettings.java
@@ -46,6 +46,7 @@
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.TelephonyIntents;
@@ -123,7 +124,7 @@
AsyncResult ar = (AsyncResult) msg.obj;
switch (msg.what) {
case MSG_ENABLE_ICC_PIN_COMPLETE:
- iccLockChanged(ar.exception == null, msg.arg1);
+ iccLockChanged(ar.exception == null, msg.arg1, ar.exception);
break;
case MSG_CHANGE_ICC_PIN_COMPLETE:
iccPinChanged(ar.exception == null, msg.arg1);
@@ -453,12 +454,25 @@
mPinToggle.setEnabled(false);
}
- private void iccLockChanged(boolean success, int attemptsRemaining) {
+ private void iccLockChanged(boolean success, int attemptsRemaining, Throwable exception) {
if (success) {
mPinToggle.setChecked(mToState);
} else {
- Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
- Toast.LENGTH_LONG).show();
+ if (exception instanceof CommandException) {
+ CommandException.Error err = ((CommandException)(exception)).getCommandError();
+ if (err == CommandException.Error.PASSWORD_INCORRECT) {
+ Toast.makeText(getContext(), getPinPasswordErrorMessage(attemptsRemaining),
+ Toast.LENGTH_LONG).show();
+ } else {
+ if (mToState) {
+ Toast.makeText(getContext(), mRes.getString
+ (R.string.sim_pin_enable_failed), Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(getContext(), mRes.getString
+ (R.string.sim_pin_disable_failed), Toast.LENGTH_LONG).show();
+ }
+ }
+ }
}
mPinToggle.setEnabled(true);
resetDialogState();
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index b47ecd7..18c83f4 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -35,6 +35,7 @@
import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncResult;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -1359,25 +1360,26 @@
imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
- imsVolteProvisionedSwitch.setEnabled(
- mImsManager.isVolteEnabledByPlatform(phone.getContext()));
+ imsVolteProvisionedSwitch.setEnabled(!Build.IS_USER
+ && mImsManager.isVolteEnabledByPlatform(phone.getContext()));
imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
- imsVtProvisionedSwitch.setEnabled(
- mImsManager.isVtEnabledByPlatform(phone.getContext()));
+ imsVtProvisionedSwitch.setEnabled(!Build.IS_USER
+ && mImsManager.isVtEnabledByPlatform(phone.getContext()));
imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
- imsWfcProvisionedSwitch.setEnabled(
- mImsManager.isWfcEnabledByPlatform(phone.getContext()));
+ imsWfcProvisionedSwitch.setEnabled(!Build.IS_USER
+ && mImsManager.isWfcEnabledByPlatform(phone.getContext()));
eabProvisionedSwitch.setOnCheckedChangeListener(null);
eabProvisionedSwitch.setChecked(isEabProvisioned());
eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
- eabProvisionedSwitch.setEnabled(isEabEnabledByPlatform(phone.getContext()));
+ eabProvisionedSwitch.setEnabled(!Build.IS_USER
+ && isEabEnabledByPlatform(phone.getContext()));
}
OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index a51d45f..9106fe4 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -299,15 +299,6 @@
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, toolbar);
setActionBar(toolbar);
-
- // Please forgive me for what I am about to do.
- //
- // Need to make the navigation icon non-clickable so that the entire card is clickable
- // and goes to the search UI. Also set the background to null so there's no ripple.
- View navView = toolbar.getNavigationView();
- navView.setClickable(false);
- navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
- navView.setBackground(null);
}
ActionBar actionBar = getActionBar();
diff --git a/src/com/android/settings/accessibility/AccessibilityServiceWarning.java b/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
index 26cb777..6360d42 100644
--- a/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
+++ b/src/com/android/settings/accessibility/AccessibilityServiceWarning.java
@@ -16,7 +16,7 @@
package com.android.settings.accessibility;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
@@ -72,7 +72,7 @@
Window window = ad.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
- params.privateFlags |= PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+ params.privateFlags |= SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
window.setAttributes(params);
ad.create();
ad.getButton(AlertDialog.BUTTON_POSITIVE).setOnTouchListener(filterTouchListener);
diff --git a/src/com/android/settings/applications/ProcessStatsBase.java b/src/com/android/settings/applications/ProcessStatsBase.java
index f7acef7..67fc4c1 100644
--- a/src/com/android/settings/applications/ProcessStatsBase.java
+++ b/src/com/android/settings/applications/ProcessStatsBase.java
@@ -30,6 +30,7 @@
import com.android.settings.applications.ProcStatsData.MemInfo;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.instrumentation.Instrumentable;
+import com.android.settingslib.widget.settingsspinner.SettingsSpinnerAdapter;
public abstract class ProcessStatsBase extends SettingsPreferenceFragment
implements OnItemSelectedListener {
@@ -104,9 +105,8 @@
super.onViewCreated(view, savedInstanceState);
mSpinnerHeader = (ViewGroup) setPinnedHeaderView(R.layout.apps_filter_spinner);
mFilterSpinner = (Spinner) mSpinnerHeader.findViewById(R.id.filter_spinner);
- mFilterAdapter = new ArrayAdapter<String>(mFilterSpinner.getContext(),
- R.layout.filter_spinner_item);
- mFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ mFilterAdapter = new SettingsSpinnerAdapter<String>(mFilterSpinner.getContext());
+
for (int i = 0; i < NUM_DURATIONS; i++) {
mFilterAdapter.add(getString(sDurationLabels[i]));
}
diff --git a/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
index 64af3c2..4c7dd81 100644
--- a/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceController.java
@@ -30,7 +30,8 @@
@Override
protected boolean hasAppCapability() {
- return DefaultBrowserPreferenceController.hasBrowserPreference(mPackageName, mContext);
+ return DefaultBrowserPreferenceController
+ .hasBrowserPreference(mPackageName, mContext, UserHandle.myUserId());
}
@Override
diff --git a/src/com/android/settings/applications/appinfo/DrawOverlayDetails.java b/src/com/android/settings/applications/appinfo/DrawOverlayDetails.java
index 6f2cf35..8405c61 100644
--- a/src/com/android/settings/applications/appinfo/DrawOverlayDetails.java
+++ b/src/com/android/settings/applications/appinfo/DrawOverlayDetails.java
@@ -15,7 +15,7 @@
*/
package com.android.settings.applications.appinfo;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.app.AppOpsManager;
import android.content.Context;
@@ -83,7 +83,7 @@
@Override
public void onResume() {
super.onResume();
- getActivity().getWindow().addPrivateFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ getActivity().getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
}
@Override
@@ -91,7 +91,7 @@
super.onPause();
Window window = getActivity().getWindow();
WindowManager.LayoutParams attrs = window.getAttributes();
- attrs.privateFlags &= ~PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+ attrs.privateFlags &= ~SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
window.setAttributes(attrs);
}
diff --git a/src/com/android/settings/applications/autofill/AutofillPickerTrampolineActivity.java b/src/com/android/settings/applications/autofill/AutofillPickerTrampolineActivity.java
index 9500fd5..ee58bfe 100644
--- a/src/com/android/settings/applications/autofill/AutofillPickerTrampolineActivity.java
+++ b/src/com/android/settings/applications/autofill/AutofillPickerTrampolineActivity.java
@@ -14,9 +14,9 @@
package com.android.settings.applications.autofill;
import android.app.Activity;
+import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
-import android.os.UserHandle;
import android.view.autofill.AutofillManager;
import com.android.settings.applications.defaultapps.DefaultAutofillPicker;
@@ -34,23 +34,23 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // First check if the current user's service already belongs to the app...
- final Intent intent = getIntent();
- final String packageName = intent.getData().getSchemeSpecificPart();
- final String currentService = DefaultAutofillPicker.getDefaultKey(
- this, UserHandle.myUserId());
- if (currentService != null && currentService.startsWith(packageName)) {
- // ...and succeed right away if it does.
- setResult(RESULT_OK);
+ final AutofillManager afm = getSystemService(AutofillManager.class);
+
+ // First check if the Autofill is available for the current user...
+ if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
+ // ... and fail right away if it is not.
+ setResult(RESULT_CANCELED);
finish();
return;
}
- // Then check if the Autofill is available for the current user...
- final AutofillManager afm = getSystemService(AutofillManager.class);
- if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
- // ... and fail right away if it is not.
- setResult(RESULT_CANCELED);
+ // Then check if the current user's service already belongs to the app...
+ final Intent intent = getIntent();
+ final String packageName = intent.getData().getSchemeSpecificPart();
+ final ComponentName currentService = afm.getAutofillServiceComponentName();
+ if (currentService != null && currentService.getPackageName().equals(packageName)) {
+ // ...and succeed right away if it does.
+ setResult(RESULT_OK);
finish();
return;
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultBrowserPicker.java b/src/com/android/settings/applications/defaultapps/DefaultBrowserPicker.java
index 626048d..cfaac3a 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultBrowserPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultBrowserPicker.java
@@ -62,7 +62,7 @@
for (ResolveInfo info : list) {
try {
- candidates.add(new DefaultAppInfo(context, mPm,
+ candidates.add(new DefaultAppInfo(context, mPm, mUserId,
mPm.getApplicationInfoAsUser(info.activityInfo.packageName, 0, mUserId)));
} catch (PackageManager.NameNotFoundException e) {
// Skip unknown packages.
diff --git a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
index 9e76ff5..24b4dcd 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceController.java
@@ -29,6 +29,7 @@
import android.util.IconDrawableFactory;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settingslib.applications.DefaultAppInfo;
@@ -75,8 +76,8 @@
try {
final String packageName = mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId);
Log.d(TAG, "Get default browser package: " + packageName);
- return new DefaultAppInfo(mContext, mPackageManager,
- mPackageManager.getApplicationInfo(packageName, 0));
+ return new DefaultAppInfo(mContext, mPackageManager, mUserId,
+ mPackageManager.getApplicationInfoAsUser(packageName, 0, mUserId));
} catch (PackageManager.NameNotFoundException e) {
return null;
}
@@ -143,7 +144,8 @@
return null;
}
- private Drawable getOnlyAppIcon() {
+ @VisibleForTesting
+ Drawable getOnlyAppIcon() {
final List<ResolveInfo> list = getCandidates(mPackageManager, mUserId);
if (list != null && list.size() == 1) {
final ResolveInfo info = list.get(0);
@@ -154,7 +156,7 @@
}
final ApplicationInfo appInfo;
try {
- appInfo = mPackageManager.getApplicationInfo(packageName, 0);
+ appInfo = mPackageManager.getApplicationInfoAsUser(packageName, 0, mUserId);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Error getting app info for " + packageName);
return null;
@@ -169,11 +171,11 @@
/**
* Whether or not the pkg contains browser capability
*/
- public static boolean hasBrowserPreference(String pkg, Context context) {
+ public static boolean hasBrowserPreference(String pkg, Context context, int userId) {
final Intent intent = new Intent(BROWSE_PROBE);
intent.setPackage(pkg);
- final List<ResolveInfo> resolveInfos =
- context.getPackageManager().queryIntentActivities(intent, 0);
+ final List<ResolveInfo> resolveInfos = context.getPackageManager()
+ .queryIntentActivitiesAsUser(intent, 0 /* flags */, userId);
return resolveInfos != null && resolveInfos.size() != 0;
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultEmergencyPicker.java b/src/com/android/settings/applications/defaultapps/DefaultEmergencyPicker.java
index f6f8a56..76e93cc 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultEmergencyPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultEmergencyPicker.java
@@ -58,7 +58,7 @@
final PackageInfo packageInfo =
mPm.getPackageInfo(info.activityInfo.packageName, 0);
final ApplicationInfo appInfo = packageInfo.applicationInfo;
- candidates.add(new DefaultAppInfo(context, mPm, appInfo));
+ candidates.add(new DefaultAppInfo(context, mPm, mUserId, appInfo));
// Get earliest installed system app.
if (isSystemApp(appInfo) && (bestMatch == null ||
bestMatch.firstInstallTime > packageInfo.firstInstallTime)) {
diff --git a/src/com/android/settings/applications/defaultapps/DefaultPhonePicker.java b/src/com/android/settings/applications/defaultapps/DefaultPhonePicker.java
index 0bda2ec..72f1cc5 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultPhonePicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultPhonePicker.java
@@ -58,7 +58,7 @@
final Context context = getContext();
for (String packageName : dialerPackages) {
try {
- candidates.add(new DefaultAppInfo(context, mPm,
+ candidates.add(new DefaultAppInfo(context, mPm, mUserId,
mPm.getApplicationInfoAsUser(packageName, 0, mUserId)));
} catch (PackageManager.NameNotFoundException e) {
// Skip unknown packages.
diff --git a/src/com/android/settings/applications/defaultapps/DefaultPhonePreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultPhonePreferenceController.java
index 95264b1..7b7755d 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultPhonePreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultPhonePreferenceController.java
@@ -59,7 +59,8 @@
@Override
protected DefaultAppInfo getDefaultAppInfo() {
try {
- return new DefaultAppInfo(mContext, mPackageManager, mPackageManager.getApplicationInfo(
+ return new DefaultAppInfo(mContext, mPackageManager, mUserId,
+ mPackageManager.getApplicationInfo(
DefaultDialerManager.getDefaultDialerApplication(mContext, mUserId), 0));
} catch (PackageManager.NameNotFoundException e) {
return null;
diff --git a/src/com/android/settings/applications/defaultapps/DefaultSmsPicker.java b/src/com/android/settings/applications/defaultapps/DefaultSmsPicker.java
index f8b1596..6d1e21d 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultSmsPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultSmsPicker.java
@@ -55,7 +55,7 @@
for (SmsApplication.SmsApplicationData smsApplicationData : smsApplications) {
try {
- candidates.add(new DefaultAppInfo(context, mPm,
+ candidates.add(new DefaultAppInfo(context, mPm, mUserId,
mPm.getApplicationInfoAsUser(smsApplicationData.mPackageName, 0, mUserId)));
} catch (PackageManager.NameNotFoundException e) {
// Skip unknown packages.
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEnrolling.java b/src/com/android/settings/biometrics/face/FaceEnrollEnrolling.java
index fccb39a..b09d0aa 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollEnrolling.java
@@ -171,6 +171,11 @@
// TODO: Update the actual animation
showError("Steps: " + steps + " Remaining: " + remaining);
+
+ // TODO: Have this match any animations that UX comes up with
+ if (remaining == 0) {
+ launchFinish(mToken);
+ }
}
@Override
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index d434637..385b5d9 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -261,10 +261,12 @@
cacheRemoveAllPrefs(preferenceGroup);
preferenceGroup.setTitle(titleId);
mDeviceListGroup = preferenceGroup;
- setFilter(filter);
if (addCachedDevices) {
+ // Don't show bonded devices when screen turned back on
+ setFilter(BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
addCachedDevices();
}
+ setFilter(filter);
preferenceGroup.setEnabled(true);
removeCachedPrefs(preferenceGroup);
}
diff --git a/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java b/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
index 476f105..5057abe 100644
--- a/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
+++ b/src/com/android/settings/connecteddevice/usb/UsbDefaultFragment.java
@@ -16,9 +16,14 @@
package com.android.settings.connecteddevice.usb;
+import static android.net.ConnectivityManager.TETHERING_USB;
+
import android.content.Context;
import android.graphics.drawable.Drawable;
+import android.hardware.usb.UsbManager;
+import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -40,11 +45,18 @@
public class UsbDefaultFragment extends RadioButtonPickerFragment {
@VisibleForTesting
UsbBackend mUsbBackend;
+ @VisibleForTesting
+ ConnectivityManager mConnectivityManager;
+ @VisibleForTesting
+ OnStartTetheringCallback mOnStartTetheringCallback = new OnStartTetheringCallback();
+ @VisibleForTesting
+ long mPreviousFunctions;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mUsbBackend = new UsbBackend(context);
+ mConnectivityManager = context.getSystemService(ConnectivityManager.class);
}
@Override
@@ -105,9 +117,37 @@
@Override
protected boolean setDefaultKey(String key) {
long functions = UsbBackend.usbFunctionsFromString(key);
+ mPreviousFunctions = mUsbBackend.getCurrentFunctions();
if (!Utils.isMonkeyRunning()) {
- mUsbBackend.setDefaultUsbFunctions(functions);
+ if (functions == UsbManager.FUNCTION_RNDIS) {
+ // We need to have entitlement check for usb tethering, so use API in
+ // ConnectivityManager.
+ mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
+ mOnStartTetheringCallback);
+ } else {
+ mUsbBackend.setDefaultUsbFunctions(functions);
+ }
+
}
return true;
}
+
+ @VisibleForTesting
+ final class OnStartTetheringCallback extends
+ ConnectivityManager.OnStartTetheringCallback {
+
+ @Override
+ public void onTetheringStarted() {
+ super.onTetheringStarted();
+ // Set default usb functions again to make internal data persistent
+ mUsbBackend.setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
+ }
+
+ @Override
+ public void onTetheringFailed() {
+ super.onTetheringFailed();
+ mUsbBackend.setDefaultUsbFunctions(mPreviousFunctions);
+ updateCandidates();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java b/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java
index e30237d..f74dc0f 100644
--- a/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java
+++ b/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java
@@ -16,10 +16,14 @@
package com.android.settings.connecteddevice.usb;
+import static android.net.ConnectivityManager.TETHERING_USB;
+
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
+import android.net.ConnectivityManager;
+import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -47,10 +51,18 @@
}
private PreferenceCategory mProfilesContainer;
+ private ConnectivityManager mConnectivityManager;
+ @VisibleForTesting
+ OnStartTetheringCallback mOnStartTetheringCallback;
+ @VisibleForTesting
+ long mPreviousFunction;
public UsbDetailsFunctionsController(Context context, UsbDetailsFragment fragment,
UsbBackend backend) {
super(context, fragment, backend);
+ mConnectivityManager = context.getSystemService(ConnectivityManager.class);
+ mOnStartTetheringCallback = new OnStartTetheringCallback();
+ mPreviousFunction = mUsbBackend.getCurrentFunctions();
}
@Override
@@ -97,9 +109,28 @@
@Override
public void onRadioButtonClicked(RadioButtonPreference preference) {
- long function = UsbBackend.usbFunctionsFromString(preference.getKey());
- if (function != mUsbBackend.getCurrentFunctions() && !Utils.isMonkeyRunning()) {
- mUsbBackend.setCurrentFunctions(function);
+ final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
+ final long previousFunction = mUsbBackend.getCurrentFunctions();
+ if (function != previousFunction && !Utils.isMonkeyRunning()) {
+ mPreviousFunction = previousFunction;
+
+ if (function == UsbManager.FUNCTION_RNDIS) {
+ //Update the UI in advance to make it looks smooth
+ final RadioButtonPreference prevPref =
+ (RadioButtonPreference) mProfilesContainer.findPreference(
+ UsbBackend.usbFunctionsToString(mPreviousFunction));
+ if (prevPref != null) {
+ prevPref.setChecked(false);
+ preference.setChecked(true);
+ }
+
+ // We need to have entitlement check for usb tethering, so use API in
+ // ConnectivityManager.
+ mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
+ mOnStartTetheringCallback);
+ } else {
+ mUsbBackend.setCurrentFunctions(function);
+ }
}
}
@@ -112,4 +143,15 @@
public String getPreferenceKey() {
return "usb_details_functions";
}
+
+ @VisibleForTesting
+ final class OnStartTetheringCallback extends
+ ConnectivityManager.OnStartTetheringCallback {
+
+ @Override
+ public void onTetheringFailed() {
+ super.onTetheringFailed();
+ mUsbBackend.setCurrentFunctions(mPreviousFunction);
+ }
+ }
}
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index 2d96fe9..45997f8 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -73,7 +73,8 @@
static final String KEY_SET_DATA_LIMIT = "set_data_limit";
private static final String KEY_DATA_LIMIT = "data_limit";
- private NetworkTemplate mNetworkTemplate;
+ @VisibleForTesting
+ NetworkTemplate mNetworkTemplate;
private Preference mBillingCycle;
private Preference mDataWarning;
private SwitchPreference mEnableDataWarning;
@@ -100,10 +101,15 @@
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- mDataUsageController = new DataUsageController(getContext());
+ final Context context = getContext();
+ mDataUsageController = new DataUsageController(context);
Bundle args = getArguments();
mNetworkTemplate = args.getParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE);
+ if (mNetworkTemplate == null) {
+ mNetworkTemplate = DataUsageUtils.getDefaultTemplate(context,
+ DataUsageUtils.getDefaultSubscriptionId(context));
+ }
mBillingCycle = findPreference(KEY_BILLING_CYCLE);
mEnableDataWarning = (SwitchPreference) findPreference(KEY_SET_DATA_WARNING);
diff --git a/src/com/android/settings/datausage/DataUsageUtils.java b/src/com/android/settings/datausage/DataUsageUtils.java
index 3001d2e..53565ac 100644
--- a/src/com/android/settings/datausage/DataUsageUtils.java
+++ b/src/com/android/settings/datausage/DataUsageUtils.java
@@ -172,8 +172,7 @@
return SystemProperties.get(TEST_RADIOS_PROP).contains("wifi");
}
- ConnectivityManager connectivityManager =
- context.getSystemService(ConnectivityManager.class);
+ final ConnectivityManager connectivityManager = ConnectivityManager.from(context);
return connectivityManager != null && connectivityManager.isNetworkSupported(TYPE_WIFI);
}
diff --git a/src/com/android/settings/development/WebViewAppPreferenceController.java b/src/com/android/settings/development/WebViewAppPreferenceController.java
index 74d6c10..37653cc 100644
--- a/src/com/android/settings/development/WebViewAppPreferenceController.java
+++ b/src/com/android/settings/development/WebViewAppPreferenceController.java
@@ -19,6 +19,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
@@ -66,7 +67,7 @@
@VisibleForTesting
DefaultAppInfo getDefaultAppInfo() {
final PackageInfo currentPackage = mWebViewUpdateServiceWrapper.getCurrentWebViewPackage();
- return new DefaultAppInfo(mContext, mPackageManager,
+ return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(),
currentPackage == null ? null : currentPackage.applicationInfo);
}
diff --git a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
index b17defd..48ec0e3 100644
--- a/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
+++ b/src/com/android/settings/deviceinfo/StorageWizardMigrateConfirm.java
@@ -85,9 +85,13 @@
FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
MetricsEvent.ACTION_STORAGE_MIGRATE_LATER);
- final Intent intent = new Intent(this, StorageWizardReady.class);
- intent.putExtra(EXTRA_MIGRATE_SKIP, true);
- startActivity(intent);
+ if (mDisk != null) {
+ final Intent intent = new Intent(this, StorageWizardReady.class);
+ intent.putExtra(EXTRA_MIGRATE_SKIP, true);
+ startActivity(intent);
+ } else {
+ finishAffinity();
+ }
}
@Override
diff --git a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
index 1a5152e..1dd3d98 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
@@ -43,6 +43,20 @@
super(context);
}
+ /**
+ * Converts a used storage amount to a formatted text.
+ *
+ * @param context Context
+ * @param usedBytes used bytes of storage
+ * @return a formatted text.
+ */
+ public static CharSequence convertUsedBytesToFormattedText(Context context, long usedBytes) {
+ final Formatter.BytesResult result = Formatter.formatBytes(context.getResources(),
+ usedBytes, 0);
+ return TextUtils.expandTemplate(context.getText(R.string.storage_size_large_alternate),
+ result.value, result.units);
+ }
+
@Override
public void displayPreference(PreferenceScreen screen) {
mSummary = (StorageSummaryDonutPreference) screen.findPreference("pref_summary");
@@ -53,11 +67,7 @@
public void updateState(Preference preference) {
super.updateState(preference);
StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference) preference;
- final Formatter.BytesResult result = Formatter.formatBytes(mContext.getResources(),
- mUsedBytes, 0);
- summary.setTitle(TextUtils.expandTemplate(
- mContext.getText(R.string.storage_size_large_alternate), result.value,
- result.units));
+ summary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
summary.setSummary(mContext.getString(R.string.storage_volume_total,
Formatter.formatShortFileSize(mContext, mTotalBytes)));
summary.setPercent(mUsedBytes, mTotalBytes);
@@ -83,6 +93,7 @@
/**
* Updates the state of the donut preference for the next update.
+ *
* @param used Total number of used bytes on the summarized volume.
* @param total Total number of bytes on the summarized volume.
*/
@@ -94,6 +105,7 @@
/**
* Updates the state of the donut preference for the next update using volume to summarize.
+ *
* @param volume VolumeInfo to use to populate the informayion.
*/
public void updateSizes(StorageVolumeProvider svp, VolumeInfo volume) {
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index f5010f9..5ca8fea 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -16,6 +16,7 @@
package com.android.settings.enterprise;
+import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
@@ -61,14 +62,18 @@
mActivity = activity;
}
- private @UserIdInt int getEnforcementAdminUserId() {
- if (mEnforcedAdmin.user == null) {
+ private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
+ if (admin.user == null) {
return UserHandle.USER_NULL;
} else {
- return mEnforcedAdmin.user.getIdentifier();
+ return admin.user.getIdentifier();
}
}
+ private @UserIdInt int getEnforcementAdminUserId() {
+ return getEnforcementAdminUserId(mEnforcedAdmin);
+ }
+
public AlertDialog.Builder prepareDialogBuilder(String restriction,
EnforcedAdmin enforcedAdmin) {
mEnforcedAdmin = enforcedAdmin;
@@ -170,18 +175,11 @@
return;
}
- final int userId;
- if (enforcedAdmin.user == null) {
- userId = UserHandle.USER_NULL;
- } else {
- userId = enforcedAdmin.user.getIdentifier();
- }
-
final DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(activity,
enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
- activity, userId)) {
+ activity, getEnforcementAdminUserId(enforcedAdmin))) {
enforcedAdmin.component = null;
} else {
if (enforcedAdmin.user == null) {
@@ -189,7 +187,8 @@
}
CharSequence supportMessage = null;
if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
- supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component, userId);
+ supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component,
+ getEnforcementAdminUserId(enforcedAdmin));
}
if (supportMessage != null) {
final TextView textView = root.findViewById(R.id.admin_support_msg);
diff --git a/src/com/android/settings/homepage/CardContentLoader.java b/src/com/android/settings/homepage/CardContentLoader.java
index 9980503..0b0d6c5 100644
--- a/src/com/android/settings/homepage/CardContentLoader.java
+++ b/src/com/android/settings/homepage/CardContentLoader.java
@@ -16,20 +16,30 @@
package com.android.settings.homepage;
+import static android.app.slice.Slice.HINT_ERROR;
+
+import static androidx.slice.widget.SliceLiveData.SUPPORTED_SPECS;
+
+import android.content.ContentProviderClient;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
+import android.net.Uri;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
+import androidx.slice.Slice;
import com.android.settings.homepage.deviceinfo.DataUsageSlice;
import com.android.settings.homepage.deviceinfo.DeviceInfoSlice;
+import com.android.settings.homepage.deviceinfo.StorageSlice;
import com.android.settingslib.utils.AsyncLoaderCompat;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
public class CardContentLoader extends AsyncLoaderCompat<List<ContextualCard>> {
private static final String TAG = "CardContentLoader";
@@ -58,18 +68,18 @@
try (Cursor cursor = getContextualCardsFromProvider()) {
if (cursor.getCount() == 0) {
result.addAll(createStaticCards());
- return result;
- }
- for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
- final ContextualCard card = new ContextualCard(cursor);
- if (card.isCustomCard()) {
- //TODO(b/114688391): Load and generate custom card,then add into list
- } else {
- result.add(card);
+ } else {
+ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
+ final ContextualCard card = new ContextualCard(cursor);
+ if (card.isCustomCard()) {
+ //TODO(b/114688391): Load and generate custom card,then add into list
+ } else {
+ result.add(card);
+ }
}
}
}
- return result;
+ return filter(result);
}
@VisibleForTesting
@@ -94,15 +104,15 @@
.build());
//TODO(b/115971399): Will change following values of SliceUri and Name
// after landing these slice cards.
- add(new ContextualCard.Builder()
- .setSliceUri("content://com.android.settings.slices/intent/battery_card")
- .setName(packageName + "/" + "battery_card")
- .setPackageName(packageName)
- .setRankingScore(rankingScore)
- .setAppVersion(appVersionCode)
- .setCardType(ContextualCard.CardType.SLICE)
- .setIsHalfWidth(true)
- .build());
+// add(new ContextualCard.Builder()
+// .setSliceUri("content://com.android.settings.slices/battery_card")
+// .setName(packageName + "/" + "battery_card")
+// .setPackageName(packageName)
+// .setRankingScore(rankingScore)
+// .setAppVersion(appVersionCode)
+// .setCardType(ContextualCard.CardType.SLICE)
+// .setIsHalfWidth(true)
+// .build());
add(new ContextualCard.Builder()
.setSliceUri(DeviceInfoSlice.DEVICE_INFO_CARD_URI.toString())
.setName(packageName + "/" + DeviceInfoSlice.PATH_DEVICE_INFO_CARD)
@@ -112,10 +122,54 @@
.setCardType(ContextualCard.CardType.SLICE)
.setIsHalfWidth(true)
.build());
+ add(new ContextualCard.Builder()
+ .setSliceUri(StorageSlice.STORAGE_CARD_URI.toString())
+ .setName(StorageSlice.PATH_STORAGE_CARD)
+ .setPackageName(packageName)
+ .setRankingScore(rankingScore)
+ .setAppVersion(appVersionCode)
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setIsHalfWidth(true)
+ .build());
}};
return result;
}
+ @VisibleForTesting
+ List<ContextualCard> filter(List<ContextualCard> candidates) {
+ return candidates.stream().filter(card -> isCardEligibleToDisplay(card)).collect(
+ Collectors.toList());
+ }
+
+ @VisibleForTesting
+ boolean isCardEligibleToDisplay(ContextualCard card) {
+ if (card.isCustomCard()) {
+ return true;
+ }
+
+ final Uri uri = card.getSliceUri();
+
+ if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
+ return false;
+ }
+
+ //check if the uri has a provider associated with.
+ final ContentProviderClient provider =
+ mContext.getContentResolver().acquireContentProviderClient(uri);
+ if (provider == null) {
+ return false;
+ }
+ //release contentProviderClient to prevent from memory leak.
+ provider.release();
+
+ final Slice slice = Slice.bindSlice(mContext, uri, SUPPORTED_SPECS);
+ if (slice == null || slice.hasHint(HINT_ERROR)) {
+ return false;
+ }
+
+ return true;
+ }
+
private long getAppVersionCode() {
try {
return mContext.getPackageManager().getPackageInfo(mContext.getPackageName(),
diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java
index 35b45a4..bfd8c4d 100644
--- a/src/com/android/settings/homepage/SettingsHomepageActivity.java
+++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java
@@ -20,6 +20,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
+import android.widget.Toolbar;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
@@ -32,7 +33,6 @@
import com.android.settings.overlay.FeatureFactory;
import com.google.android.material.bottomnavigation.BottomNavigationView;
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
public class SettingsHomepageActivity extends SettingsBaseActivity {
@@ -54,9 +54,9 @@
setContentView(R.layout.settings_homepage_container);
- final FloatingActionButton searchButton = findViewById(R.id.search_fab);
+ final Toolbar toolbar = findViewById(R.id.search_action_bar);
FeatureFactory.getFactory(this).getSearchFeatureProvider()
- .initSearchToolbar(this, searchButton);
+ .initSearchToolbar(this, toolbar);
final BottomNavigationView navigation = findViewById(R.id.bottom_nav);
navigation.setOnNavigationItemSelectedListener(item -> {
diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
index 44705c5..2dede95 100644
--- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
+++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java
@@ -21,14 +21,12 @@
import android.annotation.Nullable;
import com.android.settings.homepage.deviceinfo.DataUsageSlice;
+import com.android.settings.intelligence.ContextualCardProto.ContextualCard;
+import com.android.settings.intelligence.ContextualCardProto.ContextualCardList;
import com.android.settings.wifi.WifiSlice;
-import com.google.android.settings.intelligence.libs.contextualcards.ContextualCard;
import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;
-import java.util.ArrayList;
-import java.util.List;
-
/** Provides dynamic card for SettingsIntelligence. */
public class SettingsContextualCardProvider extends ContextualCardProvider {
@@ -36,21 +34,22 @@
@Override
@Nullable
- public List<ContextualCard> getContextualCards() {
- final List<ContextualCard> cards = new ArrayList<>();
+ public ContextualCardList getContextualCards() {
final ContextualCard wifiCard =
- new ContextualCard.Builder()
+ ContextualCard.newBuilder()
.setSliceUri(WifiSlice.WIFI_URI.toString())
- .setName(KEY_WIFI)
+ .setCardName(KEY_WIFI)
.build();
final ContextualCard dataUsageCard =
- new ContextualCard.Builder()
+ ContextualCard.newBuilder()
.setSliceUri(DataUsageSlice.DATA_USAGE_CARD_URI.toString())
- .setName(DataUsageSlice.PATH_DATA_USAGE_CARD)
+ .setCardName(DataUsageSlice.PATH_DATA_USAGE_CARD)
.build();
+ final ContextualCardList cards = ContextualCardList.newBuilder()
+ .addCard(wifiCard)
+ .addCard(dataUsageCard)
+ .build();
- cards.add(wifiCard);
- cards.add(dataUsageCard);
return cards;
}
}
diff --git a/src/com/android/settings/homepage/deviceinfo/StorageSlice.java b/src/com/android/settings/homepage/deviceinfo/StorageSlice.java
new file mode 100644
index 0000000..c9464e4
--- /dev/null
+++ b/src/com/android/settings/homepage/deviceinfo/StorageSlice.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.deviceinfo;
+
+import android.app.PendingIntent;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.storage.StorageManager;
+import android.text.format.Formatter;
+
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.slice.Slice;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.SubSettings;
+import com.android.settings.Utils;
+import com.android.settings.deviceinfo.StorageDashboardFragment;
+import com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController;
+import com.android.settings.slices.CustomSliceable;
+import com.android.settings.slices.SettingsSliceProvider;
+import com.android.settings.slices.SliceBuilderUtils;
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
+import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
+
+public class StorageSlice implements CustomSliceable {
+ private static final String TAG = "StorageSlice";
+
+ /**
+ * The path denotes the unique name of storage slicel
+ */
+ public static final String PATH_STORAGE_CARD = "storage_card";
+
+ /**
+ * Backing Uri for the storage slice.
+ */
+ public static final Uri STORAGE_CARD_URI = new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(SettingsSliceProvider.SLICE_AUTHORITY)
+ .appendPath(PATH_STORAGE_CARD)
+ .build();
+
+ private final Context mContext;
+
+ public StorageSlice(Context context) {
+ mContext = context;
+ }
+
+ @Override
+ public Uri getUri() {
+ return STORAGE_CARD_URI;
+ }
+
+ /**
+ * Return a storage slice bound to {@link #STORAGE_CARD_URI}
+ */
+ @Override
+ public Slice getSlice() {
+ final IconCompat icon = IconCompat.createWithResource(mContext,
+ R.drawable.ic_homepage_storage);
+ final String title = mContext.getString(R.string.storage_label);
+ final SliceAction primaryAction = new SliceAction(getPrimaryAction(), icon, title);
+ final PrivateStorageInfo info = getPrivateStorageInfo();
+ return new ListBuilder(mContext, STORAGE_CARD_URI, ListBuilder.INFINITY)
+ .setAccentColor(Utils.getColorAccentDefaultColor(mContext))
+ .setHeader(new ListBuilder.HeaderBuilder().setTitle(title))
+ .addRow(new ListBuilder.RowBuilder()
+ .setTitle(getStorageUsedText(info))
+ .setSubtitle(getStorageSummaryText(info))
+ .setPrimaryAction(primaryAction))
+ .build();
+ }
+
+ @Override
+ public Intent getIntent() {
+ final String screenTitle = mContext.getText(R.string.storage_label).toString();
+ final Uri contentUri = new Uri.Builder().appendPath(PATH_STORAGE_CARD).build();
+ return SliceBuilderUtils.buildSearchResultPageIntent(mContext,
+ StorageDashboardFragment.class.getName(), PATH_STORAGE_CARD, screenTitle,
+ MetricsProto.MetricsEvent.SLICE)
+ .setClassName(mContext.getPackageName(), SubSettings.class.getName())
+ .setData(contentUri);
+ }
+
+ private PendingIntent getPrimaryAction() {
+ final Intent intent = getIntent();
+ return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
+ }
+
+ @VisibleForTesting
+ PrivateStorageInfo getPrivateStorageInfo() {
+ final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
+ final StorageManagerVolumeProvider smvp = new StorageManagerVolumeProvider(storageManager);
+ return PrivateStorageInfo.getPrivateStorageInfo(smvp);
+ }
+
+ @VisibleForTesting
+ CharSequence getStorageUsedText(PrivateStorageInfo info) {
+ final long usedBytes = info.totalBytes - info.freeBytes;
+ return StorageSummaryDonutPreferenceController.convertUsedBytesToFormattedText(mContext,
+ usedBytes);
+ }
+
+ @VisibleForTesting
+ CharSequence getStorageSummaryText(PrivateStorageInfo info) {
+ return mContext.getString(R.string.storage_volume_total,
+ Formatter.formatShortFileSize(mContext, info.totalBytes));
+ }
+
+ @Override
+ public void onNotifyChange(Intent intent) {
+
+ }
+}
diff --git a/src/com/android/settings/homepage/slices/SliceContextualCardRenderer.java b/src/com/android/settings/homepage/slices/SliceContextualCardRenderer.java
index 705b990..5818e18 100644
--- a/src/com/android/settings/homepage/slices/SliceContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/slices/SliceContextualCardRenderer.java
@@ -82,6 +82,7 @@
return;
}
+ cardHolder.sliceView.setScrollable(false);
cardHolder.sliceView.setTag(uri);
//TODO(b/114009676): We will soon have a field to decide what slice mode we should set.
cardHolder.sliceView.setMode(SliceView.MODE_LARGE);
diff --git a/src/com/android/settings/inputmethod/KeyboardLayoutDialogFragment.java b/src/com/android/settings/inputmethod/KeyboardLayoutDialogFragment.java
index f515389..5618697 100644
--- a/src/com/android/settings/inputmethod/KeyboardLayoutDialogFragment.java
+++ b/src/com/android/settings/inputmethod/KeyboardLayoutDialogFragment.java
@@ -215,7 +215,7 @@
private void updateSwitchHintVisibility() {
AlertDialog dialog = (AlertDialog)getDialog();
if (dialog != null) {
- View customPanel = dialog.findViewById(com.android.internal.R.id.customPanel);
+ View customPanel = dialog.findViewById(R.id.customPanel);
customPanel.setVisibility(mAdapter.getCount() > 1 ? View.VISIBLE : View.GONE);
}
}
diff --git a/src/com/android/settings/mobilenetwork/CdmaSystemSelectListPreference.java b/src/com/android/settings/mobilenetwork/CdmaSystemSelectListPreference.java
deleted file mode 100644
index 3d3419f..0000000
--- a/src/com/android/settings/mobilenetwork/CdmaSystemSelectListPreference.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.mobilenetwork;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.provider.Settings;
-import android.telephony.TelephonyManager;
-import android.util.AttributeSet;
-import android.util.Log;
-
-import com.android.settingslib.utils.ThreadUtils;
-
-import androidx.preference.ListPreference;
-
-public class CdmaSystemSelectListPreference extends ListPreference {
-
- private static final String LOG_TAG = "CdmaRoamingListPref";
- private static final boolean DBG = false;
-
- private TelephonyManager mTelephonyManager;
- private MyHandler mHandler = new MyHandler();
-
- public CdmaSystemSelectListPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- mHandler = new MyHandler();
- mTelephonyManager = TelephonyManager.from(context);
- }
-
- public CdmaSystemSelectListPreference(Context context) {
- this(context, null);
- }
-
- /**
- * Sets the subscription id associated with this preference.
- *
- * @param subId the subscription id.
- */
- public void setSubscriptionId(int subId) {
- mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
- queryCdmaRoamingMode();
- }
-
- //TODO(b/114749736): Move this to preference controller
- protected void showDialog(Bundle state) {
- if (!mTelephonyManager.getEmergencyCallbackMode()) {
- // show Dialog
- }
- }
-
- //TODO(b/114749736): Move this to preference controller
- protected void onDialogClosed(boolean positiveResult) {
- if (positiveResult && (getValue() != null)) {
- int buttonCdmaRoamingMode = Integer.parseInt(getValue());
- int settingsCdmaRoamingMode = Settings.Global.getInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- TelephonyManager.CDMA_ROAMING_MODE_HOME);
- if (buttonCdmaRoamingMode != settingsCdmaRoamingMode) {
- int cdmaRoamingMode = TelephonyManager.CDMA_ROAMING_MODE_ANY;
- if (buttonCdmaRoamingMode != TelephonyManager.CDMA_ROAMING_MODE_ANY) {
- cdmaRoamingMode = TelephonyManager.CDMA_ROAMING_MODE_HOME;
- }
- //Set the Settings.Secure network mode
- Settings.Global.putInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- buttonCdmaRoamingMode);
- //Set the roaming preference mode
- setCdmaRoamingMode(cdmaRoamingMode);
- }
- } else {
- Log.d(LOG_TAG, String.format("onDialogClosed: positiveResult=%b value=%s -- do nothing",
- positiveResult, getValue()));
- }
- }
-
- private class MyHandler extends Handler {
-
- static final int MESSAGE_GET_ROAMING_PREFERENCE = 0;
- static final int MESSAGE_SET_ROAMING_PREFERENCE = 1;
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MESSAGE_GET_ROAMING_PREFERENCE:
- handleQueryCdmaRoamingPreference(msg);
- break;
-
- case MESSAGE_SET_ROAMING_PREFERENCE:
- handleSetCdmaRoamingPreference(msg);
- break;
- }
- }
-
- private void handleQueryCdmaRoamingPreference(Message msg) {
- int cdmaRoamingMode = msg.arg1;
-
- if (cdmaRoamingMode != TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT) {
- int settingsRoamingMode = Settings.Global.getInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- TelephonyManager.CDMA_ROAMING_MODE_HOME);
-
- //check that statusCdmaRoamingMode is from an accepted value
- if (cdmaRoamingMode == TelephonyManager.CDMA_ROAMING_MODE_HOME
- || cdmaRoamingMode == TelephonyManager.CDMA_ROAMING_MODE_ANY) {
- //check changes in statusCdmaRoamingMode and updates settingsRoamingMode
- if (cdmaRoamingMode != settingsRoamingMode) {
- settingsRoamingMode = cdmaRoamingMode;
- //changes the Settings.Secure accordingly to statusCdmaRoamingMode
- Settings.Global.putInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- settingsRoamingMode);
- }
- //changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode
- setValue(Integer.toString(cdmaRoamingMode));
- }
- else {
- if(DBG) Log.i(LOG_TAG, "reset cdma roaming mode to default" );
- resetCdmaRoamingModeToDefault();
- }
- }
- }
-
- private void handleSetCdmaRoamingPreference(Message msg) {
- boolean isSuccessed = (boolean) msg.obj;
-
- if (isSuccessed && (getValue() != null)) {
- int cdmaRoamingMode = Integer.parseInt(getValue());
- Settings.Global.putInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- cdmaRoamingMode );
- } else {
- queryCdmaRoamingMode();
- }
- }
-
- private void resetCdmaRoamingModeToDefault() {
- //set the mButtonCdmaRoam
- setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
- //set the Settings.System
- Settings.Global.putInt(
- getContext().getContentResolver(),
- Settings.Global.CDMA_ROAMING_MODE,
- TelephonyManager.CDMA_ROAMING_MODE_ANY);
- //Set the Status
- setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY);
- }
- }
-
- private void queryCdmaRoamingMode() {
- ThreadUtils.postOnBackgroundThread(() -> {
- Message msg = mHandler.obtainMessage(MyHandler.MESSAGE_GET_ROAMING_PREFERENCE);
- msg.arg1 = mTelephonyManager.getCdmaRoamingMode();
- msg.sendToTarget();
- });
- }
-
- private void setCdmaRoamingMode(int mode) {
- ThreadUtils.postOnBackgroundThread(() -> {
- Message msg = mHandler.obtainMessage(MyHandler.MESSAGE_SET_ROAMING_PREFERENCE);
- msg.obj = mTelephonyManager.setCdmaRoamingMode(mode);
- msg.sendToTarget();
- });
- }
-}
diff --git a/src/com/android/settings/mobilenetwork/MobileDataPreference.java b/src/com/android/settings/mobilenetwork/MobileDataPreference.java
deleted file mode 100644
index 37ce5a6..0000000
--- a/src/com/android/settings/mobilenetwork/MobileDataPreference.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.mobilenetwork;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.provider.Settings.Global;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.widget.Checkable;
-
-import androidx.preference.DialogPreference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.PreferenceViewHolder;
-
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-
-import java.util.List;
-
-/**
- * Customized Preference to enable / disable mobile data.
- * Basically copy of with com.android.settings.CellDataPreference.
- */
-public class MobileDataPreference extends DialogPreference implements
- DialogInterface.OnClickListener {
-
- private static final boolean DBG = false;
- private static final String TAG = "MobileDataPreference";
-
- public int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
- public boolean mChecked;
- // Whether to show the dialog to ask switching default data subscription.
- // Should be true only when a multi-sim phone only supports data connection on a single phone,
- // and user is enabling data on the non-default phone.
- public boolean mMultiSimDialog;
- private TelephonyManager mTelephonyManager;
- private SubscriptionManager mSubscriptionManager;
-
- public MobileDataPreference(Context context, AttributeSet attrs) {
- super(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
- }
-
- // Must be called to avoid binder leakage.
- void dispose() {
- mListener.setListener(false, mSubId, getContext());
- }
-
- @Override
- protected void onRestoreInstanceState(Parcelable s) {
- CellDataState state = (CellDataState) s;
- super.onRestoreInstanceState(state.getSuperState());
- mTelephonyManager = TelephonyManager.from(getContext());
- mChecked = state.mChecked;
- mMultiSimDialog = state.mMultiSimDialog;
- if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
- mSubId = state.mSubId;
- setKey(getKey() + mSubId);
- }
- notifyChanged();
- }
-
- @Override
- protected Parcelable onSaveInstanceState() {
- CellDataState state = new CellDataState(super.onSaveInstanceState());
- state.mChecked = mChecked;
- state.mMultiSimDialog = mMultiSimDialog;
- state.mSubId = mSubId;
- return state;
- }
-
- @Override
- public void onAttached() {
- super.onAttached();
- mListener.setListener(true, mSubId, getContext());
- }
-
- @Override
- protected void onPrepareForRemoval() {
- mListener.setListener(false, mSubId, getContext());
- super.onPrepareForRemoval();
- }
-
- /**
- * Initialize this preference with subId.
- */
- public void initialize(int subId) {
- if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
- throw new IllegalArgumentException("MobileDataPreference needs a SubscriptionInfo");
- }
- mSubscriptionManager = SubscriptionManager.from(getContext());
- mTelephonyManager = TelephonyManager.from(getContext());
- if (mSubId != subId) {
- mSubId = subId;
- setKey(getKey() + subId);
- }
- updateChecked();
- }
-
- private void updateChecked() {
- setChecked(mTelephonyManager.getDataEnabled(mSubId));
- }
-
- @Override
- public void performClick() {
- if (!isEnabled() || !SubscriptionManager.isValidSubscriptionId(mSubId)) {
- return;
- }
- final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
- mSubId);
- final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
- final boolean isMultiSim = (mTelephonyManager.getSimCount() > 1);
- final boolean isMultipleDataOnCapable =
- (mTelephonyManager.getNumberOfModemsWithSimultaneousDataConnections() > 1);
- final boolean isDefaultDataSubscription = (nextSir != null && currentSir != null
- && currentSir.getSubscriptionId() == nextSir.getSubscriptionId());
- if (mChecked) {
- if (!isMultiSim) {
- // disabling data; show confirmation dialog which eventually
- // calls setMobileDataEnabled() once user confirms.
- mMultiSimDialog = false;
- super.performClick();
- } else {
- // Don't show any dialog.
- setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */);
- }
- } else {
- if (isMultiSim && !isMultipleDataOnCapable && !isDefaultDataSubscription) {
- // enabling data and setting to default; show confirmation dialog which eventually
- // calls setMobileDataEnabled() once user confirms.
- mMultiSimDialog = true;
- super.performClick();
- } else {
- // Don't show any dialog.
- setMobileDataEnabled(true /* enabled */, false /* disableOtherSubscriptions */);
- }
- }
- }
-
- private void setMobileDataEnabled(boolean enabled, boolean disableOtherSubscriptions) {
- if (DBG) Log.d(TAG, "setMobileDataEnabled(" + enabled + "," + mSubId + ")");
-
- MetricsLogger.action(getContext(), MetricsEvent.ACTION_MOBILE_NETWORK_MOBILE_DATA_TOGGLE,
- enabled);
-
- mTelephonyManager.setDataEnabled(mSubId, enabled);
-
- if (disableOtherSubscriptions) {
- disableDataForOtherSubscriptions(mSubId);
- }
-
- setChecked(enabled);
- }
-
- private void setChecked(boolean checked) {
- if (mChecked == checked) return;
- mChecked = checked;
- notifyChanged();
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder holder) {
- super.onBindViewHolder(holder);
- View checkableView = holder.findViewById(com.android.internal.R.id.switch_widget);
- checkableView.setClickable(false);
- ((Checkable) checkableView).setChecked(mChecked);
- }
-
- //TODO(b/114749736): move it to preference controller
- protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
- if (mMultiSimDialog) {
- showMultiSimDialog(builder);
- } else {
- showDisableDialog(builder);
- }
- }
-
- private void showDisableDialog(AlertDialog.Builder builder) {
- builder.setTitle(null)
- .setMessage(R.string.data_usage_disable_mobile)
- .setPositiveButton(android.R.string.ok, this)
- .setNegativeButton(android.R.string.cancel, null);
- }
-
- private void showMultiSimDialog(AlertDialog.Builder builder) {
- final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
- final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
-
- final String previousName = (nextSir == null)
- ? getContext().getResources().getString(R.string.sim_selection_required_pref)
- : nextSir.getDisplayName().toString();
-
- builder.setTitle(R.string.sim_change_data_title);
- builder.setMessage(getContext().getString(R.string.sim_change_data_message,
- String.valueOf(currentSir != null ? currentSir.getDisplayName() : null),
- previousName));
-
- builder.setPositiveButton(android.R.string.ok, this);
- builder.setNegativeButton(R.string.cancel, null);
- }
-
- private void disableDataForOtherSubscriptions(int subId) {
- List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
- if (subInfoList != null) {
- for (SubscriptionInfo subInfo : subInfoList) {
- if (subInfo.getSubscriptionId() != subId) {
- mTelephonyManager.setDataEnabled(subInfo.getSubscriptionId(), false);
- }
- }
- }
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which != DialogInterface.BUTTON_POSITIVE) {
- return;
- }
- if (mMultiSimDialog) {
- mSubscriptionManager.setDefaultDataSubId(mSubId);
- setMobileDataEnabled(true /* enabled */, true /* disableOtherSubscriptions */);
- } else {
- // TODO: extend to modify policy enabled flag.
- setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */);
- }
- }
-
- private final DataStateListener mListener = new DataStateListener() {
- @Override
- public void onChange(boolean selfChange) {
- updateChecked();
- }
- };
-
- /**
- * Listener that listens mobile data state change.
- */
- public abstract static class DataStateListener extends ContentObserver {
- public DataStateListener() {
- super(new Handler(Looper.getMainLooper()));
- }
-
- /**
- * Set / Unset data state listening, specifying subId.
- */
- public void setListener(boolean listening, int subId, Context context) {
- if (listening) {
- Uri uri = Global.getUriFor(Global.MOBILE_DATA);
- if (TelephonyManager.getDefault().getSimCount() != 1) {
- uri = Global.getUriFor(Global.MOBILE_DATA + subId);
- }
- context.getContentResolver().registerContentObserver(uri, false, this);
- } else {
- context.getContentResolver().unregisterContentObserver(this);
- }
- }
- }
-
- /**
- * Class that represents state of mobile data state.
- * Used by onSaveInstanceState and onRestoreInstanceState.
- */
- public static class CellDataState extends BaseSavedState {
- public int mSubId;
- public boolean mChecked;
- public boolean mMultiSimDialog;
-
- public CellDataState(Parcelable base) {
- super(base);
- }
-
- public CellDataState(Parcel source) {
- super(source);
- mChecked = source.readByte() != 0;
- mMultiSimDialog = source.readByte() != 0;
- mSubId = source.readInt();
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeByte((byte) (mChecked ? 1 : 0));
- dest.writeByte((byte) (mMultiSimDialog ? 1 : 0));
- dest.writeInt(mSubId);
- }
-
- public static final Creator<CellDataState> CREATOR = new Creator<CellDataState>() {
- @Override
- public CellDataState createFromParcel(Parcel source) {
- return new CellDataState(source);
- }
-
- @Override
- public CellDataState[] newArray(int size) {
- return new CellDataState[size];
- }
- };
- }
-}
diff --git a/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java b/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java
deleted file mode 100644
index 2109375..0000000
--- a/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.mobilenetwork;
-
-import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.database.Cursor;
-import android.os.PersistableBundle;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.telecom.PhoneAccountHandle;
-import android.telecom.TelecomManager;
-import android.telephony.TelephonyManager;
-import android.telephony.euicc.EuiccManager;
-import android.telephony.ims.feature.ImsFeature;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.ims.ImsException;
-import com.android.ims.ImsManager;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class MobileNetworkUtils {
-
- private static final String TAG = "MobileNetworkUtils";
-
- // CID of the device.
- private static final String KEY_CID = "ro.boot.cid";
- // CIDs of devices which should not show anything related to eSIM.
- private static final String KEY_ESIM_CID_IGNORE = "ro.setupwizard.esim_cid_ignore";
- // System Property which is used to decide whether the default eSIM UI will be shown,
- // the default value is false.
- private static final String KEY_ENABLE_ESIM_UI_BY_DEFAULT =
- "esim.enable_esim_system_ui_by_default";
-
- /**
- * Returns if DPC APNs are enforced.
- */
- public static boolean isDpcApnEnforced(Context context) {
- try (Cursor enforceCursor = context.getContentResolver().query(ENFORCE_MANAGED_URI,
- null, null, null, null)) {
- if (enforceCursor == null || enforceCursor.getCount() != 1) {
- return false;
- }
- enforceCursor.moveToFirst();
- return enforceCursor.getInt(0) > 0;
- }
- }
-
- /**
- * Returns true if Wifi calling is enabled for at least one phone.
- */
- public static boolean isWifiCallingEnabled(Context context) {
- int phoneCount = TelephonyManager.from(context).getPhoneCount();
- for (int i = 0; i < phoneCount; i++) {
- if (isWifiCallingEnabled(context, i)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Returns true if Wifi calling is enabled for the specific phone with id {@code phoneId}.
- */
- public static boolean isWifiCallingEnabled(Context context, int phoneId) {
- final PhoneAccountHandle simCallManager =
- TelecomManager.from(context).getSimCallManager();
-
- boolean isWifiCallingEnabled;
- if (simCallManager != null) {
- //TODO(b/114749736): build intent to query wifi calling feature
- final Intent intent = null;
- PackageManager pm = context.getPackageManager();
- isWifiCallingEnabled = intent != null
- && !pm.queryIntentActivities(intent, 0 /* flags */).isEmpty();
- } else {
- ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
- isWifiCallingEnabled = imsMgr != null
- && imsMgr.isWfcEnabledByPlatform()
- && imsMgr.isWfcProvisionedOnDevice()
- && isImsServiceStateReady(imsMgr);
- }
-
- return isWifiCallingEnabled;
- }
-
- public static boolean isImsServiceStateReady(ImsManager imsMgr) {
- boolean isImsServiceStateReady = false;
-
- try {
- if (imsMgr != null && imsMgr.getImsServiceState() == ImsFeature.STATE_READY) {
- isImsServiceStateReady = true;
- }
- } catch (ImsException ex) {
- Log.e(TAG, "Exception when trying to get ImsServiceStatus: " + ex);
- }
-
- Log.d(TAG, "isImsServiceStateReady=" + isImsServiceStateReady);
- return isImsServiceStateReady;
- }
-
- /**
- * Whether to show the entry point to eUICC settings.
- *
- * <p>We show the entry point on any device which supports eUICC as long as either the eUICC
- * was ever provisioned (that is, at least one profile was ever downloaded onto it), or if
- * the user has enabled development mode.
- */
- public static boolean showEuiccSettings(Context context) {
- EuiccManager euiccManager =
- (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
- if (!euiccManager.isEnabled()) {
- return false;
- }
-
- final ContentResolver cr = context.getContentResolver();
-
- TelephonyManager tm =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- String currentCountry = tm.getNetworkCountryIso().toLowerCase();
- String supportedCountries =
- Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
- boolean inEsimSupportedCountries = false;
- if (TextUtils.isEmpty(currentCountry)) {
- inEsimSupportedCountries = true;
- } else if (!TextUtils.isEmpty(supportedCountries)) {
- List<String> supportedCountryList =
- Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ","));
- if (supportedCountryList.contains(currentCountry)) {
- inEsimSupportedCountries = true;
- }
- }
- final boolean esimIgnoredDevice =
- Arrays.asList(TextUtils.split(SystemProperties.get(KEY_ESIM_CID_IGNORE, ""), ","))
- .contains(SystemProperties.get(KEY_CID, null));
- final boolean enabledEsimUiByDefault =
- SystemProperties.getBoolean(KEY_ENABLE_ESIM_UI_BY_DEFAULT, true);
- final boolean euiccProvisioned =
- Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
- final boolean inDeveloperMode =
- Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
-
- return (inDeveloperMode || euiccProvisioned
- || (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries));
- }
-
- public static PersistableBundle getCarrierConfigBySubId(int mSubId) {
- //TODO(b/114749736): get carrier config from subId
- return new PersistableBundle();
- }
-}
\ No newline at end of file
diff --git a/src/com/android/settings/network/MobileNetworkPreferenceController.java b/src/com/android/settings/network/MobileNetworkPreferenceController.java
index c0e6e1c..bf5ca00 100644
--- a/src/com/android/settings/network/MobileNetworkPreferenceController.java
+++ b/src/com/android/settings/network/MobileNetworkPreferenceController.java
@@ -36,7 +36,7 @@
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.mobilenetwork.MobileSettingsActivity;
+import com.android.settings.network.telephony.MobileSettingsActivity;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.Utils;
diff --git a/src/com/android/settings/mobilenetwork/CdmaOptions.java b/src/com/android/settings/network/telephony/CdmaOptions.java
similarity index 93%
rename from src/com/android/settings/mobilenetwork/CdmaOptions.java
rename to src/com/android/settings/network/telephony/CdmaOptions.java
index fe50914..b927e25 100644
--- a/src/com/android/settings/mobilenetwork/CdmaOptions.java
+++ b/src/com/android/settings/network/telephony/CdmaOptions.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Intent;
import android.os.PersistableBundle;
@@ -43,7 +43,6 @@
private static final String LOG_TAG = "CdmaOptions";
private CarrierConfigManager mCarrierConfigManager;
- private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
private CdmaSubscriptionListPreference mButtonCdmaSubscription;
private RestrictedPreference mButtonAPNExpand;
private Preference mCategoryAPNExpand;
@@ -66,8 +65,6 @@
mCarrierConfigManager = new CarrierConfigManager(prefFragment.getContext());
// Initialize preferences.
- mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
- .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
@@ -91,9 +88,6 @@
boolean addCarrierSettings =
carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
- mPrefScreen.addPreference(mButtonCdmaSystemSelect);
- mButtonCdmaSystemSelect.setEnabled(true);
-
// Making no assumptions of whether they are added or removed at this point.
// Calling add or remove explicitly to make sure they are updated.
@@ -191,9 +185,7 @@
}
public void showDialog(Preference preference) {
- if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
- mButtonCdmaSystemSelect.showDialog(null);
- } else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
+ if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
mButtonCdmaSubscription.showDialog(null);
}
}
diff --git a/src/com/android/settings/mobilenetwork/CdmaSubscriptionListPreference.java b/src/com/android/settings/network/telephony/CdmaSubscriptionListPreference.java
similarity index 98%
rename from src/com/android/settings/mobilenetwork/CdmaSubscriptionListPreference.java
rename to src/com/android/settings/network/telephony/CdmaSubscriptionListPreference.java
index 4e3767a..559ba2d 100644
--- a/src/com/android/settings/mobilenetwork/CdmaSubscriptionListPreference.java
+++ b/src/com/android/settings/network/telephony/CdmaSubscriptionListPreference.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Context;
import android.os.Bundle;
diff --git a/src/com/android/settings/mobilenetwork/CellInfoUtil.java b/src/com/android/settings/network/telephony/CellInfoUtil.java
similarity index 98%
rename from src/com/android/settings/mobilenetwork/CellInfoUtil.java
rename to src/com/android/settings/network/telephony/CellInfoUtil.java
index bb5a8b4..ce382eb 100644
--- a/src/com/android/settings/mobilenetwork/CellInfoUtil.java
+++ b/src/com/android/settings/network/telephony/CellInfoUtil.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;
diff --git a/src/com/android/settings/mobilenetwork/DataUsagePreference.java b/src/com/android/settings/network/telephony/DataUsagePreference.java
similarity index 97%
rename from src/com/android/settings/mobilenetwork/DataUsagePreference.java
rename to src/com/android/settings/network/telephony/DataUsagePreference.java
index 05d26ed..437ba63 100644
--- a/src/com/android/settings/mobilenetwork/DataUsagePreference.java
+++ b/src/com/android/settings/network/telephony/DataUsagePreference.java
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkTemplate;
diff --git a/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelper.java b/src/com/android/settings/network/telephony/Enhanced4gLteSliceHelper.java
similarity index 99%
rename from src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelper.java
rename to src/com/android/settings/network/telephony/Enhanced4gLteSliceHelper.java
index 1ae8833..b198f92 100644
--- a/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelper.java
+++ b/src/com/android/settings/network/telephony/Enhanced4gLteSliceHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
diff --git a/src/com/android/settings/mobilenetwork/GsmUmtsOptions.java b/src/com/android/settings/network/telephony/GsmUmtsOptions.java
similarity index 98%
rename from src/com/android/settings/mobilenetwork/GsmUmtsOptions.java
rename to src/com/android/settings/network/telephony/GsmUmtsOptions.java
index 95f24fb..9b3df6b 100644
--- a/src/com/android/settings/mobilenetwork/GsmUmtsOptions.java
+++ b/src/com/android/settings/network/telephony/GsmUmtsOptions.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Context;
import android.content.Intent;
diff --git a/src/com/android/settings/network/telephony/MobileDataDialogFragment.java b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
new file mode 100644
index 0000000..be2da04
--- /dev/null
+++ b/src/com/android/settings/network/telephony/MobileDataDialogFragment.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+
+import androidx.appcompat.app.AlertDialog;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+
+/**
+ * Dialog Fragment to show dialog for "mobile data"
+ *
+ * 1. When user want to disable data in single sim case, show dialog to confirm
+ * 2. When user want to enable data in multiple sim case, show dialog to confirm to disable other
+ * sim
+ */
+public class MobileDataDialogFragment extends InstrumentedDialogFragment implements
+ DialogInterface.OnClickListener {
+
+ public static final int TYPE_DISABLE_DIALOG = 0;
+ public static final int TYPE_MULTI_SIM_DIALOG = 1;
+
+ private static final String ARG_DIALOG_TYPE = "dialog_type";
+ private static final String ARG_SUB_ID = "subId";
+
+ private SubscriptionManager mSubscriptionManager;
+ private int mType;
+ private int mSubId;
+
+ public static MobileDataDialogFragment newInstance(int type, int subId) {
+ final MobileDataDialogFragment dialogFragment = new MobileDataDialogFragment();
+
+ Bundle args = new Bundle();
+ args.putInt(ARG_DIALOG_TYPE, type);
+ args.putInt(ARG_SUB_ID, subId);
+ dialogFragment.setArguments(args);
+
+ return dialogFragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mSubscriptionManager = getContext().getSystemService(SubscriptionManager.class);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final Bundle bundle = getArguments();
+ final Context context = getContext();
+
+ mType = bundle.getInt(ARG_DIALOG_TYPE);
+ mSubId = bundle.getInt(ARG_SUB_ID);
+
+ switch (mType) {
+ case TYPE_DISABLE_DIALOG:
+ return new AlertDialog.Builder(context)
+ .setMessage(R.string.data_usage_disable_mobile)
+ .setPositiveButton(android.R.string.ok, this)
+ .setNegativeButton(android.R.string.cancel, null)
+ .create();
+ case TYPE_MULTI_SIM_DIALOG:
+ final SubscriptionInfo currentSubInfo =
+ mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
+ final SubscriptionInfo nextSubInfo =
+ mSubscriptionManager.getDefaultDataSubscriptionInfo();
+
+ final String previousName = (nextSubInfo == null)
+ ? getContext().getResources().getString(
+ R.string.sim_selection_required_pref)
+ : nextSubInfo.getDisplayName().toString();
+
+ return new AlertDialog.Builder(context)
+ .setTitle(R.string.sim_change_data_title)
+ .setMessage(context.getString(R.string.sim_change_data_message,
+ currentSubInfo != null
+ ? currentSubInfo.getDisplayName()
+ : "",
+ previousName))
+ .setPositiveButton(android.R.string.ok, this)
+ .setNegativeButton(R.string.cancel, null)
+ .create();
+ default:
+ throw new IllegalArgumentException("unknown type " + mType);
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO(b/114749736): add metric id for this fragment
+ return 0;
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ switch (mType) {
+ case TYPE_DISABLE_DIALOG:
+ MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, false /* enabled */,
+ false /* disableOtherSubscriptions */);
+ break;
+ case TYPE_MULTI_SIM_DIALOG:
+ mSubscriptionManager.setDefaultDataSubId(mSubId);
+ MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, true /* enabled */,
+ true /* disableOtherSubscriptions */);
+ break;
+ default:
+ throw new IllegalArgumentException("unknown type " + mType);
+ }
+ }
+
+}
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
new file mode 100644
index 0000000..6958a11
--- /dev/null
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.fragment.app.FragmentManager;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Preference controller for "Mobile data"
+ */
+public class MobileDataPreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnStart, OnStop {
+
+ private static final String DIALOG_TAG = "MobileDataDialog";
+
+ private SwitchPreference mPreference;
+ private TelephonyManager mTelephonyManager;
+ private SubscriptionManager mSubscriptionManager;
+ private DataContentObserver mDataContentObserver;
+ private FragmentManager mFragmentManager;
+ private int mSubId;
+ @VisibleForTesting
+ int mDialogType;
+ @VisibleForTesting
+ boolean mNeedDialog;
+
+ public MobileDataPreferenceController(Context context, String key) {
+ super(context, key);
+ mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
+ mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onStart() {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mDataContentObserver.register(mContext, mSubId);
+ }
+ }
+
+ @Override
+ public void onStop() {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mDataContentObserver.unRegister(mContext);
+ }
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ if (mNeedDialog) {
+ showDialog(mDialogType);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ mNeedDialog = isDialogNeeded();
+
+ if (!mNeedDialog) {
+ // Update data directly if we don't need dialog
+ MobileNetworkUtils.setMobileDataEnabled(mContext, mSubId, isChecked, false);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mTelephonyManager.isDataEnabled();
+ }
+
+ public void init(FragmentManager fragmentManager, int subId) {
+ mFragmentManager = fragmentManager;
+ mSubId = subId;
+ mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+ }
+
+ @VisibleForTesting
+ boolean isDialogNeeded() {
+ final boolean enableData = !mTelephonyManager.isDataEnabled();
+ final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
+ mSubId);
+ final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
+ final boolean isMultiSim = (mTelephonyManager.getSimCount() > 1);
+ final boolean isMultipleDataOnCapable =
+ (mTelephonyManager.getNumberOfModemsWithSimultaneousDataConnections() > 1);
+ final boolean isDefaultDataSubscription = (nextSir != null && currentSir != null
+ && currentSir.getSubscriptionId() == nextSir.getSubscriptionId());
+ if (enableData) {
+ if (isMultiSim && !isMultipleDataOnCapable && !isDefaultDataSubscription) {
+ mDialogType = MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG;
+ return true;
+ }
+ } else {
+ if (!isMultiSim) {
+ mDialogType = MobileDataDialogFragment.TYPE_DISABLE_DIALOG;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private void showDialog(int type) {
+ final MobileDataDialogFragment dialogFragment = MobileDataDialogFragment.newInstance(type,
+ mSubId);
+ dialogFragment.show(mFragmentManager, DIALOG_TAG);
+ }
+
+ /**
+ * Listener that listens mobile data state change.
+ */
+ public class DataContentObserver extends ContentObserver {
+
+ public DataContentObserver(Handler handler) {
+ super(handler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ updateState(mPreference);
+ }
+
+ public void register(Context context, int subId) {
+ Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
+ if (TelephonyManager.getDefault().getSimCount() != 1) {
+ uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
+ }
+ context.getContentResolver().registerContentObserver(uri, false, this);
+
+ }
+
+ public void unRegister(Context context) {
+ context.getContentResolver().unregisterContentObserver(this);
+ }
+ }
+}
diff --git a/src/com/android/settings/mobilenetwork/MobileNetworkFragment.java b/src/com/android/settings/network/telephony/MobileNetworkFragment.java
similarity index 97%
rename from src/com/android/settings/mobilenetwork/MobileNetworkFragment.java
rename to src/com/android/settings/network/telephony/MobileNetworkFragment.java
index d8df8fa..3977cdd 100644
--- a/src/com/android/settings/mobilenetwork/MobileNetworkFragment.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkFragment.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
@@ -34,6 +34,7 @@
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -48,6 +49,14 @@
import android.util.Log;
import android.view.MenuItem;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.internal.logging.MetricsLogger;
@@ -57,23 +66,17 @@
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.search.SearchIndexable;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import androidx.fragment.app.FragmentActivity;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MobileNetworkFragment extends DashboardFragment implements
Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener {
@@ -156,9 +159,10 @@
private Preference mWiFiCallingPref;
private SwitchPreference mVideoCallingPref;
private NetworkSelectListPreference mButtonNetworkSelect;
- private MobileDataPreference mMobileDataPref;
private DataUsagePreference mDataUsagePref;
+ private CdmaSystemSelectPreferenceController mCdmaSystemSelectPreferenceController;
+
private static final String iface = "rmnet0"; //TODO: this will go away
private List<SubscriptionInfo> mActiveSubInfos;
@@ -238,6 +242,9 @@
*/
@Override
public boolean onPreferenceTreeClick(Preference preference) {
+ if (super.onPreferenceTreeClick(preference)) {
+ return true;
+ }
sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
/** TODO: Refactor and get rid of the if's using subclasses */
@@ -298,7 +305,7 @@
startActivity(intent);
return true;
} else if (preference == mWiFiCallingPref || preference == mVideoCallingPref
- || preference == mMobileDataPref || preference == mDataUsagePref) {
+ || preference == mDataUsagePref) {
return false;
} else {
// if the button is anything but the simple toggle preference,
@@ -384,6 +391,18 @@
}
@Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID,
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
+
+ mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
+ mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
+ }
+
+ @Override
public void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate:+");
super.onCreate(icicle);
@@ -407,7 +426,6 @@
mCallingCategory = (PreferenceCategory) findPreference(CATEGORY_CALLING_KEY);
mWiFiCallingPref = findPreference(BUTTON_WIFI_CALLING_KEY);
mVideoCallingPref = (SwitchPreference) findPreference(BUTTON_VIDEO_CALLING_KEY);
- mMobileDataPref = (MobileDataPreference) findPreference(BUTTON_MOBILE_DATA_ENABLE_KEY);
mDataUsagePref = (DataUsagePreference) findPreference(BUTTON_DATA_USAGE_KEY);
try {
@@ -439,8 +457,6 @@
// Initialize mActiveSubInfo
int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
mActiveSubInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
- mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID,
- SubscriptionManager.INVALID_SUBSCRIPTION_ID);
updatePhone();
if (hasActiveSubscriptions()) {
@@ -491,14 +507,6 @@
}
@Override
- public void onDestroy() {
- super.onDestroy();
- if (mMobileDataPref != null) {
- mMobileDataPref.dispose();
- }
- }
-
- @Override
public void onResume() {
super.onResume();
Log.i(LOG_TAG, "onResume:+");
@@ -567,17 +575,14 @@
actionBar.setDisplayHomeAsUpEnabled(true);
}
- prefSet.addPreference(mMobileDataPref);
prefSet.addPreference(mButtonDataRoam);
prefSet.addPreference(mDataUsagePref);
- mMobileDataPref.setEnabled(hasActiveSubscriptions);
mButtonDataRoam.setEnabled(hasActiveSubscriptions);
mDataUsagePref.setEnabled(hasActiveSubscriptions);
if (hasActiveSubscriptions) {
// Customized preferences needs to be initialized with subId.
- mMobileDataPref.initialize(phoneSubId);
mDataUsagePref.initialize(phoneSubId);
// Initialize states of mButtonDataRoam.
@@ -609,8 +614,6 @@
return;
}
- prefSet.removeAll();
-
updateBodyBasicFields(activity, prefSet, mSubId, hasActiveSubscriptions);
if (hasActiveSubscriptions) {
@@ -724,10 +727,6 @@
/**
* Listen to extra preference changes that need as Metrics events logging.
*/
- if (prefSet.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY) != null) {
- prefSet.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
- .setOnPreferenceChangeListener(this);
- }
if (prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY) != null) {
prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)
@@ -787,10 +786,6 @@
if (ps != null) {
ps.setEnabled(hasActiveSubscriptions);
}
- ps = findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
- if (ps != null) {
- ps.setEnabled(hasActiveSubscriptions);
- }
ps = findPreference(CATEGORY_CALLING_KEY);
if (ps != null) {
ps.setEnabled(hasActiveSubscriptions);
@@ -1075,6 +1070,7 @@
Bundle b = new Bundle();
b.putInt(RoamingDialogFragment.SUB_ID_KEY, mSubId);
fragment.setArguments(b);
+ fragment.setTargetFragment(this, 0 /* requestCode */);
fragment.show(getFragmentManager(), ROAMING_TAG);
// Don't update the toggle unless the confirm button is actually pressed.
return false;
@@ -1098,8 +1094,6 @@
return false;
}
} else if (preference == getPreferenceScreen()
- .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
- || preference == getPreferenceScreen()
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
return true;
}
@@ -1431,13 +1425,18 @@
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch(requestCode) {
+ switch (requestCode) {
case REQUEST_CODE_EXIT_ECM:
Boolean isChoiceYes = data.getBooleanExtra(
EXTRA_EXIT_ECM_RESULT, false);
if (isChoiceYes) {
// If the phone exits from ECM mode, show the CDMA Options
- mCdmaOptions.showDialog(mClickedPreference);
+ if (TextUtils.equals(mClickedPreference.getKey(),
+ mCdmaSystemSelectPreferenceController.getPreferenceKey())) {
+ mCdmaSystemSelectPreferenceController.showDialog();
+ } else {
+ mCdmaOptions.showDialog(mClickedPreference);
+ }
} else {
// do nothing
}
@@ -1667,13 +1666,6 @@
return;
}
updateCdmaOptions(this, prefSet, mSubId);
- CdmaSystemSelectListPreference systemSelect =
- (CdmaSystemSelectListPreference)prefSet.findPreference
- (BUTTON_CDMA_SYSTEM_SELECT_KEY);
- systemSelect.setSubscriptionId(mSubId);
- if (systemSelect != null) {
- systemSelect.setEnabled(enable);
- }
}
private boolean isSupportTdscdma() {
@@ -1751,8 +1743,6 @@
if (preference == null) {
return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
- } else if (preference == mMobileDataPref) {
- return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_MOBILE_DATA_TOGGLE;
} else if (preference == mButtonDataRoam) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_DATA_ROAMING_TOGGLE;
} else if (preference == mDataUsagePref) {
@@ -1864,6 +1854,17 @@
protected boolean isPageSearchEnabled(Context context) {
return false;
}
+
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.network_setting_fragment;
+ result.add(sir);
+ return result;
+ }
};
private static final class SetPreferredNetworkAsyncTask extends AsyncTask<Void, Void, Boolean> {
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
new file mode 100644
index 0000000..666db1b
--- /dev/null
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.database.Cursor;
+import android.os.PersistableBundle;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.telephony.euicc.EuiccManager;
+import android.telephony.ims.feature.ImsFeature;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.ims.ImsException;
+import com.android.ims.ImsManager;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.R;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class MobileNetworkUtils {
+
+ private static final String TAG = "MobileNetworkUtils";
+
+ // CID of the device.
+ private static final String KEY_CID = "ro.boot.cid";
+ // CIDs of devices which should not show anything related to eSIM.
+ private static final String KEY_ESIM_CID_IGNORE = "ro.setupwizard.esim_cid_ignore";
+ // System Property which is used to decide whether the default eSIM UI will be shown,
+ // the default value is false.
+ private static final String KEY_ENABLE_ESIM_UI_BY_DEFAULT =
+ "esim.enable_esim_system_ui_by_default";
+ private static final String LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT =
+ "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
+
+ /**
+ * Returns if DPC APNs are enforced.
+ */
+ public static boolean isDpcApnEnforced(Context context) {
+ try (Cursor enforceCursor = context.getContentResolver().query(ENFORCE_MANAGED_URI,
+ null, null, null, null)) {
+ if (enforceCursor == null || enforceCursor.getCount() != 1) {
+ return false;
+ }
+ enforceCursor.moveToFirst();
+ return enforceCursor.getInt(0) > 0;
+ }
+ }
+
+ /**
+ * Returns true if Wifi calling is enabled for at least one phone.
+ */
+ public static boolean isWifiCallingEnabled(Context context) {
+ int phoneCount = TelephonyManager.from(context).getPhoneCount();
+ for (int i = 0; i < phoneCount; i++) {
+ if (isWifiCallingEnabled(context, i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if Wifi calling is enabled for the specific phone with id {@code phoneId}.
+ */
+ public static boolean isWifiCallingEnabled(Context context, int phoneId) {
+ final PhoneAccountHandle simCallManager =
+ TelecomManager.from(context).getSimCallManager();
+
+ boolean isWifiCallingEnabled;
+ if (simCallManager != null) {
+ Intent intent = buildPhoneAccountConfigureIntent(
+ context, simCallManager);
+
+ isWifiCallingEnabled = intent != null;
+ } else {
+ ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
+ isWifiCallingEnabled = imsMgr != null
+ && imsMgr.isWfcEnabledByPlatform()
+ && imsMgr.isWfcProvisionedOnDevice()
+ && isImsServiceStateReady(imsMgr);
+ }
+
+ return isWifiCallingEnabled;
+ }
+
+ @VisibleForTesting
+ static Intent buildPhoneAccountConfigureIntent(
+ Context context, PhoneAccountHandle accountHandle) {
+ Intent intent = buildConfigureIntent(
+ context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
+
+ if (intent == null) {
+ // If the new configuration didn't work, try the old configuration intent.
+ intent = buildConfigureIntent(context, accountHandle,
+ LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT);
+ }
+ return intent;
+ }
+
+ private static Intent buildConfigureIntent(
+ Context context, PhoneAccountHandle accountHandle, String actionStr) {
+ if (accountHandle == null || accountHandle.getComponentName() == null
+ || TextUtils.isEmpty(accountHandle.getComponentName().getPackageName())) {
+ return null;
+ }
+
+ // Build the settings intent.
+ Intent intent = new Intent(actionStr);
+ intent.setPackage(accountHandle.getComponentName().getPackageName());
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
+ intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
+
+ // Check to see that the phone account package can handle the setting intent.
+ PackageManager pm = context.getPackageManager();
+ List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
+ if (resolutions.size() == 0) {
+ intent = null; // set no intent if the package cannot handle it.
+ }
+
+ return intent;
+ }
+
+ public static boolean isImsServiceStateReady(ImsManager imsMgr) {
+ boolean isImsServiceStateReady = false;
+
+ try {
+ if (imsMgr != null && imsMgr.getImsServiceState() == ImsFeature.STATE_READY) {
+ isImsServiceStateReady = true;
+ }
+ } catch (ImsException ex) {
+ Log.e(TAG, "Exception when trying to get ImsServiceStatus: " + ex);
+ }
+
+ Log.d(TAG, "isImsServiceStateReady=" + isImsServiceStateReady);
+ return isImsServiceStateReady;
+ }
+
+ /**
+ * Whether to show the entry point to eUICC settings.
+ *
+ * <p>We show the entry point on any device which supports eUICC as long as either the eUICC
+ * was ever provisioned (that is, at least one profile was ever downloaded onto it), or if
+ * the user has enabled development mode.
+ */
+ public static boolean showEuiccSettings(Context context) {
+ EuiccManager euiccManager =
+ (EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
+ if (!euiccManager.isEnabled()) {
+ return false;
+ }
+
+ final ContentResolver cr = context.getContentResolver();
+
+ TelephonyManager tm =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ String currentCountry = tm.getNetworkCountryIso().toLowerCase();
+ String supportedCountries =
+ Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
+ boolean inEsimSupportedCountries = false;
+ if (TextUtils.isEmpty(currentCountry)) {
+ inEsimSupportedCountries = true;
+ } else if (!TextUtils.isEmpty(supportedCountries)) {
+ List<String> supportedCountryList =
+ Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ","));
+ if (supportedCountryList.contains(currentCountry)) {
+ inEsimSupportedCountries = true;
+ }
+ }
+ final boolean esimIgnoredDevice =
+ Arrays.asList(TextUtils.split(SystemProperties.get(KEY_ESIM_CID_IGNORE, ""), ","))
+ .contains(SystemProperties.get(KEY_CID, null));
+ final boolean enabledEsimUiByDefault =
+ SystemProperties.getBoolean(KEY_ENABLE_ESIM_UI_BY_DEFAULT, true);
+ final boolean euiccProvisioned =
+ Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
+ final boolean inDeveloperMode =
+ Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+
+ return (inDeveloperMode || euiccProvisioned
+ || (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries));
+ }
+
+ public static PersistableBundle getCarrierConfigBySubId(int mSubId) {
+ //TODO(b/114749736): get carrier config from subId
+ return new PersistableBundle();
+ }
+
+ /**
+ * Set whether to enable data for {@code subId}, also whether to disable data for other
+ * subscription
+ */
+ public static void setMobileDataEnabled(Context context, int subId, boolean enabled,
+ boolean disableOtherSubscriptions) {
+ final TelephonyManager telephonyManager = TelephonyManager.from(context)
+ .createForSubscriptionId(subId);
+ final SubscriptionManager subscriptionManager = context.getSystemService(
+ SubscriptionManager.class);
+ telephonyManager.setDataEnabled(enabled);
+
+ if (disableOtherSubscriptions) {
+ List<SubscriptionInfo> subInfoList =
+ subscriptionManager.getActiveSubscriptionInfoList();
+ if (subInfoList != null) {
+ for (SubscriptionInfo subInfo : subInfoList) {
+ if (subInfo.getSubscriptionId() != subId) {
+ TelephonyManager.from(context).createForSubscriptionId(
+ subInfo.getSubscriptionId()).setDataEnabled(false);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Return {@code true} if show CDMA category
+ */
+ public static boolean isCdmaOptions(Context context, int subId) {
+ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ return false;
+ }
+ final TelephonyManager telephonyManager = TelephonyManager.from(context)
+ .createForSubscriptionId(subId);
+
+ if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
+ return true;
+ }
+
+ if (isWorldMode(context, subId)) {
+ final int settingsNetworkMode = android.provider.Settings.Global.getInt(
+ 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) {
+ return true;
+ }
+
+ if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
+ && !isTdscdmaSupported(context, telephonyManager)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Return {@code true} if it is world mode, and we may show advanced options in telephony
+ * settings
+ */
+ public static boolean isWorldMode(Context context, int subId) {
+ final TelephonyManager telephonyManager = TelephonyManager.from(context)
+ .createForSubscriptionId(subId);
+ boolean worldModeOn = false;
+ final String configString = context.getString(R.string.config_world_mode);
+
+ if (!TextUtils.isEmpty(configString)) {
+ String[] configArray = configString.split(";");
+ // Check if we have World mode configuration set to True only or config is set to True
+ // and SIM GID value is also set and matches to the current SIM GID.
+ if (configArray != null &&
+ ((configArray.length == 1 && configArray[0].equalsIgnoreCase("true"))
+ || (configArray.length == 2 && !TextUtils.isEmpty(configArray[1])
+ && telephonyManager != null
+ && configArray[1].equalsIgnoreCase(
+ telephonyManager.getGroupIdLevel1())))) {
+ worldModeOn = true;
+ }
+ }
+
+ Log.d(TAG, "isWorldMode=" + worldModeOn);
+
+ return worldModeOn;
+ }
+
+ //TODO(b/117651939): move it to telephony
+ private static boolean isTdscdmaSupported(Context context, TelephonyManager telephonyManager) {
+ if (context.getResources().getBoolean(R.bool.config_support_tdscdma)) {
+ return true;
+ }
+
+ String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
+ String[] numericArray = context.getResources().getStringArray(
+ R.array.config_support_tdscdma_roaming_on_networks);
+ if (numericArray.length == 0 || operatorNumeric == null) {
+ return false;
+ }
+ for (String numeric : numericArray) {
+ if (operatorNumeric.equals(numeric)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java b/src/com/android/settings/network/telephony/MobileSettingsActivity.java
similarity index 68%
rename from src/com/android/settings/mobilenetwork/MobileSettingsActivity.java
rename to src/com/android/settings/network/telephony/MobileSettingsActivity.java
index 37a180c..e857871 100644
--- a/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java
+++ b/src/com/android/settings/network/telephony/MobileSettingsActivity.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Intent;
import android.os.Bundle;
@@ -23,6 +23,12 @@
import android.view.Menu;
import android.view.View;
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+
import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
import com.android.settings.core.SettingsBaseActivity;
@@ -31,23 +37,28 @@
import java.util.List;
-import androidx.annotation.VisibleForTesting;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-
public class MobileSettingsActivity extends SettingsBaseActivity {
@VisibleForTesting
static final String MOBILE_SETTINGS_TAG = "mobile_settings:";
public static final String KEY_SUBSCRIPTION_ID = "key_subscription_id";
+ public static final String KEY_CUR_SUBSCRIPTION_ID = "key_cur_subscription_id";
private SubscriptionManager mSubscriptionManager;
@VisibleForTesting
- int mPrevSubscriptionId;
+ Integer mCurSubscriptionId;
@VisibleForTesting
List<SubscriptionInfo> mSubscriptionInfos;
+ private final SubscriptionManager.OnSubscriptionsChangedListener
+ mOnSubscriptionsChangeListener
+ = new SubscriptionManager.OnSubscriptionsChangedListener() {
+ @Override
+ public void onSubscriptionsChanged() {
+ updateSubscriptions(null);
+ }
+ };
+
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -58,18 +69,42 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mSubscriptionManager = getSystemService(SubscriptionManager.class);
- mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
- mPrevSubscriptionId = CollectionUtils.isEmpty(mSubscriptionInfos)
- ? SubscriptionManager.INVALID_SUBSCRIPTION_ID
- : mSubscriptionInfos.get(0).getSubscriptionId();
setContentView(R.layout.mobile_settings_container);
+ mSubscriptionManager = getSystemService(SubscriptionManager.class);
+ mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
+ mCurSubscriptionId = savedInstanceState != null
+ ? savedInstanceState.getInt(KEY_CUR_SUBSCRIPTION_ID)
+ : null;
+
+ mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
+
+ updateSubscriptions(savedInstanceState);
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ saveInstanceState(outState);
+ }
+
+ @VisibleForTesting
+ void saveInstanceState(@NonNull Bundle outState) {
+ outState.putInt(KEY_CUR_SUBSCRIPTION_ID, mCurSubscriptionId);
+ }
+
+ @VisibleForTesting
+ void updateSubscriptions(Bundle savedInstanceState) {
+ //TODO(b/114749736): Sort it by phoneId
+ mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
+ final int subId = CollectionUtils.isEmpty(mSubscriptionInfos)
+ ? SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ : mSubscriptionInfos.get(0).getSubscriptionId();
updateBottomNavigationView();
if (savedInstanceState == null) {
- switchFragment(new MobileNetworkFragment(), mPrevSubscriptionId);
+ switchFragment(new MobileNetworkFragment(), subId);
}
}
@@ -89,24 +124,27 @@
}
navigation.setOnNavigationItemSelectedListener(item -> {
switchFragment(new MobileNetworkFragment(), item.getItemId());
- mPrevSubscriptionId = item.getItemId();
return true;
});
-
}
}
@VisibleForTesting
void switchFragment(Fragment fragment, int subscriptionId) {
+ if (mCurSubscriptionId != null && subscriptionId == mCurSubscriptionId) {
+ return;
+ }
final FragmentManager fragmentManager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
final Bundle bundle = new Bundle();
bundle.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
- final Fragment hideFragment = fragmentManager.findFragmentByTag(
- buildFragmentTag(mPrevSubscriptionId));
- if (hideFragment != null) {
- fragmentTransaction.hide(hideFragment);
+ if (mCurSubscriptionId != null) {
+ final Fragment hideFragment = fragmentManager.findFragmentByTag(
+ buildFragmentTag(mCurSubscriptionId));
+ if (hideFragment != null) {
+ fragmentTransaction.hide(hideFragment);
+ }
}
Fragment showFragment = fragmentManager.findFragmentByTag(buildFragmentTag(subscriptionId));
@@ -118,6 +156,7 @@
fragmentTransaction.show(showFragment);
}
fragmentTransaction.commit();
+ mCurSubscriptionId = subscriptionId;
}
private String buildFragmentTag(int subscriptionId) {
diff --git a/src/com/android/settings/mobilenetwork/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
similarity index 98%
rename from src/com/android/settings/mobilenetwork/NetworkOperatorPreference.java
rename to src/com/android/settings/network/telephony/NetworkOperatorPreference.java
index b11d52c..4b00613 100644
--- a/src/com/android/settings/mobilenetwork/NetworkOperatorPreference.java
+++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Context;
import android.graphics.Color;
diff --git a/src/com/android/settings/mobilenetwork/NetworkOperators.java b/src/com/android/settings/network/telephony/NetworkOperators.java
similarity index 99%
rename from src/com/android/settings/mobilenetwork/NetworkOperators.java
rename to src/com/android/settings/network/telephony/NetworkOperators.java
index 9f0de8a..7014820 100644
--- a/src/com/android/settings/mobilenetwork/NetworkOperators.java
+++ b/src/com/android/settings/network/telephony/NetworkOperators.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.app.ProgressDialog;
import android.content.Context;
diff --git a/src/com/android/settings/mobilenetwork/NetworkScanHelper.java b/src/com/android/settings/network/telephony/NetworkScanHelper.java
similarity index 99%
rename from src/com/android/settings/mobilenetwork/NetworkScanHelper.java
rename to src/com/android/settings/network/telephony/NetworkScanHelper.java
index 234d3b3..b34e592 100644
--- a/src/com/android/settings/mobilenetwork/NetworkScanHelper.java
+++ b/src/com/android/settings/network/telephony/NetworkScanHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.annotation.IntDef;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
diff --git a/src/com/android/settings/mobilenetwork/NetworkSelectListPreference.java b/src/com/android/settings/network/telephony/NetworkSelectListPreference.java
similarity index 99%
rename from src/com/android/settings/mobilenetwork/NetworkSelectListPreference.java
rename to src/com/android/settings/network/telephony/NetworkSelectListPreference.java
index c4d0d77..ceb0efa 100644
--- a/src/com/android/settings/mobilenetwork/NetworkSelectListPreference.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectListPreference.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 The Android Open Source Project
+ * Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.app.ProgressDialog;
import android.content.Context;
diff --git a/src/com/android/settings/mobilenetwork/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
similarity index 99%
rename from src/com/android/settings/mobilenetwork/NetworkSelectSettings.java
rename to src/com/android/settings/network/telephony/NetworkSelectSettings.java
index 20cc628..9205188 100644
--- a/src/com/android/settings/mobilenetwork/NetworkSelectSettings.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.content.Context;
import android.os.AsyncTask;
diff --git a/src/com/android/settings/mobilenetwork/RoamingDialogFragment.java b/src/com/android/settings/network/telephony/RoamingDialogFragment.java
similarity index 95%
rename from src/com/android/settings/mobilenetwork/RoamingDialogFragment.java
rename to src/com/android/settings/network/telephony/RoamingDialogFragment.java
index 6f71d9c..efb91d5 100644
--- a/src/com/android/settings/mobilenetwork/RoamingDialogFragment.java
+++ b/src/com/android/settings/network/telephony/RoamingDialogFragment.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -26,7 +26,6 @@
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
@@ -60,7 +59,6 @@
mSubId = args.getInt(SUB_ID_KEY);
mCarrierConfigManager = new CarrierConfigManager(context);
- //TODO(b/114749736): set target fragment in host fragment
Fragment fragment = getTargetFragment();
try {
mListener = (RoamingDialogListener) fragment;
diff --git a/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java b/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java
new file mode 100644
index 0000000..3d47fec
--- /dev/null
+++ b/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceController.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony.cdma;
+
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.network.telephony.MobileNetworkUtils;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Preference controller for "System Select"
+ */
+public class CdmaSystemSelectPreferenceController extends BasePreferenceController
+ implements LifecycleObserver, OnStart, OnStop, ListPreference.OnPreferenceChangeListener {
+
+ @VisibleForTesting
+ ListPreference mPreference;
+ private TelephonyManager mTelephonyManager;
+ private PreferenceManager mPreferenceManager;
+ private DataContentObserver mDataContentObserver;
+ private int mSubId;
+
+ public CdmaSystemSelectPreferenceController(Context context, String key) {
+ super(context, key);
+ mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
+ }
+
+ @Override
+ public void onStart() {
+ mDataContentObserver.register(mContext, mSubId);
+ }
+
+ @Override
+ public void onStop() {
+ mDataContentObserver.unRegister(mContext);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ final ListPreference listPreference = (ListPreference) preference;
+ listPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
+ final int mode = mTelephonyManager.getCdmaRoamingMode();
+ if (mode != TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT) {
+ if (mode == TelephonyManager.CDMA_ROAMING_MODE_HOME
+ || mode == TelephonyManager.CDMA_ROAMING_MODE_ANY) {
+ listPreference.setValue(Integer.toString(mode));
+ } else {
+ resetCdmaRoamingModeToDefault();
+ }
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object object) {
+ int newMode = Integer.parseInt((String) object);
+ //TODO(b/117611981): only set it in one place
+ if (mTelephonyManager.setCdmaRoamingMode(newMode)) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE, newMode);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void init(PreferenceManager preferenceManager, int subId) {
+ mPreferenceManager = preferenceManager;
+ mSubId = subId;
+ mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+ }
+
+ public void showDialog() {
+ if (!mTelephonyManager.getEmergencyCallbackMode()) {
+ mPreferenceManager.showDialog(mPreference);
+ }
+ }
+
+ private void resetCdmaRoamingModeToDefault() {
+ //set the mButtonCdmaRoam
+ mPreference.setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
+ //set the Settings.System
+ Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_ANY);
+ //Set the Status
+ mTelephonyManager.setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY);
+ }
+
+ /**
+ * Listener that listens mobile data state change.
+ */
+ public class DataContentObserver extends ContentObserver {
+
+ public DataContentObserver(Handler handler) {
+ super(handler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ updateState(mPreference);
+ }
+
+ public void register(Context context, int subId) {
+ Uri uri = Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE + subId);
+ context.getContentResolver().registerContentObserver(uri, false, this);
+ }
+
+ public void unRegister(Context context) {
+ context.getContentResolver().unregisterContentObserver(this);
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
index 16d255b..54a0d5e 100644
--- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -87,13 +87,13 @@
public void onResume() {
super.onResume();
getWindow().addFlags(
- WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
}
@Override
public void onPause() {
getWindow().clearFlags(
- WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
super.onPause();
}
diff --git a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
index 7d5ebf1..7b37855 100644
--- a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
+++ b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
@@ -25,6 +25,7 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.utils.ThreadUtils;
public abstract class RingtonePreferenceControllerBase extends AbstractPreferenceController
implements PreferenceControllerMixin {
@@ -45,11 +46,17 @@
@Override
public void updateState(Preference preference) {
+ ThreadUtils.postOnBackgroundThread(() -> updateSummary(preference));
+ }
+
+ private void updateSummary(Preference preference) {
Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, getRingtoneType());
final CharSequence summary = Ringtone.getTitle(
mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
if (summary != null) {
- preference.setSummary(summary);
+ ThreadUtils.postOnMainThread(() -> {
+ preference.setSummary(summary);
+ });
}
}
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index caddb1f..27e8349 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -16,12 +16,15 @@
*/
package com.android.settings.search;
+import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
+
import android.annotation.NonNull;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.view.View;
+import android.widget.Toolbar;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.overlay.FeatureFactory;
@@ -53,15 +56,23 @@
return "com.android.settings.intelligence";
}
-
/**
* Initializes the search toolbar.
*/
- default void initSearchToolbar(Activity activity, View view) {
- if (activity == null || view == null) {
+ default void initSearchToolbar(Activity activity, Toolbar toolbar) {
+ if (activity == null || toolbar == null) {
return;
}
- view.setOnClickListener(tb -> {
+ // Please forgive me for what I am about to do.
+ //
+ // Need to make the navigation icon non-clickable so that the entire card is clickable
+ // and goes to the search UI. Also set the background to null so there's no ripple.
+ final View navView = toolbar.getNavigationView();
+ navView.setClickable(false);
+ navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ navView.setBackground(null);
+
+ toolbar.setOnClickListener(tb -> {
final Intent intent = SEARCH_UI_INTENT;
intent.setPackage(getSettingsIntelligencePkgName());
final Context context = activity.getApplicationContext();
diff --git a/src/com/android/settings/slices/CustomSliceManager.java b/src/com/android/settings/slices/CustomSliceManager.java
index 3d708c7..8fa2fb6 100644
--- a/src/com/android/settings/slices/CustomSliceManager.java
+++ b/src/com/android/settings/slices/CustomSliceManager.java
@@ -22,6 +22,7 @@
import com.android.settings.homepage.deviceinfo.DataUsageSlice;
import com.android.settings.homepage.deviceinfo.DeviceInfoSlice;
+import com.android.settings.homepage.deviceinfo.StorageSlice;
import com.android.settings.wifi.WifiSlice;
import java.util.Map;
@@ -91,5 +92,6 @@
mUriMap.put(WifiSlice.WIFI_URI, WifiSlice.class);
mUriMap.put(DataUsageSlice.DATA_USAGE_CARD_URI, DataUsageSlice.class);
mUriMap.put(DeviceInfoSlice.DEVICE_INFO_CARD_URI, DeviceInfoSlice.class);
+ mUriMap.put(StorageSlice.STORAGE_CARD_URI, StorageSlice.class);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index e359477..8b975b4 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -42,7 +42,7 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flashlight.FlashlightSliceBuilder;
import com.android.settings.location.LocationSliceBuilder;
-import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
+import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.notification.ZenModeSliceBuilder;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.WifiSlice;
diff --git a/src/com/android/settings/slices/SliceBroadcastReceiver.java b/src/com/android/settings/slices/SliceBroadcastReceiver.java
index 4a4ee4d..e9e9d2c 100644
--- a/src/com/android/settings/slices/SliceBroadcastReceiver.java
+++ b/src/com/android/settings/slices/SliceBroadcastReceiver.java
@@ -19,7 +19,7 @@
import static com.android.settings.bluetooth.BluetoothSliceBuilder.ACTION_BLUETOOTH_SLICE_CHANGED;
import static com.android.settings.flashlight.FlashlightSliceBuilder
.ACTION_FLASHLIGHT_SLICE_CHANGED;
-import static com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper
+import static com.android.settings.network.telephony.Enhanced4gLteSliceHelper
.ACTION_ENHANCED_4G_LTE_CHANGED;
import static com.android.settings.notification.ZenModeSliceBuilder.ACTION_ZEN_MODE_SLICE_CHANGED;
import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CHANGED;
diff --git a/src/com/android/settings/slices/SlicesFeatureProvider.java b/src/com/android/settings/slices/SlicesFeatureProvider.java
index 5940aa4..1a9fd98 100644
--- a/src/com/android/settings/slices/SlicesFeatureProvider.java
+++ b/src/com/android/settings/slices/SlicesFeatureProvider.java
@@ -2,7 +2,7 @@
import android.content.Context;
-import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
+import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
/**
diff --git a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
index fc2298c..39d385e 100644
--- a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
+++ b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
@@ -2,7 +2,7 @@
import android.content.Context;
-import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
+import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
import com.android.settingslib.utils.ThreadUtils;
diff --git a/src/com/android/settings/webview/WebViewAppPicker.java b/src/com/android/settings/webview/WebViewAppPicker.java
index b96217e..72d7918 100644
--- a/src/com/android/settings/webview/WebViewAppPicker.java
+++ b/src/com/android/settings/webview/WebViewAppPicker.java
@@ -118,9 +118,9 @@
}
private static class WebViewAppInfo extends DefaultAppInfo {
- public WebViewAppInfo(Context context, PackageManager pm,
+ public WebViewAppInfo(Context context, PackageManager pm, int userId,
PackageItemInfo packageItemInfo, String summary, boolean enabled) {
- super(context, pm, packageItemInfo, summary, enabled);
+ super(context, pm, userId, packageItemInfo, summary, enabled);
}
@Override
@@ -138,7 +138,7 @@
@VisibleForTesting
DefaultAppInfo createDefaultAppInfo(Context context, PackageManager pm,
PackageItemInfo packageItemInfo, String disabledReason) {
- return new WebViewAppInfo(context, pm, packageItemInfo, disabledReason,
+ return new WebViewAppInfo(context, pm, mUserId, packageItemInfo, disabledReason,
TextUtils.isEmpty(disabledReason) /* enabled */);
}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerV2Test.java
index 5e9179f..708222e 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerV2Test.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppDataUsagePreferenceControllerV2Test.java
@@ -43,12 +43,11 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;import android.net.INetworkStatsSession;
+import org.mockito.Mock;
import android.util.FeatureFlagUtils;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
import androidx.loader.app.LoaderManager;
import androidx.preference.Preference;
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
index f6abb5b..f4571ce 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java
@@ -18,8 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -66,8 +66,8 @@
public void hasAppCapability_hasBrowserCapability_shouldReturnTrue() {
List<ResolveInfo> resolveInfos = new ArrayList<>();
resolveInfos.add(new ResolveInfo());
- when(mPackageManager.queryIntentActivities(argThat(intent-> intent != null
- && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt()))
+ when(mPackageManager.queryIntentActivitiesAsUser(argThat(intent-> intent != null
+ && intent.getCategories().contains(Intent.CATEGORY_BROWSABLE)), anyInt(), anyInt()))
.thenReturn(resolveInfos);
assertThat(mController.hasAppCapability()).isTrue();
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DrawOverlayDetailsTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DrawOverlayDetailsTest.java
index d867b6f..1b25286 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/DrawOverlayDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DrawOverlayDetailsTest.java
@@ -16,7 +16,7 @@
package com.android.settings.applications.appinfo;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
@@ -91,7 +91,7 @@
when(mWindow.getAttributes()).thenReturn(layoutParams);
mFragment.onResume();
- verify(mWindow).addPrivateFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ verify(mWindow).addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
mFragment.onPause();
@@ -99,6 +99,6 @@
ArgumentCaptor<LayoutParams> paramCaptor = ArgumentCaptor.forClass(LayoutParams.class);
verify(mWindow).setAttributes(paramCaptor.capture());
assertEquals(0,
- paramCaptor.getValue().privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ paramCaptor.getValue().privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
index 4a482d0..cd3a426 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultBrowserPreferenceControllerTest.java
@@ -34,6 +34,7 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
import android.os.UserManager;
import androidx.preference.Preference;
@@ -131,6 +132,16 @@
}
@Test
+ public void getDefaultApp_shouldGetApplicationInfoAsUser() throws NameNotFoundException {
+ final String PACKAGE_NAME = "com.test.package";
+ when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn(PACKAGE_NAME);
+
+ mController.getDefaultAppInfo();
+
+ verify(mPackageManager).getApplicationInfoAsUser(eq(PACKAGE_NAME), anyInt(), anyInt());
+ }
+
+ @Test
public void isBrowserDefault_onlyApp_shouldReturnTrue() {
when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn(null);
final List<ResolveInfo> resolveInfos = new ArrayList<>();
@@ -173,6 +184,33 @@
any(Intent.class), eq(0) /* flags */, eq(0) /* userId */);
}
+ @Test
+ public void getOnlyAppIcon_shouldGetApplicationInfoAsUser() throws NameNotFoundException {
+ final List<ResolveInfo> resolveInfos = new ArrayList<>();
+ final String PACKAGE_NAME = "com.test.package";
+ resolveInfos.add(createResolveInfo(PACKAGE_NAME));
+ when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
+ .thenReturn(resolveInfos);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
+ when(mContext.getResources()).thenReturn(mock(Resources.class));
+
+ mController.getOnlyAppIcon();
+
+ verify(mPackageManager).getApplicationInfoAsUser(
+ eq(PACKAGE_NAME), eq(0) /* flags */, eq(0) /* userId */);
+ }
+
+ @Test
+ public void hasBrowserPreference_shouldQueryIntentActivitiesAsUser() {
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+
+ mController.hasBrowserPreference("com.test.package", mContext, 0 /* userId */);
+
+ verify(mPackageManager).queryIntentActivitiesAsUser(
+ any(Intent.class), eq(0) /* flags */, eq(0) /* userId */);
+ }
+
private ResolveInfo createResolveInfo(String packageName) {
final ResolveInfo info = new ResolveInfo();
info.handleAllWebDataURI = true;
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
index bfbdd7f..369d222 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
@@ -19,14 +19,9 @@
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 android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -59,12 +54,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
@@ -98,4 +88,4 @@
assertThat(adapter.isEnabled()).isTrue();
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
index 8aec1f7..2c619dc 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDefaultFragmentTest.java
@@ -16,13 +16,21 @@
package com.android.settings.connecteddevice.usb;
+import static android.net.ConnectivityManager.TETHERING_USB;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.hardware.usb.UsbManager;
+import android.net.ConnectivityManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -32,13 +40,17 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;
+import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class)
public class UsbDefaultFragmentTest {
@Mock
private UsbBackend mUsbBackend;
+ @Mock
+ private ConnectivityManager mConnectivityManager;
private UsbDefaultFragment mFragment;
@@ -47,6 +59,7 @@
MockitoAnnotations.initMocks(this);
mFragment = new UsbDefaultFragment();
mFragment.mUsbBackend = mUsbBackend;
+ mFragment.mConnectivityManager = mConnectivityManager;
}
@Test
@@ -103,12 +116,6 @@
}
@Test
- public void setDefaultKey_isRndis_shouldSetRndis() {
- mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
- verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
- }
-
- @Test
public void setDefaultKey_isMidi_shouldSetMidi() {
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MIDI));
verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_MIDI);
@@ -119,6 +126,39 @@
public void setDefaultKey_isMonkey_shouldDoNothing() {
ShadowUtils.setIsUserAMonkey(true);
mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP));
- verifyZeroInteractions(mUsbBackend);
+
+ verify(mUsbBackend, never()).setDefaultUsbFunctions(anyLong());
+ }
+
+ @Test
+ public void setDefaultKey_functionRndis_startTetheringInvoked() {
+ doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
+
+ mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
+
+ verify(mConnectivityManager).startTethering(TETHERING_USB, true,
+ mFragment.mOnStartTetheringCallback);
+ assertThat(mFragment.mPreviousFunctions).isEqualTo(
+ UsbManager.FUNCTION_MTP);
+ }
+
+ @Test
+ public void setDefaultKey_functionOther_setCurrentFunctionInvoked() {
+ doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
+
+ mFragment.setDefaultKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
+
+ verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_PTP);
+ assertThat(mFragment.mPreviousFunctions).isEqualTo(
+ UsbManager.FUNCTION_MTP);
+ }
+
+ @Test
+ public void onTetheringStarted_setDefaultUsbFunctions() {
+ mFragment.mPreviousFunctions = UsbManager.FUNCTION_PTP;
+
+ mFragment.mOnStartTetheringCallback.onTetheringStarted();
+
+ verify(mUsbBackend).setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
}
}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
index 888a1f3..679a2a9 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java
@@ -16,20 +16,21 @@
package com.android.settings.connecteddevice.usb;
+import static android.net.ConnectivityManager.TETHERING_USB;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
-
-import androidx.fragment.app.FragmentActivity;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
+import android.net.ConnectivityManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowUtils;
@@ -48,15 +49,21 @@
import java.util.Iterator;
import java.util.List;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class UsbDetailsFunctionsControllerTest {
private UsbDetailsFunctionsController mDetailsFunctionsController;
private Context mContext;
private Lifecycle mLifecycle;
- private PreferenceCategory mPreference;
+ private PreferenceCategory mPreferenceCategory;
private PreferenceManager mPreferenceManager;
private PreferenceScreen mScreen;
+ private RadioButtonPreference mRadioButtonPreference;
@Mock
private UsbBackend mUsbBackend;
@@ -64,12 +71,14 @@
private UsbDetailsFragment mFragment;
@Mock
private FragmentActivity mActivity;
+ @Mock
+ private ConnectivityManager mConnectivityManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
+ mContext = spy(RuntimeEnvironment.application);
mLifecycle = new Lifecycle(() -> mLifecycle);
mPreferenceManager = new PreferenceManager(mContext);
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
@@ -79,12 +88,16 @@
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
+ when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
mDetailsFunctionsController = new UsbDetailsFunctionsController(mContext, mFragment,
mUsbBackend);
- mPreference = new PreferenceCategory(mContext);
- mPreference.setKey(mDetailsFunctionsController.getPreferenceKey());
- mScreen.addPreference(mPreference);
+ mPreferenceCategory = new PreferenceCategory(mContext);
+ mPreferenceCategory.setKey(mDetailsFunctionsController.getPreferenceKey());
+ mScreen.addPreference(mPreferenceCategory);
+ mDetailsFunctionsController.displayPreference(mScreen);
+
+ mRadioButtonPreference = new RadioButtonPreference(mContext);
}
@Test
@@ -106,10 +119,9 @@
public void displayRefresh_disconnected_shouldDisable() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(false, UsbManager.FUNCTION_NONE,
UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE);
- assertThat(mPreference.isEnabled()).isFalse();
+ assertThat(mPreferenceCategory.isEnabled()).isFalse();
}
@Test
@@ -119,7 +131,6 @@
when(mUsbBackend.areFunctionsSupported(UsbManager.FUNCTION_PTP)).thenReturn(false);
when(mUsbBackend.areFunctionsSupported(UsbManager.FUNCTION_RNDIS)).thenReturn(false);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_NONE, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
List<RadioButtonPreference> prefs = getRadioPreferences();
@@ -132,7 +143,6 @@
public void displayRefresh_mtpEnabled_shouldCheckSwitches() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_MTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
List<RadioButtonPreference> prefs = getRadioPreferences();
@@ -146,7 +156,6 @@
public void onClickMtp_noneEnabled_shouldEnableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_NONE, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_NONE);
@@ -165,7 +174,6 @@
public void onClickMtp_ptpEnabled_shouldEnableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_PTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_PTP);
@@ -187,7 +195,6 @@
public void onClickNone_mtpEnabled_shouldDisableMtp() {
when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true);
- mDetailsFunctionsController.displayPreference(mScreen);
mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_MTP, UsbPort.POWER_ROLE_SINK,
UsbPort.DATA_ROLE_DEVICE);
when(mUsbBackend.getCurrentFunctions()).thenReturn(UsbManager.FUNCTION_MTP);
@@ -211,9 +218,55 @@
private List<RadioButtonPreference> getRadioPreferences() {
ArrayList<RadioButtonPreference> result = new ArrayList<>();
- for (int i = 0; i < mPreference.getPreferenceCount(); i++) {
- result.add((RadioButtonPreference) mPreference.getPreference(i));
+ for (int i = 0; i < mPreferenceCategory.getPreferenceCount(); i++) {
+ result.add((RadioButtonPreference) mPreferenceCategory.getPreference(i));
}
return result;
}
+
+ @Test
+ public void onRadioButtonClicked_functionRndis_startTetheringInvoked() {
+ mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_RNDIS));
+ doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
+
+ mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
+
+ verify(mConnectivityManager).startTethering(TETHERING_USB, true,
+ mDetailsFunctionsController.mOnStartTetheringCallback);
+ assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
+ UsbManager.FUNCTION_MTP);
+ }
+
+ @Test
+ public void onRadioButtonClicked_functionOther_setCurrentFunctionInvoked() {
+ mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
+ doReturn(UsbManager.FUNCTION_MTP).when(mUsbBackend).getCurrentFunctions();
+
+ mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
+
+ verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
+ assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(
+ UsbManager.FUNCTION_MTP);
+ }
+
+ @Test
+ public void onRadioButtonClicked_clickSameButton_doNothing() {
+ mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP));
+ doReturn(UsbManager.FUNCTION_PTP).when(mUsbBackend).getCurrentFunctions();
+
+ mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference);
+
+ verify(mUsbBackend, never()).setCurrentFunctions(UsbManager.FUNCTION_PTP);
+ verify(mConnectivityManager, never()).startTethering(TETHERING_USB, true,
+ mDetailsFunctionsController.mOnStartTetheringCallback);
+ }
+
+ @Test
+ public void onTetheringFailed_resetPreviousFunctions() {
+ mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_PTP;
+
+ mDetailsFunctionsController.mOnStartTetheringCallback.onTetheringFailed();
+
+ verify(mUsbBackend).setCurrentFunctions(UsbManager.FUNCTION_PTP);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java b/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java
index eb5e491..1560af3 100644
--- a/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java
@@ -16,14 +16,17 @@
package com.android.settings.datausage;
import static android.net.NetworkPolicy.CYCLE_NONE;
+import static com.google.common.truth.Truth.assertThat;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.nullable;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -32,14 +35,20 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.NetworkPolicyManager;
import android.os.Bundle;
+import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.SwitchPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.NetworkPolicyEditor;
+import com.android.settingslib.widget.FooterPreference;
+import com.android.settingslib.widget.FooterPreferenceMixinCompat;
import org.junit.Before;
import org.junit.Test;
@@ -47,6 +56,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
public class BillingCycleSettingsTest {
@@ -60,6 +70,10 @@
PreferenceManager mMockPreferenceManager;
@Mock
private NetworkPolicyEditor mNetworkPolicyEditor;
+ @Mock
+ private ConnectivityManager mConnectivityManager;
+ @Mock
+ private NetworkPolicyManager mNetworkPolicyManager;
private Context mContext;
@Mock
@@ -96,7 +110,8 @@
public void testDataUsageLimit_shouldNotBeSetOnCancel() {
mConfirmLimitFragment.onClick(null, DialogInterface.BUTTON_NEGATIVE);
- assertFalse(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, true));
+ assertThat(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, true))
+ .isFalse();
verify(mMockBillingCycleSettings, never()).setPolicyLimitBytes(anyLong());
}
@@ -104,7 +119,8 @@
public void testDataUsageLimit_shouldBeSetOnConfirmation() {
mConfirmLimitFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
- assertTrue(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, false));
+ assertThat(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, false))
+ .isTrue();
verify(mMockBillingCycleSettings).setPolicyLimitBytes(LIMIT_BYTES);
}
@@ -124,4 +140,32 @@
verify(mBillingCycle).setSummary(null);
}
+
+ @Test
+ public void onCreate_emptyArguments_shouldSetDefaultNetworkTemplate() {
+ final BillingCycleSettings billingCycleSettings = spy(new BillingCycleSettings());
+ when(billingCycleSettings.getContext()).thenReturn(mContext);
+ when(billingCycleSettings.getArguments()).thenReturn(Bundle.EMPTY);
+ final FragmentActivity activity = mock(FragmentActivity.class);
+ when(billingCycleSettings.getActivity()).thenReturn(activity);
+ final Resources.Theme theme = mContext.getTheme();
+ when(activity.getTheme()).thenReturn(theme);
+ doNothing().when(billingCycleSettings)
+ .onCreatePreferences(any(Bundle.class), nullable(String.class));
+ when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE))
+ .thenReturn(mNetworkPolicyManager);
+ when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
+ .thenReturn(mConnectivityManager);
+ when(mConnectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
+ final SwitchPreference preference = mock(SwitchPreference.class);
+ when(billingCycleSettings.findPreference(anyString())).thenReturn(preference);
+ final FooterPreferenceMixinCompat footer = mock(FooterPreferenceMixinCompat.class);
+ ReflectionHelpers.setField(billingCycleSettings, "mFooterPreferenceMixin", footer);
+ when(footer.createFooterPreference()).thenReturn(mock(FooterPreference.class));
+
+ billingCycleSettings.onCreate(Bundle.EMPTY);
+
+ assertThat(billingCycleSettings.mNetworkTemplate).isNotNull();
+ }
+
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
index 254e4f6f..5171548 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryPreferenceControllerTest.java
@@ -121,7 +121,7 @@
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
when(mActivity.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
- when(mActivity.getSystemService(ConnectivityManager.class))
+ when(mActivity.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mConnectivityManager);
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
diff --git a/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java b/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
index 07296e6..56a84bb 100644
--- a/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
@@ -19,12 +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 android.content.Context;
-import android.content.res.Resources;
import android.provider.Settings;
import androidx.slice.Slice;
@@ -53,12 +48,7 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/homepage/CardContentLoaderTest.java b/tests/robotests/src/com/android/settings/homepage/CardContentLoaderTest.java
index 20ad067..defe0d9 100644
--- a/tests/robotests/src/com/android/settings/homepage/CardContentLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/CardContentLoaderTest.java
@@ -18,128 +18,94 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-
import android.content.Context;
-import android.database.Cursor;
-import android.database.MatrixCursor;
+import android.net.Uri;
+import com.android.settings.homepage.deviceinfo.DataUsageSlice;
+import com.android.settings.homepage.deviceinfo.DeviceInfoSlice;
+import com.android.settings.homepage.deviceinfo.StorageSlice;
+import com.android.settings.slices.SettingsSliceProvider;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowContentResolver;
+import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
@RunWith(SettingsRobolectricTestRunner.class)
public class CardContentLoaderTest {
- private static final String[] QUERY_PROJECTION = {
- CardDatabaseHelper.CardColumns.NAME,
- CardDatabaseHelper.CardColumns.TYPE,
- CardDatabaseHelper.CardColumns.SCORE,
- CardDatabaseHelper.CardColumns.SLICE_URI,
- CardDatabaseHelper.CardColumns.CATEGORY,
- CardDatabaseHelper.CardColumns.LOCALIZED_TO_LOCALE,
- CardDatabaseHelper.CardColumns.PACKAGE_NAME,
- CardDatabaseHelper.CardColumns.APP_VERSION,
- CardDatabaseHelper.CardColumns.TITLE_RES_NAME,
- CardDatabaseHelper.CardColumns.TITLE_TEXT,
- CardDatabaseHelper.CardColumns.SUMMARY_RES_NAME,
- CardDatabaseHelper.CardColumns.SUMMARY_TEXT,
- CardDatabaseHelper.CardColumns.ICON_RES_NAME,
- CardDatabaseHelper.CardColumns.ICON_RES_ID,
- CardDatabaseHelper.CardColumns.CARD_ACTION,
- CardDatabaseHelper.CardColumns.EXPIRE_TIME_MS,
- CardDatabaseHelper.CardColumns.SUPPORT_HALF_WIDTH
- };
private Context mContext;
private CardContentLoader mCardContentLoader;
+ private SettingsSliceProvider mProvider;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
- mCardContentLoader = spy(new CardContentLoader(mContext));
+ mCardContentLoader = new CardContentLoader(mContext);
+ mProvider = new SettingsSliceProvider();
+ ShadowContentResolver.registerProviderInternal(SettingsSliceProvider.SLICE_AUTHORITY,
+ mProvider);
}
@Test
- public void loadInBackground_hasDataInDb_shouldReturnData() {
- final Cursor cursor = generateTwoRowContextualCards();
- doReturn(cursor).when(mCardContentLoader).getContextualCardsFromProvider();
+ public void createStaticCards_shouldReturnTwoCards() {
+ final List<ContextualCard> defaultData = mCardContentLoader.createStaticCards();
- final List<ContextualCard> contextualCards = mCardContentLoader.loadInBackground();
-
- assertThat(contextualCards.size()).isEqualTo(cursor.getCount());
+ assertThat(defaultData).hasSize(3);
}
@Test
- public void loadInBackground_hasNoData_shouldReturnThreeDefaultData() {
- final Cursor cursor = generateEmptyContextualCards();
- doReturn(cursor).when(mCardContentLoader).getContextualCardsFromProvider();
+ public void createStaticCards_shouldContainDataUsageAndDeviceInfo() {
+ final Uri dataUsage = DataUsageSlice.DATA_USAGE_CARD_URI;
+ final Uri deviceInfo = DeviceInfoSlice.DEVICE_INFO_CARD_URI;
+ final Uri storageInfo = StorageSlice.STORAGE_CARD_URI;
+ final List<Uri> expectedUris = Arrays.asList(dataUsage, deviceInfo, storageInfo);
- final List<ContextualCard> contextualCards = mCardContentLoader.loadInBackground();
+ final List<Uri> actualCardUris = mCardContentLoader.createStaticCards().stream().map(
+ ContextualCard::getSliceUri).collect(Collectors.toList());
- assertThat(contextualCards.size()).isEqualTo(mCardContentLoader.createStaticCards().size());
+ assertThat(actualCardUris).containsExactlyElementsIn(expectedUris);
}
- private MatrixCursor generateEmptyContextualCards() {
- final MatrixCursor result = new MatrixCursor(QUERY_PROJECTION);
- return result;
+ @Test
+ public void isCardEligibleToDisplay_customCard_returnTrue() {
+ final ContextualCard customCard = new ContextualCard.Builder()
+ .setName("custom_card")
+ .setCardType(ContextualCard.CardType.DEFAULT)
+ .setTitleText("custom_title")
+ .setSummaryText("custom_summary")
+ .build();
+
+ assertThat(mCardContentLoader.isCardEligibleToDisplay(customCard)).isTrue();
}
- private MatrixCursor generateTwoRowContextualCards() {
- final MatrixCursor result = generateEmptyContextualCards();
- result.addRow(generateFirstFakeData());
- result.addRow(generateSecondFakeData());
- return result;
+ @Test
+ public void isCardEligibleToDisplay_invalidScheme_returnFalse() {
+ final String sliceUri = "contet://com.android.settings.slices/action/flashlight";
+
+ assertThat(
+ mCardContentLoader.isCardEligibleToDisplay(getContextualCard(sliceUri))).isFalse();
}
- private Object[] generateFirstFakeData() {
- final Object[] ref = new Object[]{
- "auto_rotate", /* NAME */
- ContextualCard.CardType.SLICE, /* TYPE */
- 0.5, /* SCORE */
- "content://com.android.settings.slices/action/auto_rotate", /* SLICE_URI */
- 2, /* CATEGORY */
- "", /* LOCALIZED_TO_LOCALE */
- "com.android.settings", /* PACKAGE_NAME */
- 1l, /* APP_VERSION */
- "", /* TITLE_RES_NAME */
- "", /* TITLE_TEXT */
- "", /* SUMMARY_RES_NAME */
- "", /* SUMMARY_TEXT */
- "", /* ICON_RES_NAME */
- 0, /* ICON_RES_ID */
- 0, /* CARD_ACTION */
- -1, /* EXPIRE_TIME_MS */
- 0 /* SUPPORT_HALF_WIDTH */
- };
- return ref;
+ @Test
+ public void isCardEligibleToDisplay_noProvider_returnFalse() {
+ final String sliceUri = "content://com.android.settings.test.slices/action/flashlight";
+
+ assertThat(
+ mCardContentLoader.isCardEligibleToDisplay(getContextualCard(sliceUri))).isFalse();
}
- private Object[] generateSecondFakeData() {
- final Object[] ref = new Object[]{
- "toggle_airplane", /* NAME */
- ContextualCard.CardType.SLICE, /* TYPE */
- 0.5, /* SCORE */
- "content://com.android.settings.slices/action/toggle_airplane", /* SLICE_URI */
- 2, /* CATEGORY */
- "", /* LOCALIZED_TO_LOCALE */
- "com.android.settings", /* PACKAGE_NAME */
- 1l, /* APP_VERSION */
- "", /* TITLE_RES_NAME */
- "", /* TITLE_TEXT */
- "", /* SUMMARY_RES_NAME */
- "", /* SUMMARY_TEXT */
- "", /* ICON_RES_NAME */
- 0, /* ICON_RES_ID */
- 0, /* CARD_ACTION */
- -1, /* EXPIRE_TIME_MS */
- 0 /* SUPPORT_HALF_WIDTH */
- };
- return ref;
+ private ContextualCard getContextualCard(String sliceUri) {
+ return new ContextualCard.Builder()
+ .setName("test_card")
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setSliceUri(sliceUri)
+ .build();
}
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java
index 80d9497..a80b963 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProviderTest.java
@@ -24,9 +24,9 @@
import android.net.Uri;
import android.os.Bundle;
+import com.android.settings.intelligence.ContextualCardProto.ContextualCardList;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.google.android.settings.intelligence.libs.contextualcards.ContextualCard;
import com.google.android.settings.intelligence.libs.contextualcards.ContextualCardProvider;
import org.junit.Before;
@@ -34,8 +34,6 @@
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
-import java.util.ArrayList;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class SettingsContextualCardProviderTest {
@@ -54,11 +52,12 @@
}
@Test
- public void contentProviderCall_returnCorrectSize() {
+ public void contentProviderCall_returnCorrectSize() throws Exception {
final Bundle returnValue =
mResolver.call(mUri, ContextualCardProvider.METHOD_GET_CARD_LIST, "", null);
- final ArrayList<ContextualCard> cards =
- returnValue.getParcelableArrayList(ContextualCardProvider.BUNDLE_CARD_LIST);
- assertThat(cards.size()).isEqualTo(2);
+ final ContextualCardList cards =
+ ContextualCardList.parseFrom(
+ returnValue.getByteArray(ContextualCardProvider.BUNDLE_CARD_LIST));
+ assertThat(cards.getCardCount()).isEqualTo(2);
}
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/homepage/deviceinfo/DataUsageSliceTest.java b/tests/robotests/src/com/android/settings/homepage/deviceinfo/DataUsageSliceTest.java
index c03070c..9993369 100644
--- a/tests/robotests/src/com/android/settings/homepage/deviceinfo/DataUsageSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/deviceinfo/DataUsageSliceTest.java
@@ -19,12 +19,10 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context;
-import android.content.res.Resources;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -58,12 +56,7 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/homepage/deviceinfo/DeviceInfoSliceTest.java b/tests/robotests/src/com/android/settings/homepage/deviceinfo/DeviceInfoSliceTest.java
index 2480baf..58a7220 100644
--- a/tests/robotests/src/com/android/settings/homepage/deviceinfo/DeviceInfoSliceTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/deviceinfo/DeviceInfoSliceTest.java
@@ -57,7 +57,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/homepage/deviceinfo/StorageSliceTest.java b/tests/robotests/src/com/android/settings/homepage/deviceinfo/StorageSliceTest.java
new file mode 100644
index 0000000..effc8da
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/deviceinfo/StorageSliceTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage.deviceinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+
+import androidx.core.graphics.drawable.IconCompat;
+import androidx.slice.Slice;
+import androidx.slice.SliceItem;
+import androidx.slice.SliceMetadata;
+import androidx.slice.SliceProvider;
+import androidx.slice.core.SliceAction;
+import androidx.slice.widget.SliceLiveData;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.SliceTester;
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class StorageSliceTest {
+ private static final String USED_BYTES_TEXT = "test used bytes";
+ private static final String SUMMARY_TEXT = "test summary";
+
+ private Context mContext;
+ private StorageSlice mStorageSlice;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+
+ // Set-up specs for SliceMetadata.
+ SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+
+ mStorageSlice = spy(new StorageSlice(mContext));
+ }
+
+ @Test
+ public void getSlice_shouldBeCorrectSliceContent() {
+ final PrivateStorageInfo info = new PrivateStorageInfo(100L, 600L);
+ doReturn(info).when(mStorageSlice).getPrivateStorageInfo();
+ doReturn(USED_BYTES_TEXT).when(mStorageSlice).getStorageUsedText(any());
+ doReturn(SUMMARY_TEXT).when(mStorageSlice).getStorageSummaryText(any());
+ final Slice slice = mStorageSlice.getSlice();
+ final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
+ final SliceAction primaryAction = metadata.getPrimaryAction();
+ final IconCompat expectedIcon = IconCompat.createWithResource(mContext,
+ R.drawable.ic_homepage_storage);
+ assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
+
+ final List<SliceItem> sliceItems = slice.getItems();
+ SliceTester.assertTitle(sliceItems, mContext.getString(R.string.storage_label));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/slices/SliceContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/slices/SliceContextualCardRendererTest.java
index 3239971..c597a6e 100644
--- a/tests/robotests/src/com/android/settings/homepage/slices/SliceContextualCardRendererTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/slices/SliceContextualCardRendererTest.java
@@ -54,6 +54,18 @@
}
@Test
+ public void bindView_shouldSetScrollableToFalse() {
+ final String sliceUri = "content://com.android.settings.slices/action/flashlight";
+ RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
+
+ mRenderer.bindView(viewHolder, buildContextualCard(sliceUri));
+
+ assertThat(
+ ((SliceContextualCardRenderer.SliceViewHolder) viewHolder).sliceView.isScrollable
+ ()).isFalse();
+ }
+
+ @Test
public void bindView_invalidScheme_sliceShouldBeNull() {
final String sliceUri = "contet://com.android.settings.slices/action/flashlight";
RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
diff --git a/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
index 65b2e87..ecbf858 100644
--- a/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
@@ -2,12 +2,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 android.content.Context;
-import android.content.res.Resources;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -35,12 +30,7 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelperTest.java b/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLteSliceHelperTest.java
similarity index 95%
rename from tests/robotests/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelperTest.java
rename to tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLteSliceHelperTest.java
index 6d98381..d260a97 100644
--- a/tests/robotests/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/Enhanced4gLteSliceHelperTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_TITLE;
@@ -23,7 +23,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -32,7 +31,6 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.telephony.CarrierConfigManager;
import androidx.slice.Slice;
@@ -81,7 +79,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
+ mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();
@@ -98,11 +96,6 @@
//setup for SliceBroadcastReceiver test
mReceiver = spy(new SliceBroadcastReceiver());
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
-
mEnhanced4gLteSliceHelper = new FakeEnhanced4gLteSliceHelper(mContext);
// Set-up specs for SliceMetadata.
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
new file mode 100644
index 0000000..2fc3d98
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileDataPreferenceControllerTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class MobileDataPreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private FragmentManager mFragmentManager;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mInvalidTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo;
+ @Mock
+ private FragmentTransaction mFragmentTransaction;
+
+ private MobileDataPreferenceController mController;
+ private SwitchPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+ doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
+
+ mPreference = new SwitchPreference(mContext);
+ mController = new MobileDataPreferenceController(mContext, "mobile_data");
+ mController.init(mFragmentManager, SUB_ID);
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_invalidSubscription_returnUnavailable() {
+ mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void isDialogNeeded_disableSingleSim_returnTrue() {
+ doReturn(true).when(mTelephonyManager).isDataEnabled();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(1).when(mTelephonyManager).getSimCount();
+
+ assertThat(mController.isDialogNeeded()).isTrue();
+ assertThat(mController.mDialogType).isEqualTo(MobileDataDialogFragment.TYPE_DISABLE_DIALOG);
+ }
+
+ @Test
+ public void isDialogNeeded_enableNonDefaultSimInMultiSimMode_returnTrue() {
+ doReturn(false).when(mTelephonyManager).isDataEnabled();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+ doReturn(null).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(2).when(mTelephonyManager).getSimCount();
+ doReturn(1).when(mTelephonyManager).getNumberOfModemsWithSimultaneousDataConnections();
+
+ assertThat(mController.isDialogNeeded()).isTrue();
+ assertThat(mController.mDialogType).isEqualTo(
+ MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_needDialog_showDialog() {
+ mController.mNeedDialog = true;
+
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mFragmentManager).beginTransaction();
+ }
+
+ @Test
+ public void onPreferenceChange_needDialog_doNothing() {
+ doReturn(true).when(mTelephonyManager).isDataEnabled();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(1).when(mTelephonyManager).getSimCount();
+
+ mController.onPreferenceChange(mPreference, true);
+
+ verify(mTelephonyManager, never()).setDataEnabled(true);
+ }
+
+ @Test
+ public void onPreferenceChange_notNeedDialog_update() {
+ doReturn(true).when(mTelephonyManager).isDataEnabled();
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
+ doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
+ doReturn(2).when(mTelephonyManager).getSimCount();
+
+ mController.onPreferenceChange(mPreference, true);
+
+ verify(mTelephonyManager).setDataEnabled(true);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
new file mode 100644
index 0000000..c03fb71
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.google.common.truth.Truth.assertThat;
+
+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;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.provider.Settings;
+import android.telecom.PhoneAccountHandle;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class MobileNetworkUtilsTest {
+ private static final String PACKAGE_NAME = "com.android.app";
+ private static final int SUB_ID_1 = 1;
+ private static final int SUB_ID_2 = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mTelephonyManager2;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo1;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo2;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private PhoneAccountHandle mPhoneAccountHandle;
+ @Mock
+ private ComponentName mComponentName;
+ @Mock
+ private ResolveInfo mResolveInfo;
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID_1);
+ doReturn(mTelephonyManager2).when(mTelephonyManager).createForSubscriptionId(SUB_ID_2);
+ doReturn(mPackageManager).when(mContext).getPackageManager();
+ doReturn(mComponentName).when(mPhoneAccountHandle).getComponentName();
+ doReturn(PACKAGE_NAME).when(mComponentName).getPackageName();
+
+ doReturn(SUB_ID_1).when(mSubscriptionInfo1).getSubscriptionId();
+ doReturn(SUB_ID_2).when(mSubscriptionInfo2).getSubscriptionId();
+
+ doReturn(Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)).when(
+ mSubscriptionManager).getActiveSubscriptionInfoList();
+ }
+
+ @Test
+ public void setMobileDataEnabled_setEnabled_enabled() {
+ MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_1, true, false);
+
+ verify(mTelephonyManager).setDataEnabled(true);
+ verify(mTelephonyManager2, never()).setDataEnabled(anyBoolean());
+ }
+
+ @Test
+ public void setMobileDataEnabled_setDisabled_disabled() {
+ MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_2, true, false);
+
+ verify(mTelephonyManager2).setDataEnabled(true);
+ verify(mTelephonyManager, never()).setDataEnabled(anyBoolean());
+ }
+
+ @Test
+ public void setMobileDataEnabled_disableOtherSubscriptions() {
+ MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_1, true, true);
+
+ verify(mTelephonyManager).setDataEnabled(true);
+ verify(mTelephonyManager2).setDataEnabled(false);
+ }
+
+ @Test
+ public void buildConfigureIntent_nullHandle_returnNull() {
+ assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, null)).isNull();
+ }
+
+ @Test
+ public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
+ doReturn(new ArrayList<ResolveInfo>()).when(mPackageManager).queryIntentActivities(
+ nullable(Intent.class), anyInt());
+
+ assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
+ mPhoneAccountHandle)).isNull();
+ }
+
+ @Test
+ public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
+ doReturn(Arrays.asList(mResolveInfo)).when(mPackageManager).queryIntentActivities(
+ nullable(Intent.class), anyInt());
+
+ assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
+ mPhoneAccountHandle)).isNotNull();
+ }
+
+ @Test
+ public void isCdmaOptions_phoneTypeCdma_returnTrue() {
+ doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
+
+ assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
+ }
+
+ @Test
+ public void isCdmaOptions_worldModeWithGsmWcdma_returnTrue() {
+ doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
+ doReturn("true").when(mContext).getString(R.string.config_world_mode);
+ Settings.Global.putInt(mContext.getContentResolver(),
+ android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
+ TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+
+ assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileSettingsActivityTest.java
similarity index 85%
rename from tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java
rename to tests/robotests/src/com/android/settings/network/telephony/MobileSettingsActivityTest.java
index cb86d6f..c5ca427 100644
--- a/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileSettingsActivityTest.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.settings.mobilenetwork;
+package com.android.settings.network.telephony;
-import static com.android.settings.mobilenetwork.MobileSettingsActivity.MOBILE_SETTINGS_TAG;
+import static com.android.settings.network.telephony.MobileSettingsActivity.MOBILE_SETTINGS_TAG;
import static com.google.common.truth.Truth.assertThat;
@@ -25,11 +25,16 @@
import static org.mockito.Mockito.verify;
import android.content.Context;
+import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.view.Menu;
import android.view.View;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+
import com.android.internal.view.menu.ContextMenuBuilder;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -41,15 +46,12 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class MobileSettingsActivityTest {
@@ -120,7 +122,7 @@
@Test
public void switchFragment_hidePreviousFragment() {
- mMobileSettingsActivity.mPrevSubscriptionId = PREV_SUB_ID;
+ mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.switchFragment(mShowFragment, CURRENT_SUB_ID);
@@ -129,7 +131,7 @@
@Test
public void switchFragment_fragmentExist_showItWithArguments() {
- mMobileSettingsActivity.mPrevSubscriptionId = PREV_SUB_ID;
+ mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.switchFragment(mShowFragment, CURRENT_SUB_ID);
@@ -137,4 +139,17 @@
MobileSettingsActivity.KEY_SUBSCRIPTION_ID)).isEqualTo(CURRENT_SUB_ID);
verify(mFragmentTransaction).show(mShowFragment);
}
+
+ @Test
+ public void onSaveInstanceState_saveCurrentSubId() {
+ mMobileSettingsActivity = Robolectric.buildActivity(
+ MobileSettingsActivity.class).get();
+ mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
+ final Bundle bundle = new Bundle();
+
+ mMobileSettingsActivity.saveInstanceState(bundle);
+
+ assertThat(bundle.getInt(MobileSettingsActivity.KEY_CUR_SUBSCRIPTION_ID)).isEqualTo(
+ PREV_SUB_ID);
+ }
}
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
new file mode 100644
index 0000000..2046237
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/cdma/CdmaSystemSelectPreferenceControllerTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony.cdma;
+
+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 android.content.Context;
+import android.provider.Settings;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.preference.ListPreference;
+import androidx.preference.PreferenceManager;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class CdmaSystemSelectPreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private PreferenceManager mPreferenceManager;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mInvalidTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+
+ private CdmaSystemSelectPreferenceController mController;
+ private ListPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+ doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ mPreference = new ListPreference(mContext);
+ mController = new CdmaSystemSelectPreferenceController(mContext, "mobile_data");
+ mController.init(mPreferenceManager, SUB_ID);
+ mController.mPreference = mPreference;
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void onPreferenceChange_selectHome_returnHomeMode() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_ANY);
+ doReturn(true).when(mTelephonyManager).setCdmaRoamingMode(anyInt());
+
+ mController.onPreferenceChange(mPreference,
+ Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_HOME));
+
+ assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_ANY)).isEqualTo(
+ TelephonyManager.CDMA_ROAMING_MODE_HOME);
+ }
+
+ @Test
+ public void updateState_stateHome_displayHome() {
+ doReturn(TelephonyManager.CDMA_ROAMING_MODE_HOME).when(
+ mTelephonyManager).getCdmaRoamingMode();
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getValue()).isEqualTo(
+ Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_HOME));
+ }
+
+ @Test
+ public void updateState_stateOther_resetToDefault() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_HOME);
+ doReturn(TelephonyManager.CDMA_ROAMING_MODE_AFFILIATED).when(
+ mTelephonyManager).getCdmaRoamingMode();
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getValue()).isEqualTo(
+ Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
+ assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.CDMA_ROAMING_MODE,
+ TelephonyManager.CDMA_ROAMING_MODE_HOME)).isEqualTo(
+ TelephonyManager.CDMA_ROAMING_MODE_ANY);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
index bfc5c42..ee51317 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
@@ -20,14 +20,9 @@
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 android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.provider.Settings;
import androidx.slice.Slice;
@@ -58,12 +53,7 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index 7b66a6b..adb5e43 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -44,7 +44,7 @@
@Before
public void setUp() {
FakeFeatureFactory.setupForTest();
- mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
+ mActivity = Robolectric.setupActivity(Activity.class);
mProvider = spy(new SearchFeatureProviderImpl());
}
@@ -54,6 +54,8 @@
// Should not crash.
final Toolbar toolbar = new Toolbar(mActivity);
+ // This ensures navigationView is created.
+ toolbar.setNavigationContentDescription("test");
mProvider.initSearchToolbar(mActivity, toolbar);
toolbar.performClick();
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 16e9cb7..f9cc427 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -18,7 +18,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.doReturn;
import static org.mockito.Mockito.spy;
@@ -27,7 +26,6 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.net.Uri;
import android.provider.Settings;
import android.provider.SettingsSlicesContract;
@@ -81,15 +79,10 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
+ mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mLoggingArgumentCatpor = ArgumentCaptor.forClass(Pair.class);
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
-
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index a68c5d3..bd21cdc 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -30,18 +30,12 @@
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
-import org.robolectric.res.StyleData;
-import org.robolectric.res.StyleResolver;
-import org.robolectric.res.ThemeStyleSet;
import org.robolectric.shadows.ShadowAssetManager;
import org.robolectric.shadows.ShadowResources;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
import org.w3c.dom.Node;
-import java.util.List;
-import java.util.Map;
-
/**
* Shadow Resources and Theme classes to handle resource references that Robolectric shadows cannot
* handle because they are too new or private.
@@ -207,46 +201,10 @@
if (attributeValue.contains("attr/fingerprint_layout_theme")) {
// Workaround for https://github.com/robolectric/robolectric/issues/2641
node.setNodeValue("@style/FingerprintLayoutTheme");
- } else if (attributeValue.startsWith("@*android:string")) {
- node.setNodeValue("PLACEHOLDER");
- } else if (attributeValue.startsWith("@*android:dimen")) {
- node.setNodeValue("321dp");
- } else if (attributeValue.startsWith("@*android:drawable")) {
- node.setNodeValue("");
}
}
}
}
-
- // Track down all styles and remove all inheritance from private styles.
- final Map<Long, Object /* NativeTheme */> appliedStylesList =
- ReflectionHelpers.getField(mAssetManager, "nativeThemes");
- synchronized (appliedStylesList) {
- for (Long idx : appliedStylesList.keySet()) {
- final ThemeStyleSet appliedStyles = ReflectionHelpers.getField(
- appliedStylesList.get(idx), "themeStyleSet");
- // The Object's below are actually ShadowAssetManager.OverlayedStyle.
- // We can't use
-
- // it here because it's private.
- final List<Object /* OverlayedStyle */> overlayedStyles =
- ReflectionHelpers.getField(appliedStyles, "styles");
- for (Object appliedStyle : overlayedStyles) {
- final StyleResolver styleResolver = ReflectionHelpers.getField(appliedStyle,
- "style");
- final List<StyleData> styleDatas =
- ReflectionHelpers.getField(styleResolver, "styles");
- for (StyleData styleData : styleDatas) {
- if (styleData.getParent() != null &&
- styleData.getParent().startsWith("@*android:style")) {
- ReflectionHelpers.setField(StyleData.class, styleData, "parent",
- null);
- }
- }
- }
-
- }
- }
return super.obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowKeyValueListParser.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowKeyValueListParser.java
deleted file mode 100644
index 5dce990..0000000
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowKeyValueListParser.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.testutils.shadow;
-
-import android.util.KeyValueListParser;
-
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-
-/**
- * Shadow for {@link KeyValueListParser} so we could implement
- * {@link #getBoolean(String, boolean)} that doesn't support in the current
- * robolectric
- */
-@Implements(KeyValueListParser.class)
-public class ShadowKeyValueListParser {
-
- @Implementation
- public boolean getBoolean(String key, boolean defaultValue) {
- return defaultValue;
- }
-}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index 3266a7f..bb691cb 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -89,6 +89,16 @@
}
@Implementation
+ public List<UserHandle> getUserProfiles(){
+ int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
+ List<UserHandle> result = new ArrayList<>(userIds.length);
+ for (int userId : userIds) {
+ result.add(UserHandle.of(userId));
+ }
+ return result;
+ }
+
+ @Implementation
public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
return userHandle;
}
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
index dda5d8f..742c8ad 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
@@ -19,13 +19,8 @@
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 android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.net.wifi.WifiManager;
import androidx.core.graphics.drawable.IconCompat;
@@ -56,12 +51,7 @@
@Before
public void setUp() {
- mContext = spy(RuntimeEnvironment.application);
-
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
+ mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
index 7e87711..ae4c753 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
@@ -23,7 +23,6 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -33,7 +32,6 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.telephony.CarrierConfigManager;
import androidx.slice.Slice;
@@ -88,7 +86,7 @@
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
+ mContext = RuntimeEnvironment.application;
//setup for SettingsSliceProvider tests
mProvider = spy(new SettingsSliceProvider());
@@ -104,11 +102,6 @@
when(mSlicesFeatureProvider.getCustomSliceManager(any(Context.class)))
.thenReturn(manager);
- // Prevent crash in SliceMetadata.
- Resources resources = spy(mContext.getResources());
- doReturn(60).when(resources).getDimensionPixelSize(anyInt());
- doReturn(resources).when(mContext).getResources();
-
mWfcSliceHelper = new FakeWifiCallingSliceHelper(mContext);
// Set-up specs for SliceMetadata.
diff --git a/tests/unit/src/com/android/settings/homepage/CardContentLoaderTest.java b/tests/unit/src/com/android/settings/homepage/CardContentLoaderTest.java
new file mode 100644
index 0000000..1f762bb
--- /dev/null
+++ b/tests/unit/src/com/android/settings/homepage/CardContentLoaderTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.homepage;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public class CardContentLoaderTest {
+
+ private Context mContext;
+ private CardContentLoader mCardContentLoader;
+
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getTargetContext();
+ mCardContentLoader = new CardContentLoader(mContext);
+ }
+
+ @Test
+ public void filter_twoInvalidCards_shouldReturnOneCard() {
+ final String sliceUri1 = "content://com.android.settings.slices/action/flashlight"; //valid
+ final String sliceUri2 = "content://com.android.settings.test.slices/action/flashlight";
+ final String sliceUri3 = "cotent://com.android.settings.slices/action/flashlight";
+
+ final List<ContextualCard> cards = new ArrayList<>();
+ cards.add(getContextualCard(sliceUri1));
+ cards.add(getContextualCard(sliceUri2));
+ cards.add(getContextualCard(sliceUri3));
+
+ final List<ContextualCard> result = mCardContentLoader.filter(cards);
+
+ assertThat(result).hasSize(1);
+ }
+
+ private ContextualCard getContextualCard(String sliceUri) {
+ return new ContextualCard.Builder()
+ .setName("test_card")
+ .setCardType(ContextualCard.CardType.SLICE)
+ .setSliceUri(sliceUri)
+ .build();
+ }
+}