[Settings] Apply the SettingsDataService to the SIM page, roaming
controller Implement it in 0RoamingPreferenceController Launch MobileNetworkSettings in SettingsApp by SubSettingLauncher Launch MobileNetworkSettings by intent Bug: 257197354 Test: atest RoamingPreferenceControllerTest Change-Id: Ia2df51ad3a9b2b72bdada05de480e0b05d2d4f43
This commit is contained in:
@@ -23,12 +23,14 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
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;
|
||||
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.SubscriptionManager;
|
||||
@@ -36,12 +38,16 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -65,15 +71,25 @@ public class RoamingPreferenceControllerTest {
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
@Mock
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
|
||||
private LifecycleRegistry mLifecycleRegistry;
|
||||
private RoamingPreferenceController mController;
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
private Context mContext;
|
||||
private MobileNetworkInfoEntity mMobileNetworkInfoEntity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(
|
||||
@@ -87,11 +103,21 @@ public class RoamingPreferenceControllerTest {
|
||||
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
|
||||
|
||||
mPreference = spy(new RestrictedSwitchPreference(mContext));
|
||||
mController = spy(new RoamingPreferenceController(mContext, "roaming"));
|
||||
mController.init(mFragmentManager, SUB_ID);
|
||||
mController = spy(
|
||||
new RoamingPreferenceController(mContext, "roaming", mLifecycle, mLifecycleOwner,
|
||||
SUB_ID));
|
||||
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||
mController.init(mFragmentManager, SUB_ID, mMobileNetworkInfoEntity);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
private MobileNetworkInfoEntity setupMobileNetworkInfoEntity(String subId,
|
||||
boolean isDataRoaming) {
|
||||
return new MobileNetworkInfoEntity(subId, false, false, true, false, false, false, false,
|
||||
false, false, false, isDataRoaming);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_validSubId_returnAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
@@ -100,9 +126,11 @@ public class RoamingPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_invalidSubId_returnUnsearchable() {
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
||||
mMobileNetworkInfoEntity);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
assertThat(mController.getAvailabilityStatus(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@@ -111,14 +139,16 @@ public class RoamingPreferenceControllerTest {
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_DISABLE_CHARGE_INDICATION_BOOL, false);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
doReturn(false).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
mMobileNetworkInfoEntity = setupMobileNetworkInfoEntity(String.valueOf(SUB_ID), false);
|
||||
mController.setMobileNetworkInfoEntity(mMobileNetworkInfoEntity);
|
||||
|
||||
assertThat(mController.isDialogNeeded()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDialogNeeded_roamingEnabled_returnFalse() {
|
||||
doReturn(true).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
mMobileNetworkInfoEntity = setupMobileNetworkInfoEntity(String.valueOf(SUB_ID), true);
|
||||
mController.setMobileNetworkInfoEntity(mMobileNetworkInfoEntity);
|
||||
|
||||
assertThat(mController.isDialogNeeded()).isFalse();
|
||||
}
|
||||
@@ -126,10 +156,10 @@ public class RoamingPreferenceControllerTest {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void setChecked_needDialog_showDialog() {
|
||||
doReturn(false).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
mMobileNetworkInfoEntity = setupMobileNetworkInfoEntity(String.valueOf(SUB_ID), false);
|
||||
mController.setMobileNetworkInfoEntity(mMobileNetworkInfoEntity);
|
||||
doReturn(null).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
|
||||
mController.setChecked(true);
|
||||
|
||||
verify(mFragmentManager).beginTransaction();
|
||||
@@ -137,7 +167,11 @@ public class RoamingPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_invalidSubId_disabled() {
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkInfoEntity = setupMobileNetworkInfoEntity(
|
||||
String.valueOf(SubscriptionManager.INVALID_SUBSCRIPTION_ID), false);
|
||||
mController.setMobileNetworkInfoEntity(mMobileNetworkInfoEntity);
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
|
||||
mMobileNetworkInfoEntity);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -146,7 +180,8 @@ public class RoamingPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_validSubId_enabled() {
|
||||
doReturn(true).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
mMobileNetworkInfoEntity = setupMobileNetworkInfoEntity(String.valueOf(SUB_ID), true);
|
||||
mController.setMobileNetworkInfoEntity(mMobileNetworkInfoEntity);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -191,7 +226,7 @@ public class RoamingPreferenceControllerTest {
|
||||
@Test
|
||||
public void getAvailabilityStatus_forceHomeNetworkIsTrue_shouldReturnConditionallyAvailable() {
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, false);
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_FORCE_HOME_NETWORK_BOOL, true);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
|
Reference in New Issue
Block a user