Merge "Change search fab to search bar."
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/res/values/strings.xml b/res/values/strings.xml
index 9843b80..b52bfea 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10088,7 +10088,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/xml/network_setting_fragment.xml b/res/xml/network_setting_fragment.xml
index c383ab6..396f2e4 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.mobilenetwork.MobileDataPreferenceController"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="button_roaming_key"
diff --git a/src/com/android/settings/MonitoringCertInfoActivity.java b/src/com/android/settings/MonitoringCertInfoActivity.java
index 6785b4b..eadebc1 100644
--- a/src/com/android/settings/MonitoringCertInfoActivity.java
+++ b/src/com/android/settings/MonitoringCertInfoActivity.java
@@ -46,10 +46,17 @@
mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ final UserHandle user;
+ if (mUserId == UserHandle.USER_NULL) {
+ user = null;
+ } else {
+ user = UserHandle.of(mUserId);
+ }
+
DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
final int numberOfCertificates = getIntent().getIntExtra(
Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1);
- final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, mUserId) != null
+ final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, user) != null
? R.plurals.ssl_ca_cert_settings_button // Check certificate
: R.plurals.ssl_ca_cert_dialog_title; // Trust or remove certificate
final CharSequence title = getResources().getQuantityText(titleId, numberOfCertificates);
diff --git a/src/com/android/settings/RestrictedSettingsFragment.java b/src/com/android/settings/RestrictedSettingsFragment.java
index df438d5..13bc9c51 100644
--- a/src/com/android/settings/RestrictedSettingsFragment.java
+++ b/src/com/android/settings/RestrictedSettingsFragment.java
@@ -222,8 +222,8 @@
public EnforcedAdmin getRestrictionEnforcedAdmin() {
mEnforcedAdmin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(getActivity(),
mRestrictionKey, UserHandle.myUserId());
- if (mEnforcedAdmin != null && mEnforcedAdmin.userId == UserHandle.USER_NULL) {
- mEnforcedAdmin.userId = UserHandle.myUserId();
+ if (mEnforcedAdmin != null && mEnforcedAdmin.user == null) {
+ mEnforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
return mEnforcedAdmin;
}
diff --git a/src/com/android/settings/TrustedCredentialsDialogBuilder.java b/src/com/android/settings/TrustedCredentialsDialogBuilder.java
index 6fd846d..806da92 100644
--- a/src/com/android/settings/TrustedCredentialsDialogBuilder.java
+++ b/src/com/android/settings/TrustedCredentialsDialogBuilder.java
@@ -229,7 +229,7 @@
&& !mDpm.isCaCertApproved(certHolder.getAlias(), certHolder.getUserId());
final boolean isProfileOrDeviceOwner = RestrictedLockUtils.getProfileOrDeviceOwner(
- mActivity, certHolder.getUserId()) != null;
+ mActivity, UserHandle.of(certHolder.getUserId())) != null;
// Show trust button only when it requires consumer user (non-PO/DO) to approve
CharSequence displayText = mActivity.getText(!isProfileOrDeviceOwner && mNeedsApproval
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/dashboard/RestrictedDashboardFragment.java b/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
index ca30247..f43445b 100644
--- a/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
+++ b/src/com/android/settings/dashboard/RestrictedDashboardFragment.java
@@ -215,8 +215,8 @@
public EnforcedAdmin getRestrictionEnforcedAdmin() {
mEnforcedAdmin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(getActivity(),
mRestrictionKey, UserHandle.myUserId());
- if (mEnforcedAdmin != null && mEnforcedAdmin.userId == UserHandle.USER_NULL) {
- mEnforcedAdmin.userId = UserHandle.myUserId();
+ if (mEnforcedAdmin != null && mEnforcedAdmin.user == null) {
+ mEnforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
return mEnforcedAdmin;
}
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/enterprise/ActionDisabledByAdminDialog.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java
index 104b216..1142766 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java
@@ -53,12 +53,18 @@
@androidx.annotation.VisibleForTesting
EnforcedAdmin getAdminDetailsFromIntent(Intent intent) {
- final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.myUserId());
+ final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.of(UserHandle.myUserId()));
if (intent == null) {
return admin;
}
admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
- admin.userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+
+ int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ if (userId == UserHandle.USER_NULL) {
+ admin.user = null;
+ } else {
+ admin.user = UserHandle.of(userId);
+ }
return admin;
}
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index ac1939c..f5010f9 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.UserIdInt;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
@@ -60,6 +61,14 @@
mActivity = activity;
}
+ private @UserIdInt int getEnforcementAdminUserId() {
+ if (mEnforcedAdmin.user == null) {
+ return UserHandle.USER_NULL;
+ } else {
+ return mEnforcedAdmin.user.getIdentifier();
+ }
+ }
+
public AlertDialog.Builder prepareDialogBuilder(String restriction,
EnforcedAdmin enforcedAdmin) {
mEnforcedAdmin = enforcedAdmin;
@@ -68,7 +77,7 @@
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
mDialogView = (ViewGroup) LayoutInflater.from(builder.getContext()).inflate(
R.layout.admin_support_details_dialog, null);
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
mRestriction);
return builder
.setPositiveButton(R.string.okay, null)
@@ -86,7 +95,7 @@
}
mEnforcedAdmin = admin;
mRestriction = restriction;
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
mRestriction);
}
@@ -108,7 +117,15 @@
}
setAdminSupportTitle(root, restriction);
- setAdminSupportDetails(mActivity, root, new EnforcedAdmin(admin, userId));
+
+ final UserHandle user;
+ if (userId == UserHandle.USER_NULL) {
+ user = null;
+ } else {
+ user = UserHandle.of(userId);
+ }
+
+ setAdminSupportDetails(mActivity, root, new EnforcedAdmin(admin, user));
}
@VisibleForTesting
@@ -152,20 +169,27 @@
if (enforcedAdmin == null || enforcedAdmin.component == null) {
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, enforcedAdmin.userId)) {
+ activity, userId)) {
enforcedAdmin.component = null;
} else {
- if (enforcedAdmin.userId == UserHandle.USER_NULL) {
- enforcedAdmin.userId = UserHandle.myUserId();
+ if (enforcedAdmin.user == null) {
+ enforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
CharSequence supportMessage = null;
if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
- supportMessage = dpm.getShortSupportMessageForUser(
- enforcedAdmin.component, enforcedAdmin.userId);
+ supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component, userId);
}
if (supportMessage != null) {
final TextView textView = root.findViewById(R.id.admin_support_msg);
@@ -183,8 +207,7 @@
enforcedAdmin.component);
intent.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
// DeviceAdminAdd class may need to run as managed profile.
- activity.startActivityAsUser(intent,
- new UserHandle(enforcedAdmin.userId));
+ activity.startActivityAsUser(intent, enforcedAdmin.user);
} else {
intent.setClass(activity, Settings.DeviceAdminSettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
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/mobilenetwork/MobileDataDialogFragment.java b/src/com/android/settings/mobilenetwork/MobileDataDialogFragment.java
new file mode 100644
index 0000000..86a5518
--- /dev/null
+++ b/src/com/android/settings/mobilenetwork/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.mobilenetwork;
+
+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/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/MobileDataPreferenceController.java b/src/com/android/settings/mobilenetwork/MobileDataPreferenceController.java
new file mode 100644
index 0000000..c341d7e
--- /dev/null
+++ b/src/com/android/settings/mobilenetwork/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.mobilenetwork;
+
+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/mobilenetwork/MobileNetworkFragment.java
index d8df8fa..716a496 100644
--- a/src/com/android/settings/mobilenetwork/MobileNetworkFragment.java
+++ b/src/com/android/settings/mobilenetwork/MobileNetworkFragment.java
@@ -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;
@@ -61,8 +62,11 @@
import com.android.settings.search.Indexable;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -156,7 +160,6 @@
private Preference mWiFiCallingPref;
private SwitchPreference mVideoCallingPref;
private NetworkSelectListPreference mButtonNetworkSelect;
- private MobileDataPreference mMobileDataPref;
private DataUsagePreference mDataUsagePref;
private static final String iface = "rmnet0"; //TODO: this will go away
@@ -238,6 +241,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 +304,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 +390,15 @@
}
@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);
+ }
+
+ @Override
public void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate:+");
super.onCreate(icicle);
@@ -407,7 +422,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 +453,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 +503,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 +571,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 +610,6 @@
return;
}
- prefSet.removeAll();
-
updateBodyBasicFields(activity, prefSet, mSubId, hasActiveSubscriptions);
if (hasActiveSubscriptions) {
@@ -1075,6 +1074,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;
@@ -1751,8 +1751,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 +1862,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/mobilenetwork/MobileNetworkUtils.java b/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java
index 2109375..44b1cef 100644
--- a/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java
+++ b/src/com/android/settings/mobilenetwork/MobileNetworkUtils.java
@@ -22,13 +22,14 @@
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;
@@ -170,4 +171,30 @@
//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);
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java b/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java
index 37a180c..4442ddf 100644
--- a/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java
+++ b/src/com/android/settings/mobilenetwork/MobileSettingsActivity.java
@@ -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/RoamingDialogFragment.java b/src/com/android/settings/mobilenetwork/RoamingDialogFragment.java
index 6f71d9c..794b993 100644
--- a/src/com/android/settings/mobilenetwork/RoamingDialogFragment.java
+++ b/src/com/android/settings/mobilenetwork/RoamingDialogFragment.java
@@ -60,7 +60,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/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/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
index 6c78c65..fe10d3e 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java
@@ -31,6 +31,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.UserHandle;
import android.os.UserManager;
import android.view.View;
@@ -67,7 +68,8 @@
@BeforeClass
public static void beforeClass() {
- sFakeEnforcedAdmin = new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+ sFakeEnforcedAdmin = new EnforcedAdmin(new ComponentName("test.package", "test.Class"),
+ UserHandle.of(10));
}
@Mock
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
index bfbdd7f..faab3bd 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothSliceBuilderTest.java
@@ -19,14 +19,11 @@
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;
@@ -61,11 +58,6 @@
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();
-
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
@@ -98,4 +90,4 @@
assertThat(adapter.isEnabled()).isTrue();
}
-}
\ No newline at end of file
+}
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/enterprise/ActionDisabledByAdminDialogHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
index 9b138a6..0a265a1 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelperTest.java
@@ -27,6 +27,7 @@
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.Process;
+import android.os.UserHandle;
import android.os.UserManager;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -76,7 +77,7 @@
final int userId = 123;
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, userId);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(userId));
mHelper.showAdminPolicies(admin, mActivity);
@@ -90,7 +91,7 @@
@Test
public void testShowAdminPoliciesWithoutComponent() {
final int userId = 123;
- final EnforcedAdmin admin = new EnforcedAdmin(null, userId);
+ final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.of(userId));
mHelper.showAdminPolicies(admin, mActivity);
final Intent intent = mActivityShadow.getNextStartedActivity();
assertEquals(intent.getComponent(), new ComponentName(mActivity,
@@ -146,7 +147,7 @@
final ViewGroup view = new FrameLayout(mActivity);
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
final TextView textView = new TextView(mActivity);
textView.setId(R.id.admin_support_msg);
@@ -169,7 +170,7 @@
final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
dpmShadow.setIsAdminActiveAsUser(false);
diff --git a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java
index ebdfad6..e016a06 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ActionDisabledByAdminDialogTest.java
@@ -43,7 +43,7 @@
public void testGetAdminDetailsFromIntent() {
final int userId = 123;
final ComponentName component = new ComponentName("com.some.package", ".SomeClass");
- final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, userId);
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, UserHandle.of(userId));
final Intent intent = new Intent();
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component);
@@ -54,7 +54,7 @@
@Test
public void testGetAdminDetailsFromNullIntent() {
final int userId = UserHandle.myUserId();
- final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, userId);
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, UserHandle.of(userId));
Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(null));
}
diff --git a/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java b/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
index 07296e6..6bea031 100644
--- a/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/flashlight/FlashlightSliceBuilderTest.java
@@ -19,12 +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.content.Context;
-import android.content.res.Resources;
import android.provider.Settings;
import androidx.slice.Slice;
@@ -55,11 +52,6 @@
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();
-
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
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..c0af3d8 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;
@@ -60,11 +58,6 @@
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();
-
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
diff --git a/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
index 65b2e87..90222ca 100644
--- a/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
@@ -2,12 +2,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.content.Context;
-import android.content.res.Resources;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -37,11 +34,6 @@
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();
-
// 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/mobilenetwork/Enhanced4gLteSliceHelperTest.java
index 6d98381..1943b36 100644
--- a/tests/robotests/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/mobilenetwork/Enhanced4gLteSliceHelperTest.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.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;
@@ -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/mobilenetwork/MobileDataPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/mobilenetwork/MobileDataPreferenceControllerTest.java
new file mode 100644
index 0000000..9bf9b54
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/mobilenetwork/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.mobilenetwork;
+
+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/mobilenetwork/MobileNetworkUtilsTest.java b/tests/robotests/src/com/android/settings/mobilenetwork/MobileNetworkUtilsTest.java
new file mode 100644
index 0000000..2b21f1f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/mobilenetwork/MobileNetworkUtilsTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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 org.mockito.ArgumentMatchers.anyBoolean;
+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 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.Arrays;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class MobileNetworkUtilsTest {
+ 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;
+
+ 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(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);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java b/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java
index cb86d6f..b18676f 100644
--- a/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/mobilenetwork/MobileSettingsActivityTest.java
@@ -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/notification/ZenModeSliceBuilderTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
index bfc5c42..6c43736 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSliceBuilderTest.java
@@ -20,14 +20,11 @@
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;
@@ -60,11 +57,6 @@
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();
-
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 16e9cb7..078186a 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;
@@ -85,11 +83,6 @@
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/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/wifi/WifiSliceTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
index dda5d8f..5a2f546 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSliceTest.java
@@ -19,13 +19,10 @@
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;
@@ -58,11 +55,6 @@
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();
-
// 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..c5c4b67 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;
@@ -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.