diff --git a/res/values/strings.xml b/res/values/strings.xml
index 646a3eea602..2cd78066425 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -11424,15 +11424,6 @@
Use Wi\u2011Fi for calls to improve quality
-
- Backup calling
-
-
- If %1$s is unavailable or roaming, use your mobile data SIM for %1$s calls.
-
-
- backup calling
-
Incoming MMS message
diff --git a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
deleted file mode 100644
index 4f64399f524..00000000000
--- a/src/com/android/settings/network/telephony/BackupCallingPreferenceController.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network.telephony;
-
-import android.content.Context;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.ims.ImsException;
-import android.telephony.ims.ImsManager;
-import android.telephony.ims.ImsMmTelManager;
-import android.util.Log;
-
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.R;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.network.ims.WifiCallingQueryImsState;
-
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Preference controller for "Backup Calling"
- **/
-public class BackupCallingPreferenceController extends TelephonyTogglePreferenceController {
-
- private static final String LOG_TAG = "BackupCallingPrefCtrl";
-
- private Preference mPreference;
-
- /**
- * Class constructor of backup calling.
- *
- * @param context of settings
- * @param key assigned within UI entry of XML file
- **/
- public BackupCallingPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- /**
- * Initialization based on given subscription id.
- *
- * @param subId is the subscription id
- * @return this instance after initialization
- **/
- public BackupCallingPreferenceController init(int subId) {
- mSubId = subId;
- return this;
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- if (!hasBackupCallingFeature(subId)) {
- return CONDITIONALLY_UNAVAILABLE;
- }
- List subIdList = getActiveSubscriptionList();
- SubscriptionInfo subInfo = getSubscriptionInfoFromList(subIdList, subId);
- if (subInfo == null) { // given subId is not actives
- return CONDITIONALLY_UNAVAILABLE;
- }
- return (subIdList.size() > 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- /**
- * Implementation of abstract methods
- **/
- public boolean setChecked(boolean isChecked) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
- if (imsMmTelMgr == null) {
- return false;
- }
- try {
- imsMmTelMgr.setCrossSimCallingEnabled(isChecked);
- } catch (ImsException exception) {
- Log.w(LOG_TAG, "fail to change cross SIM calling configuration: " + isChecked,
- exception);
- return false;
- }
- return true;
- }
-
- /**
- * Implementation of abstract methods
- **/
- public boolean isChecked() {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(mSubId);
- if (imsMmTelMgr == null) {
- return false;
- }
- try {
- return imsMmTelMgr.isCrossSimCallingEnabled();
- } catch (ImsException exception) {
- Log.w(LOG_TAG, "fail to get cross SIM calling configuration", exception);
- }
- return false;
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- if ((preference == null) || (!(preference instanceof SwitchPreference))) {
- return;
- }
- SubscriptionInfo subInfo = getSubscriptionInfoFromActiveList(mSubId);
-
- mPreference = preference;
-
- final SwitchPreference switchPreference = (SwitchPreference) preference;
- switchPreference.setChecked((subInfo != null) ? isChecked() : false);
-
- updateSummary(getLatestSummary(subInfo));
- }
-
- private String getLatestSummary(SubscriptionInfo subInfo) {
- return Objects.toString((subInfo == null) ? null
- : SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext), "");
- }
-
- private void updateSummary(String displayName) {
- Preference preference = mPreference;
- if (preference == null) {
- return;
- }
- String summary = displayName;
- String finalText = String.format(
- getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
- summary)
- .toString();
- preference.setSummary(finalText);
- }
-
- private boolean hasBackupCallingFeature(int subscriptionId) {
- return isCrossSimEnabledByPlatform(mContext, subscriptionId);
- }
-
- protected boolean isCrossSimEnabledByPlatform(Context context, int subscriptionId) {
- // TODO : Change into API which created for accessing
- // com.android.ims.ImsManager#isCrossSimEnabledByPlatform()
- if ((new WifiCallingQueryImsState(context, subscriptionId)).isWifiCallingSupported()) {
- PersistableBundle bundle = getCarrierConfigForSubId(subscriptionId);
- return (bundle != null) && bundle.getBoolean(
- CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false /*default*/);
- }
- Log.d(LOG_TAG, "Not supported by framework. subId = " + subscriptionId);
- return false;
- }
-
- private ImsMmTelManager getImsMmTelManager(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
- return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(subId);
- }
-
- private List getActiveSubscriptionList() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- return SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- }
-
- private SubscriptionInfo getSubscriptionInfoFromList(
- List subInfoList, int subId) {
- for (SubscriptionInfo subInfo : subInfoList) {
- if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
- return subInfo;
- }
- }
- return null;
- }
-
- private SubscriptionInfo getSubscriptionInfoFromActiveList(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- return getSubscriptionInfoFromList(getActiveSubscriptionList(), subId);
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java
deleted file mode 100644
index 58dd18f2c62..00000000000
--- a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroup.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.network.telephony;
-
-import static androidx.lifecycle.Lifecycle.Event;
-
-import android.content.Context;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-import android.telephony.ims.ImsException;
-import android.telephony.ims.ImsManager;
-import android.telephony.ims.ImsMmTelManager;
-import android.util.ArrayMap;
-import android.util.Log;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.LifecycleObserver;
-import androidx.lifecycle.OnLifecycleEvent;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.R;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settings.network.SubscriptionsChangeListener;
-import com.android.settings.network.ims.WifiCallingQueryImsState;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Preference controller for "Backup Calling"
- **/
-public class NetworkProviderBackupCallingGroup extends
- TelephonyTogglePreferenceController implements LifecycleObserver,
- SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
- private static final String TAG = "NetworkProviderBackupCallingGroup";
- private static final String KEY_PREFERENCE_BACKUPCALLING_GROUP =
- "provider_model_backup_call_group";
- private static final int PREF_START_ORDER = 10;
-
- private String mPreferenceGroupKey;
- private PreferenceGroup mPreferenceGroup;
- private Map mBackupCallingForSubPreferences;
- private List mSubInfoListForBackupCall;
- private Map mTelephonyManagerList = new HashMap<>();
- private SubscriptionsChangeListener mSubscriptionsChangeListener;
-
- public NetworkProviderBackupCallingGroup(Context context, Lifecycle lifecycle,
- List subscriptionList, String preferenceGroupKey) {
- super(context, preferenceGroupKey);
- mPreferenceGroupKey = preferenceGroupKey;
- mSubInfoListForBackupCall = subscriptionList;
- mBackupCallingForSubPreferences = new ArrayMap<>();
- setSubscriptionInfoList(context);
- lifecycle.addObserver(this);
- }
-
- @OnLifecycleEvent(Event.ON_RESUME)
- public void onResume() {
- if (mSubscriptionsChangeListener == null) {
- mSubscriptionsChangeListener = new SubscriptionsChangeListener(mContext, this);
- }
- mSubscriptionsChangeListener.start();
- }
-
- @OnLifecycleEvent(Event.ON_PAUSE)
- public void onPause() {
- if (mSubscriptionsChangeListener != null) {
- mSubscriptionsChangeListener.stop();
- }
- }
-
- @Override
- public int getAvailabilityStatus(int subId) {
- if (mSubInfoListForBackupCall == null
- || getSubscriptionInfoFromList(mSubInfoListForBackupCall, subId) == null) {
- return CONDITIONALLY_UNAVAILABLE;
- }
-
- return (mSubInfoListForBackupCall.size() > 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- private boolean setCrossSimCallingEnabled(int subId, boolean checked) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(subId);
- if (imsMmTelMgr == null) {
- Log.d(TAG, "setCrossSimCallingEnabled(), ImsMmTelManager is null");
- return false;
- }
-
- try {
- imsMmTelMgr.setCrossSimCallingEnabled(checked);
- } catch (ImsException exception) {
- Log.w(TAG, "fail to get cross SIM calling configuration", exception);
- return false;
- }
- return true;
- }
-
- @Override
- public boolean setChecked(boolean checked) {
- return false;
- }
-
- private boolean isCrossSimCallingEnabled(int subId) {
- ImsMmTelManager imsMmTelMgr = getImsMmTelManager(subId);
- if (imsMmTelMgr == null) {
- Log.d(TAG, "isCrossSimCallingEnabled(), ImsMmTelManager is null");
- return false;
- }
- try {
- return imsMmTelMgr.isCrossSimCallingEnabled();
- } catch (ImsException exception) {
- Log.w(TAG, "fail to get cross SIM calling configuration", exception);
- }
- return false;
- }
-
- @Override
- public boolean isChecked() {
- return false;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- mPreferenceGroup = screen.findPreference(mPreferenceGroupKey);
- update();
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- // Do nothing in this case since preference is invisible
- if (preference == null) {
- return;
- }
- update();
- }
-
- private void update() {
- if (mPreferenceGroup == null) {
- return;
- }
-
- setSubscriptionInfoList(mContext);
- if (mSubInfoListForBackupCall == null || mSubInfoListForBackupCall.size() < 2) {
- for (SwitchPreference pref : mBackupCallingForSubPreferences.values()) {
- mPreferenceGroup.removePreference(pref);
- }
- mBackupCallingForSubPreferences.clear();
- return;
- }
-
- Map toRemovePreferences = mBackupCallingForSubPreferences;
- mBackupCallingForSubPreferences = new ArrayMap<>();
- setSubscriptionInfoForPreference(toRemovePreferences);
- }
-
- private void setSubscriptionInfoForPreference(
- Map toRemovePreferences) {
- int order = PREF_START_ORDER;
- for (SubscriptionInfo subInfo : mSubInfoListForBackupCall) {
- final int subId = subInfo.getSubscriptionId();
-
- SwitchPreference pref = toRemovePreferences.remove(subId);
- if (pref == null) {
- pref = new SwitchPreference(mPreferenceGroup.getContext());
- mPreferenceGroup.addPreference(pref);
- }
-
- CharSequence displayName = (subInfo == null) ? ""
- : SubscriptionUtil.getUniqueSubscriptionDisplayName(subInfo, mContext);
- pref.setTitle(displayName);
- pref.setOrder(order++);
- pref.setSummary(getSummary(displayName));
- boolean enabled = isCrossSimCallingEnabled(subId);
- pref.setChecked(enabled);
- pref.setOnPreferenceClickListener(clickedPref -> {
- setCrossSimCallingEnabled(subId, !enabled);
- return true;
- });
- mBackupCallingForSubPreferences.put(subId, pref);
- }
- }
-
- private String getSummary(CharSequence displayName) {
- String summary = String.format(
- getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
- displayName)
- .toString();
- return summary;
- }
-
- private void setSubscriptionInfoList(Context context) {
- if (mSubInfoListForBackupCall != null) {
- mSubInfoListForBackupCall.removeIf(info -> {
- int subId = info.getSubscriptionId();
- setTelephonyManagerForSubscriptionId(context, subId);
- if (!hasBackupCallingFeature(subId) && mSubInfoListForBackupCall.contains(info)) {
- return true;
- }
- return false;
- });
- } else {
- Log.d(TAG, "No active subscriptions");
- }
- }
-
- private void setTelephonyManagerForSubscriptionId(Context context, int subId) {
- TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(subId);
- mTelephonyManagerList.put(subId, telephonyManager);
- }
-
- @VisibleForTesting
- protected boolean hasBackupCallingFeature(int subscriptionId) {
- return isCrossSimEnabledByPlatform(mContext, subscriptionId);
- }
-
- /**
- * Copied from {@link BackupCallingPreferenceController}
- **/
- @VisibleForTesting
- protected boolean isCrossSimEnabledByPlatform(Context context, int subscriptionId) {
- // TODO : Change into API which created for accessing
- // com.android.ims.ImsManager#isCrossSimEnabledByPlatform()
- if ((new WifiCallingQueryImsState(context, subscriptionId)).isWifiCallingSupported()) {
- PersistableBundle bundle = getCarrierConfigForSubId(subscriptionId);
- return (bundle != null) && bundle.getBoolean(
- CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false /*default*/);
- }
- Log.d(TAG, "WifiCalling is not supported by framework. subId = " + subscriptionId);
- return false;
- }
-
- private ImsMmTelManager getImsMmTelManager(int subId) {
- if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
- return null;
- }
- ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
- return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(subId);
- }
-
- private SubscriptionInfo getSubscriptionInfoFromList(
- List subInfoList, int subId) {
- for (SubscriptionInfo subInfo : subInfoList) {
- if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
- return subInfo;
- }
- }
- return null;
- }
-
- @Override
- public String getPreferenceKey() {
- return KEY_PREFERENCE_BACKUPCALLING_GROUP;
- }
-
- @Override
- public void onAirplaneModeChanged(boolean airplaneModeEnabled) {}
-
- @Override
- public void onSubscriptionsChanged() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- mSubInfoListForBackupCall = SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- update();
- }
-}
diff --git a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java b/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
deleted file mode 100644
index 5c336efc507..00000000000
--- a/src/com/android/settings/network/telephony/NetworkProviderBackupCallingPreferenceController.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network.telephony;
-
-import android.content.Context;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.network.SubscriptionUtil;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-
-import java.util.List;
-
-/**
- * Preference controller for "Backup Calling" summary list
- */
-public class NetworkProviderBackupCallingPreferenceController extends
- BasePreferenceController implements LifecycleObserver {
-
- private static final String TAG = "NetProvBackupCallingCtrl";
- private static final String KEY_PREFERENCE_CATEGORY = "provider_model_backup_calling_category";
-
- private PreferenceCategory mPreferenceCategory;
- private PreferenceScreen mPreferenceScreen;
- private NetworkProviderBackupCallingGroup mNetworkProviderBackupCallingGroup;
- private List mSubscriptionList;
-
- /**
- * Preference controller for "Backup Calling" summary list
- */
- public NetworkProviderBackupCallingPreferenceController(Context context, String key) {
- super(context, key);
- }
-
- protected NetworkProviderBackupCallingGroup createBackupCallingControllerForSub(
- Lifecycle lifecycle, List subscriptionList) {
- return new NetworkProviderBackupCallingGroup(mContext, lifecycle, subscriptionList,
- KEY_PREFERENCE_CATEGORY);
- }
-
- /**
- * Initialize the binding with Lifecycle
- *
- * @param lifecycle Lifecycle of UI which owns this Preference
- */
- public void init(Lifecycle lifecycle) {
- mSubscriptionList = getActiveSubscriptionList();
- mNetworkProviderBackupCallingGroup = createBackupCallingControllerForSub(lifecycle,
- mSubscriptionList);
- }
-
- private List getActiveSubscriptionList() {
- SubscriptionManager subscriptionManager =
- mContext.getSystemService(SubscriptionManager.class);
- return SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
- }
-
- @Override
- public int getAvailabilityStatus() {
- if (mNetworkProviderBackupCallingGroup == null
- || mSubscriptionList == null
- || mSubscriptionList.size() < 2) {
- return CONDITIONALLY_UNAVAILABLE;
- } else {
- return AVAILABLE;
- }
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreferenceScreen = screen;
- mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY);
- mPreferenceCategory.setVisible(isAvailable());
- mNetworkProviderBackupCallingGroup.displayPreference(screen);
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java
deleted file mode 100644
index 4e110f0d018..00000000000
--- a/tests/unit/src/com/android/settings/network/telephony/BackupCallingPreferenceControllerTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.network.telephony;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.spy;
-
-import android.content.Context;
-
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.core.BasePreferenceController;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class BackupCallingPreferenceControllerTest {
- private static final int SUB_ID = 2;
-
- private BackupCallingPreferenceController mController;
- private Context mContext;
-
- @Before
- public void setUp() {
- mContext = spy(ApplicationProvider.getApplicationContext());
-
- mController = new BackupCallingPreferenceController(mContext, "backup_calling_key");
- mController.init(SUB_ID);
- }
-
- @Test
- public void controller_isUnavailable() {
- assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
- }
-}
diff --git a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java b/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java
deleted file mode 100644
index a5717ef519a..00000000000
--- a/tests/unit/src/com/android/settings/network/telephony/NetworkProviderBackupCallingGroupTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.network.telephony;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.os.Looper;
-import android.os.PersistableBundle;
-import android.telephony.CarrierConfigManager;
-import android.telephony.SubscriptionInfo;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
-import com.android.settings.network.CarrierConfigCache;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.List;
-
-@RunWith(AndroidJUnit4.class)
-public class NetworkProviderBackupCallingGroupTest {
-
- private static final int SUB_ID_1 = 1;
- private static final int SUB_ID_2 = 2;
-
- private static final String KEY_PREFERENCE_CATEGORY_BACKUP_CALLING =
- "provider_model_backup_calling_category";
- private static final String DISPLAY_NAME_1 = "Test Display Name 1";
- private static final String DISPLAY_NAME_2 = "Test Display Name 2";
-
- @Mock
- private PreferenceGroup mPreferenceGroup;
- @Mock
- private CarrierConfigCache mCarrierConfigCache;
- @Mock
- private Lifecycle mLifecycle;
- @Mock
- private SubscriptionManager mSubscriptionManager;
- @Mock
- private SubscriptionInfo mSubscriptionInfo1;
- @Mock
- private SubscriptionInfo mSubscriptionInfo2;
- @Mock
- private List mSubscriptionInfoList;
- @Mock
- private TelephonyManager mTelephonyManager1;
- @Mock
- private TelephonyManager mTelephonyManager2;
-
- @Mock
- private NetworkProviderBackupCallingGroup mNetworkProviderBackupCallingGroup;
- private Context mContext;
- private PersistableBundle mCarrierConfig;
- private PreferenceManager mPreferenceManager;
- private PreferenceScreen mPreferenceScreen;
- private SwitchPreference mSwitchPreference1;
- private SwitchPreference mSwitchPreference2;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager1);
- when(mTelephonyManager1.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager1);
- when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager2);
- when(mTelephonyManager2.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
- when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
- when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
- when(mSubscriptionInfo1.getDisplayName()).thenReturn(DISPLAY_NAME_1);
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
- mSubscriptionInfoList.add(mSubscriptionInfo1);
- when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
- when(mSubscriptionInfo2.getDisplayName()).thenReturn(DISPLAY_NAME_2);
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_2);
- mSubscriptionInfoList.add(mSubscriptionInfo2);
- when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
- mSubscriptionInfoList);
-
- CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
- mCarrierConfig = new PersistableBundle();
- doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_1);
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- true);
- doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_2);
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- true);
-
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
-
- mPreferenceManager = new PreferenceManager(mContext);
- mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
- when(mPreferenceGroup.getKey()).thenReturn(KEY_PREFERENCE_CATEGORY_BACKUP_CALLING);
- when(mPreferenceGroup.getPreferenceCount()).thenReturn(2);
- mPreferenceScreen.addPreference(mPreferenceGroup);
-
- mNetworkProviderBackupCallingGroup = spy(new NetworkProviderBackupCallingGroup(
- mContext, mLifecycle, mSubscriptionInfoList,
- KEY_PREFERENCE_CATEGORY_BACKUP_CALLING));
- }
-
- @Test
- public void shouldShowBackupCallingForSub_invalidSubId_returnFalse() {
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(
- SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(false);
- }
-
- @Test
- public void shouldShowBackupCallingForSub_carrierConfigIsUnavailable_returnFalse() {
- mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
- false);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(false);
- }
-
- @Test
- public void
- shouldShowBackupCallingForSub_crossSimDisabled_returnFalse() {
- doReturn(false).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(false);
- }
-
- @Test
- public void shouldBackupCallingForSub_crossSimEnabled_returnTrue() {
- doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
- mContext, SUB_ID_1);
-
- assertThat(mNetworkProviderBackupCallingGroup.hasBackupCallingFeature(SUB_ID_1))
- .isEqualTo(true);
- }
-}