Merge "Refine the logic to show/hide cdma preference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
0c95a2980c
@@ -30,7 +30,6 @@ import android.provider.Settings;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -213,11 +212,6 @@ public class MobileNetworkUtils {
|
||||
|| (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries));
|
||||
}
|
||||
|
||||
public static PersistableBundle getCarrierConfigBySubId(int mSubId) {
|
||||
//TODO(b/114749736): get carrier config from subId
|
||||
return new PersistableBundle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to enable data for {@code subId}, also whether to disable data for other
|
||||
* subscription
|
||||
@@ -253,9 +247,17 @@ public class MobileNetworkUtils {
|
||||
}
|
||||
final TelephonyManager telephonyManager = TelephonyManager.from(context)
|
||||
.createForSubscriptionId(subId);
|
||||
final PersistableBundle carrierConfig = context.getSystemService(
|
||||
CarrierConfigManager.class).getConfigForSubId(subId);
|
||||
|
||||
|
||||
if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
|
||||
return true;
|
||||
} else if (carrierConfig != null
|
||||
&& !carrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isWorldMode(context, subId)) {
|
||||
@@ -312,7 +314,10 @@ public class MobileNetworkUtils {
|
||||
|
||||
if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
|
||||
return true;
|
||||
} else if (carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
|
||||
} else if (carrierConfig != null
|
||||
&& !carrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,8 @@ import android.telephony.TelephonyManager;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.telephony.Phone;
|
||||
|
||||
/**
|
||||
* Preference controller for "System Select"
|
||||
*/
|
||||
@@ -47,6 +49,12 @@ public class CdmaSystemSelectPreferenceController extends CdmaBasePreferenceCont
|
||||
resetCdmaRoamingModeToDefault();
|
||||
}
|
||||
}
|
||||
final int settingsNetworkMode = Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
|
||||
Phone.PREFERRED_NT_MODE);
|
||||
listPreference.setEnabled(
|
||||
settingsNetworkMode != TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,18 +21,20 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telecom.PhoneAccountHandle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -75,27 +77,35 @@ public class MobileNetworkUtilsTest {
|
||||
private ComponentName mComponentName;
|
||||
@Mock
|
||||
private ResolveInfo mResolveInfo;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private Context mContext;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID_1);
|
||||
doReturn(mTelephonyManager2).when(mTelephonyManager).createForSubscriptionId(SUB_ID_2);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(mComponentName).when(mPhoneAccountHandle).getComponentName();
|
||||
doReturn(PACKAGE_NAME).when(mComponentName).getPackageName();
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPhoneAccountHandle.getComponentName()).thenReturn(mComponentName);
|
||||
when(mComponentName.getPackageName()).thenReturn(PACKAGE_NAME);
|
||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
||||
mCarrierConfigManager);
|
||||
|
||||
doReturn(SUB_ID_1).when(mSubscriptionInfo1).getSubscriptionId();
|
||||
doReturn(SUB_ID_2).when(mSubscriptionInfo2).getSubscriptionId();
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
||||
|
||||
doReturn(Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)).when(
|
||||
mSubscriptionManager).getActiveSubscriptionInfoList();
|
||||
when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1);
|
||||
when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2);
|
||||
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,8 +139,8 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
|
||||
doReturn(new ArrayList<ResolveInfo>()).when(mPackageManager).queryIntentActivities(
|
||||
nullable(Intent.class), anyInt());
|
||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
||||
.thenReturn(new ArrayList<>());
|
||||
|
||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mPhoneAccountHandle)).isNull();
|
||||
@@ -138,8 +148,8 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
|
||||
doReturn(Arrays.asList(mResolveInfo)).when(mPackageManager).queryIntentActivities(
|
||||
nullable(Intent.class), anyInt());
|
||||
when(mPackageManager.queryIntentActivities(nullable(Intent.class), anyInt()))
|
||||
.thenReturn(Arrays.asList(mResolveInfo));
|
||||
|
||||
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
|
||||
mPhoneAccountHandle)).isNotNull();
|
||||
@@ -147,19 +157,29 @@ public class MobileNetworkUtilsTest {
|
||||
|
||||
@Test
|
||||
public void isCdmaOptions_phoneTypeCdma_returnTrue() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||
when(mTelephonyManager.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_CDMA);
|
||||
|
||||
assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCdmaOptions_worldModeWithGsmWcdma_returnTrue() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
||||
doReturn("true").when(mContext).getString(R.string.config_world_mode);
|
||||
when(mTelephonyManager.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
|
||||
when(mContext.getString(R.string.config_world_mode)).thenReturn("true");
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
|
||||
TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
|
||||
|
||||
assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCdmaOptions_carrierWorldModeWithoutHideCarrier_returnTrue() {
|
||||
when(mTelephonyManager.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
|
||||
false);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, true);
|
||||
|
||||
assertThat(MobileNetworkUtils.isCdmaOptions(mContext, SUB_ID_1)).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,13 @@ 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 static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
@@ -53,9 +56,12 @@ public class CdmaSubscriptionPreferenceControllerTest {
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private CdmaSubscriptionPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
@@ -68,6 +74,10 @@ public class CdmaSubscriptionPreferenceControllerTest {
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
doReturn(mCarrierConfigManager).when(mContext).getSystemService(CarrierConfigManager.class);
|
||||
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||
|
||||
mPreference = new ListPreference(mContext);
|
||||
mController = new CdmaSubscriptionPreferenceController(mContext, "mobile_data");
|
||||
|
@@ -21,9 +21,12 @@ 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 static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
@@ -51,9 +54,12 @@ public class CdmaSystemSelectPreferenceControllerTest {
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private CdmaSystemSelectPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
private PersistableBundle mCarrierConfig;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
@@ -67,6 +73,12 @@ public class CdmaSystemSelectPreferenceControllerTest {
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
doReturn(mCarrierConfigManager).when(mContext).getSystemService(CarrierConfigManager.class);
|
||||
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||
|
||||
|
||||
mPreference = new ListPreference(mContext);
|
||||
mController = new CdmaSystemSelectPreferenceController(mContext, "mobile_data");
|
||||
mController.init(mPreferenceManager, SUB_ID);
|
||||
@@ -101,6 +113,20 @@ public class CdmaSystemSelectPreferenceControllerTest {
|
||||
Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_HOME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_LteGSMWcdma_disabled() {
|
||||
doReturn(TelephonyManager.CDMA_ROAMING_MODE_HOME).when(
|
||||
mTelephonyManager).getCdmaRoamingMode();
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
|
||||
TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updateState_stateOther_resetToDefault() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
|
Reference in New Issue
Block a user