[Settings] Do not creat multiple database
Bug: 254405469 Test: manual Change-Id: I96ea77899270439a87569bd1676d38b52dd36650
This commit is contained in:
@@ -101,7 +101,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
mInternetUpdater = new InternetUpdater(context, lifecycle, this);
|
mInternetUpdater = new InternetUpdater(context, lifecycle, this);
|
||||||
mInternetType = mInternetUpdater.getInternetType();
|
mInternetType = mInternetUpdater.getInternetType();
|
||||||
mLifecycleOwner = lifecycleOwner;
|
mLifecycleOwner = lifecycleOwner;
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,6 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
/** @OnLifecycleEvent(ON_PAUSE) */
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
@OnLifecycleEvent(ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mMobileNetworkRepository.removeRegister();
|
|
||||||
mSummaryHelper.register(false);
|
mSummaryHelper.register(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,22 +202,38 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateCellularSummary() {
|
void updateCellularSummary() {
|
||||||
CharSequence summary = null;
|
CharSequence summary = null;
|
||||||
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
|
SubscriptionInfoEntity activeSubInfo = null;
|
||||||
if (subInfo.isSubscriptionVisible && subInfo.isActiveDataSubscriptionId) {
|
SubscriptionInfoEntity defaultSubInfo = null;
|
||||||
summary = subInfo.uniqueName;
|
|
||||||
break;
|
for (SubscriptionInfoEntity subInfo : getSubscriptionInfoList()) {
|
||||||
} else if (subInfo.isDefaultDataSubscription) {
|
if (subInfo.isActiveDataSubscriptionId) {
|
||||||
summary = mContext.getString(
|
activeSubInfo = subInfo;
|
||||||
R.string.mobile_data_temp_using, subInfo.uniqueName);
|
}
|
||||||
|
if (subInfo.isDefaultDataSubscription) {
|
||||||
|
defaultSubInfo = subInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (activeSubInfo == null) {
|
||||||
if (summary == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
activeSubInfo = activeSubInfo.isSubscriptionVisible ? activeSubInfo : defaultSubInfo;
|
||||||
|
|
||||||
|
if (activeSubInfo.equals(defaultSubInfo)) {
|
||||||
|
// DDS is active
|
||||||
|
summary = activeSubInfo.uniqueName;
|
||||||
|
} else {
|
||||||
|
summary = mContext.getString(
|
||||||
|
R.string.mobile_data_temp_using, activeSubInfo.uniqueName);
|
||||||
|
}
|
||||||
|
|
||||||
mPreference.setSummary(summary);
|
mPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
||||||
|
return mSubInfoEntityList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||||
if ((mSubInfoEntityList != null &&
|
if ((mSubInfoEntityList != null &&
|
||||||
|
@@ -93,10 +93,15 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
private boolean mIsRemovable = false;
|
private boolean mIsRemovable = false;
|
||||||
private boolean mIsActive = false;
|
private boolean mIsActive = false;
|
||||||
|
|
||||||
MobileNetworkRepository(Context context, MobileNetworkCallback mobileNetworkCallback) {
|
public static MobileNetworkRepository create(Context context,
|
||||||
|
MobileNetworkCallback mobileNetworkCallback) {
|
||||||
|
return new MobileNetworkRepository(context, mobileNetworkCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MobileNetworkRepository(Context context, MobileNetworkCallback mobileNetworkCallback) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mCallback = mobileNetworkCallback;
|
mCallback = mobileNetworkCallback;
|
||||||
mMobileNetworkDatabase = MobileNetworkDatabase.createDatabase(context);
|
mMobileNetworkDatabase = MobileNetworkDatabase.getInstance(context);
|
||||||
mSubscriptionInfoDao = mMobileNetworkDatabase.mSubscriptionInfoDao();
|
mSubscriptionInfoDao = mMobileNetworkDatabase.mSubscriptionInfoDao();
|
||||||
mUiccInfoDao = mMobileNetworkDatabase.mUiccInfoDao();
|
mUiccInfoDao = mMobileNetworkDatabase.mUiccInfoDao();
|
||||||
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
||||||
@@ -194,6 +199,10 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
return mMobileNetworkInfoEntityList;
|
return mMobileNetworkInfoEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubscriptionInfoEntity getSubInfoById(String subId) {
|
||||||
|
return mSubscriptionInfoDao.querySubInfoById(subId);
|
||||||
|
}
|
||||||
|
|
||||||
public int getSubInfosCount() {
|
public int getSubInfosCount() {
|
||||||
return mSubscriptionInfoDao.count();
|
return mSubscriptionInfoDao.count();
|
||||||
}
|
}
|
||||||
@@ -439,7 +448,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
|||||||
* Callback for clients to get the latest info changes if the framework or content observers.
|
* Callback for clients to get the latest info changes if the framework or content observers.
|
||||||
* updates the relevant info.
|
* updates the relevant info.
|
||||||
*/
|
*/
|
||||||
interface MobileNetworkCallback {
|
public interface MobileNetworkCallback {
|
||||||
void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
||||||
|
|
||||||
void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList);
|
||||||
|
@@ -87,7 +87,7 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
|
||||||
mUserManager = context.getSystemService(UserManager.class);
|
mUserManager = context.getSystemService(UserManager.class);
|
||||||
mLifecycleOwner = lifecycleOwner;
|
mLifecycleOwner = lifecycleOwner;
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,6 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
|||||||
|
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
@OnLifecycleEvent(ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mMobileNetworkRepository.removeRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -71,7 +71,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
|
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
|
||||||
== View.LAYOUT_DIRECTION_RTL;
|
== View.LAYOUT_DIRECTION_RTL;
|
||||||
mLifecycleOwner = lifecycleOwner;
|
mLifecycleOwner = lifecycleOwner;
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,6 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
@OnLifecycleEvent(Event.ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mMobileNetworkRepository.removeRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -72,7 +72,7 @@ public class NetworkProviderDownloadedSimListController extends
|
|||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||||
mPreferences = new ArrayMap<>();
|
mPreferences = new ArrayMap<>();
|
||||||
mLifecycleOwner = lifecycleOwner;
|
mLifecycleOwner = lifecycleOwner;
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
|||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||||
mPreferences = new ArrayMap<>();
|
mPreferences = new ArrayMap<>();
|
||||||
mLifecycleOwner = lifecycleOwner;
|
mLifecycleOwner = lifecycleOwner;
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(context, this);
|
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -95,7 +95,7 @@ public class MobileNetworkSummaryControllerTest {
|
|||||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||||
doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
|
doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
|
||||||
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
|
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
|
||||||
mMobileNetworkRepository = new MobileNetworkRepository(mContext, mMobileNetworkCallback);
|
mMobileNetworkRepository = MobileNetworkRepository.create(mContext, mMobileNetworkCallback);
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
mMobileNetworkRepository.addRegister(mLifecycleOwner);
|
mMobileNetworkRepository.addRegister(mLifecycleOwner);
|
||||||
|
@@ -40,16 +40,20 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.LifecycleRegistry;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
|
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -59,22 +63,44 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class InternetPreferenceControllerTest {
|
public class InternetPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String TEST_SUMMARY = "test summary";
|
private static final String TEST_SUMMARY = "test summary";
|
||||||
private static final String NOT_CONNECTED = "Not connected";
|
private static final String NOT_CONNECTED = "Not connected";
|
||||||
|
private static final String SUB_ID_1 = "1";
|
||||||
|
private static final String SUB_ID_2 = "2";
|
||||||
|
private static final String INVALID_SUB_ID = "-1";
|
||||||
|
private static final String DISPLAY_NAME_1 = "Sub 1";
|
||||||
|
private static final String DISPLAY_NAME_2 = "Sub 2";
|
||||||
|
private static final String SUB_MCC_1 = "123";
|
||||||
|
private static final String SUB_MNC_1 = "456";
|
||||||
|
private static final String SUB_MCC_2 = "223";
|
||||||
|
private static final String SUB_MNC_2 = "456";
|
||||||
|
private static final String SUB_COUNTRY_ISO_1 = "Sub 1";
|
||||||
|
private static final String SUB_COUNTRY_ISO_2 = "Sub 2";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Mock
|
@Mock
|
||||||
|
private SubscriptionInfoEntity mActiveSubInfo;
|
||||||
|
@Mock
|
||||||
|
private SubscriptionInfoEntity mDefaultDataSubInfo;
|
||||||
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
|
@Mock
|
||||||
|
private LifecycleOwner mLifecycleOwner;
|
||||||
|
|
||||||
|
private LifecycleRegistry mLifecycleRegistry;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private InternetPreferenceController mController;
|
private MockInternetPreferenceController mController;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private List<SubscriptionInfoEntity> mSubscriptionInfoEntityList = new ArrayList<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -85,13 +111,15 @@ public class InternetPreferenceControllerTest {
|
|||||||
final WifiManager wifiManager = mock(WifiManager.class);
|
final WifiManager wifiManager = mock(WifiManager.class);
|
||||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(wifiManager);
|
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(wifiManager);
|
||||||
when(wifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
|
when(wifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
|
||||||
|
|
||||||
mController = new InternetPreferenceController(mContext, mock(Lifecycle.class),
|
|
||||||
mLifecycleOwner);
|
|
||||||
mController.sIconMap.put(INTERNET_WIFI, 0);
|
|
||||||
if (Looper.myLooper() == null) {
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
|
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
||||||
|
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||||
|
mController = new MockInternetPreferenceController(mContext, mock(Lifecycle.class),
|
||||||
|
mLifecycleOwner);
|
||||||
|
mController.sIconMap.put(INTERNET_WIFI, 0);
|
||||||
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
@@ -99,12 +127,45 @@ public class InternetPreferenceControllerTest {
|
|||||||
mScreen.addPreference(mPreference);
|
mScreen.addPreference(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MockInternetPreferenceController extends
|
||||||
|
com.android.settings.network.InternetPreferenceController {
|
||||||
|
public MockInternetPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
|
LifecycleOwner lifecycleOwner) {
|
||||||
|
super(context, lifecycle, lifecycleOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SubscriptionInfoEntity> mSubscriptionInfoEntity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
||||||
|
return mSubscriptionInfoEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubscriptionInfoList(List<SubscriptionInfoEntity> list) {
|
||||||
|
mSubscriptionInfoEntity = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private SubscriptionInfoEntity setupSubscriptionInfoEntity(String subId, int slotId,
|
||||||
|
int carrierId, String displayName, String mcc, String mnc, String countryIso,
|
||||||
|
int cardId, boolean isVisible, boolean isValid, boolean isActive, boolean isAvailable,
|
||||||
|
boolean isDefaultData, boolean isActiveData) {
|
||||||
|
return new SubscriptionInfoEntity(subId, slotId, carrierId,
|
||||||
|
displayName, displayName, 0, mcc, mnc, countryIso, false, cardId,
|
||||||
|
TelephonyManager.DEFAULT_PORT_INDEX, false, null,
|
||||||
|
SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM, displayName, isVisible,
|
||||||
|
"1234567890", true, "default", false, isValid, true, isActive, isAvailable, false,
|
||||||
|
false, isDefaultData, false, isActiveData);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_shouldBeTrue() {
|
public void isAvailable_shouldBeTrue() {
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@UiThreadTest
|
||||||
public void onResume_shouldRegisterCallback() {
|
public void onResume_shouldRegisterCallback() {
|
||||||
mController.onResume();
|
mController.onResume();
|
||||||
|
|
||||||
@@ -117,6 +178,7 @@ public class InternetPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@UiThreadTest
|
||||||
public void onPause_shouldUnregisterCallback() {
|
public void onPause_shouldUnregisterCallback() {
|
||||||
mController.onResume();
|
mController.onResume();
|
||||||
mController.onPause();
|
mController.onPause();
|
||||||
@@ -149,33 +211,33 @@ public class InternetPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateCellularSummary_getNullSubscriptionInfo_shouldNotCrash() {
|
public void updateCellularSummary_getNullSubscriptionInfo_shouldNotCrash() {
|
||||||
final SubscriptionManager subscriptionManager = mock(SubscriptionManager.class);
|
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(subscriptionManager);
|
|
||||||
when(subscriptionManager.getDefaultDataSubscriptionInfo()).thenReturn(null);
|
|
||||||
when(subscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(null);
|
|
||||||
|
|
||||||
mController.updateCellularSummary();
|
mController.updateCellularSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateCellularSummary_getActiveSubscriptionInfo_cbrs() {
|
public void updateCellularSummary_getActiveSubscriptionInfo_cbrs() {
|
||||||
|
mActiveSubInfo = setupSubscriptionInfoEntity(SUB_ID_1, 1, 1, DISPLAY_NAME_1, SUB_MCC_1,
|
||||||
|
SUB_MNC_1, SUB_COUNTRY_ISO_1, 1, false, true, true, true, false, true);
|
||||||
|
mDefaultDataSubInfo = setupSubscriptionInfoEntity(SUB_ID_2, 1, 1, DISPLAY_NAME_2, SUB_MCC_2,
|
||||||
|
SUB_MNC_2, SUB_COUNTRY_ISO_2, 1, false, true, true, true, true, false);
|
||||||
|
mSubscriptionInfoEntityList.add(mActiveSubInfo);
|
||||||
|
mSubscriptionInfoEntityList.add(mDefaultDataSubInfo);
|
||||||
|
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
final SubscriptionManager subscriptionManager = mock(SubscriptionManager.class);
|
|
||||||
final SubscriptionInfo defaultSubInfo = mock(SubscriptionInfo.class);
|
|
||||||
final SubscriptionInfo activeSubInfo = mock(SubscriptionInfo.class);
|
|
||||||
final String expectedSummary =
|
|
||||||
ResourcesUtils.getResourcesString(mContext, "mobile_data_temp_using", "");
|
|
||||||
|
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(subscriptionManager);
|
|
||||||
when(subscriptionManager.getDefaultDataSubscriptionInfo()).thenReturn(defaultSubInfo);
|
|
||||||
|
|
||||||
when(subscriptionManager.getActiveSubscriptionInfo(anyInt())).thenReturn(activeSubInfo);
|
|
||||||
when(subscriptionManager.isSubscriptionVisible(activeSubInfo)).thenReturn(false);
|
|
||||||
|
|
||||||
mController.updateCellularSummary();
|
mController.updateCellularSummary();
|
||||||
assertThat(mPreference.getSummary()).isEqualTo("");
|
assertThat(mPreference.getSummary()).isEqualTo(DISPLAY_NAME_2);
|
||||||
|
|
||||||
when(subscriptionManager.isSubscriptionVisible(activeSubInfo)).thenReturn(true);
|
mActiveSubInfo = setupSubscriptionInfoEntity(SUB_ID_1, 1, 1, DISPLAY_NAME_1, SUB_MCC_1,
|
||||||
|
SUB_MNC_1, SUB_COUNTRY_ISO_1, 1, true, true, true, true, false, true);
|
||||||
|
mSubscriptionInfoEntityList.add(mActiveSubInfo);
|
||||||
|
mController.setSubscriptionInfoList(mSubscriptionInfoEntityList);
|
||||||
|
mController.onAvailableSubInfoChanged(mSubscriptionInfoEntityList);
|
||||||
|
final String expectedSummary =
|
||||||
|
ResourcesUtils.getResourcesString(mContext, "mobile_data_temp_using",
|
||||||
|
DISPLAY_NAME_1);
|
||||||
mController.updateCellularSummary();
|
mController.updateCellularSummary();
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
|
assertThat(mPreference.getSummary()).isEqualTo(expectedSummary);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user