Merge "Fix failures on com.android.settings.network.ApnEditorTest" into rvc-dev
This commit is contained in:
@@ -130,7 +130,8 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
private boolean mNewApn;
|
private boolean mNewApn;
|
||||||
private int mSubId;
|
private int mSubId;
|
||||||
private ProxySubscriptionManager mProxySubscriptionMgr;
|
@VisibleForTesting
|
||||||
|
ProxySubscriptionManager mProxySubscriptionMgr;
|
||||||
private int mBearerInitialVal = 0;
|
private int mBearerInitialVal = 0;
|
||||||
private String mMvnoTypeStr;
|
private String mMvnoTypeStr;
|
||||||
private String mMvnoMatchDataStr;
|
private String mMvnoMatchDataStr;
|
||||||
@@ -263,34 +264,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
// enable ProxySubscriptionMgr with Lifecycle support for all controllers
|
setLifecycleForAllControllers();
|
||||||
// live within this fragment
|
|
||||||
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(getContext());
|
|
||||||
mProxySubscriptionMgr.setLifecycle(getLifecycle());
|
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.apn_editor);
|
|
||||||
|
|
||||||
sNotSet = getResources().getString(R.string.apn_not_set);
|
|
||||||
mName = (EditTextPreference) findPreference("apn_name");
|
|
||||||
mApn = (EditTextPreference) findPreference("apn_apn");
|
|
||||||
mProxy = (EditTextPreference) findPreference("apn_http_proxy");
|
|
||||||
mPort = (EditTextPreference) findPreference("apn_http_port");
|
|
||||||
mUser = (EditTextPreference) findPreference("apn_user");
|
|
||||||
mServer = (EditTextPreference) findPreference("apn_server");
|
|
||||||
mPassword = (EditTextPreference) findPreference(KEY_PASSWORD);
|
|
||||||
mMmsProxy = (EditTextPreference) findPreference("apn_mms_proxy");
|
|
||||||
mMmsPort = (EditTextPreference) findPreference("apn_mms_port");
|
|
||||||
mMmsc = (EditTextPreference) findPreference("apn_mmsc");
|
|
||||||
mMcc = (EditTextPreference) findPreference("apn_mcc");
|
|
||||||
mMnc = (EditTextPreference) findPreference("apn_mnc");
|
|
||||||
mApnType = (EditTextPreference) findPreference("apn_type");
|
|
||||||
mAuthType = (ListPreference) findPreference(KEY_AUTH_TYPE);
|
|
||||||
mProtocol = (ListPreference) findPreference(KEY_PROTOCOL);
|
|
||||||
mRoamingProtocol = (ListPreference) findPreference(KEY_ROAMING_PROTOCOL);
|
|
||||||
mCarrierEnabled = (SwitchPreference) findPreference(KEY_CARRIER_ENABLED);
|
|
||||||
mBearerMulti = (MultiSelectListPreference) findPreference(KEY_BEARER_MULTI);
|
|
||||||
mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
|
|
||||||
mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
|
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
@@ -298,47 +272,11 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
|
mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
mReadOnlyApn = false;
|
|
||||||
mReadOnlyApnTypes = null;
|
|
||||||
mReadOnlyApnFields = null;
|
|
||||||
|
|
||||||
final CarrierConfigManager configManager = (CarrierConfigManager)
|
initApnEditorUi();
|
||||||
getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
getCarrierCustomizedConfig();
|
||||||
if (configManager != null) {
|
|
||||||
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
|
|
||||||
if (b != null) {
|
|
||||||
mReadOnlyApnTypes = b.getStringArray(
|
|
||||||
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
|
||||||
if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
|
||||||
Log.d(TAG,
|
|
||||||
"onCreate: read only APN type: " + Arrays.toString(mReadOnlyApnTypes));
|
|
||||||
}
|
|
||||||
mReadOnlyApnFields = b.getStringArray(
|
|
||||||
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
|
|
||||||
|
|
||||||
mDefaultApnTypes = b.getStringArray(
|
|
||||||
CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY);
|
|
||||||
if (!ArrayUtils.isEmpty(mDefaultApnTypes)) {
|
|
||||||
Log.d(TAG, "onCreate: default apn types: " + Arrays.toString(mDefaultApnTypes));
|
|
||||||
}
|
|
||||||
|
|
||||||
mDefaultApnProtocol = b.getString(
|
|
||||||
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_PROTOCOL_STRING);
|
|
||||||
if (!TextUtils.isEmpty(mDefaultApnProtocol)) {
|
|
||||||
Log.d(TAG, "onCreate: default apn protocol: " + mDefaultApnProtocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
mDefaultApnRoamingProtocol = b.getString(
|
|
||||||
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING);
|
|
||||||
if (!TextUtils.isEmpty(mDefaultApnRoamingProtocol)) {
|
|
||||||
Log.d(TAG, "onCreate: default apn roaming protocol: "
|
|
||||||
+ mDefaultApnRoamingProtocol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri uri = null;
|
Uri uri = null;
|
||||||
if (action.equals(Intent.ACTION_EDIT)) {
|
if (action.equals(Intent.ACTION_EDIT)) {
|
||||||
@@ -391,6 +329,17 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable ProxySubscriptionMgr with Lifecycle support for all controllers
|
||||||
|
* live within this fragment
|
||||||
|
*/
|
||||||
|
private void setLifecycleForAllControllers() {
|
||||||
|
if (mProxySubscriptionMgr == null) {
|
||||||
|
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(getContext());
|
||||||
|
}
|
||||||
|
mProxySubscriptionMgr.setLifecycle(getLifecycle());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
||||||
super.onViewStateRestored(savedInstanceState);
|
super.onViewStateRestored(savedInstanceState);
|
||||||
@@ -1279,32 +1228,102 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
|
if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
|
||||||
apnTypeList = mDefaultApnTypes;
|
apnTypeList = mDefaultApnTypes;
|
||||||
}
|
}
|
||||||
|
userEnteredApnType = getEditableApnType(apnTypeList);
|
||||||
final StringBuilder editableApnTypes = new StringBuilder();
|
|
||||||
final List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes);
|
|
||||||
boolean first = true;
|
|
||||||
for (String apnType : apnTypeList) {
|
|
||||||
// add APN type if it is not read-only and is not wild-cardable
|
|
||||||
if (!readOnlyApnTypes.contains(apnType)
|
|
||||||
&& !apnType.equals(APN_TYPE_IA)
|
|
||||||
&& !apnType.equals(APN_TYPE_EMERGENCY)
|
|
||||||
&& !apnType.equals(APN_TYPE_MCX)) {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
editableApnTypes.append(",");
|
|
||||||
}
|
|
||||||
editableApnTypes.append(apnType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
userEnteredApnType = editableApnTypes.toString();
|
|
||||||
Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
|
Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
|
||||||
+ userEnteredApnType);
|
+ userEnteredApnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return userEnteredApnType;
|
return userEnteredApnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getEditableApnType(String[] apnTypeList) {
|
||||||
|
final StringBuilder editableApnTypes = new StringBuilder();
|
||||||
|
final List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes);
|
||||||
|
boolean first = true;
|
||||||
|
for (String apnType : apnTypeList) {
|
||||||
|
// add APN type if it is not read-only and is not wild-cardable
|
||||||
|
if (!readOnlyApnTypes.contains(apnType)
|
||||||
|
&& !apnType.equals(APN_TYPE_IA)
|
||||||
|
&& !apnType.equals(APN_TYPE_EMERGENCY)
|
||||||
|
&& !apnType.equals(APN_TYPE_MCX)) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
editableApnTypes.append(",");
|
||||||
|
}
|
||||||
|
editableApnTypes.append(apnType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return editableApnTypes.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initApnEditorUi() {
|
||||||
|
addPreferencesFromResource(R.xml.apn_editor);
|
||||||
|
|
||||||
|
sNotSet = getResources().getString(R.string.apn_not_set);
|
||||||
|
mName = (EditTextPreference) findPreference("apn_name");
|
||||||
|
mApn = (EditTextPreference) findPreference("apn_apn");
|
||||||
|
mProxy = (EditTextPreference) findPreference("apn_http_proxy");
|
||||||
|
mPort = (EditTextPreference) findPreference("apn_http_port");
|
||||||
|
mUser = (EditTextPreference) findPreference("apn_user");
|
||||||
|
mServer = (EditTextPreference) findPreference("apn_server");
|
||||||
|
mPassword = (EditTextPreference) findPreference(KEY_PASSWORD);
|
||||||
|
mMmsProxy = (EditTextPreference) findPreference("apn_mms_proxy");
|
||||||
|
mMmsPort = (EditTextPreference) findPreference("apn_mms_port");
|
||||||
|
mMmsc = (EditTextPreference) findPreference("apn_mmsc");
|
||||||
|
mMcc = (EditTextPreference) findPreference("apn_mcc");
|
||||||
|
mMnc = (EditTextPreference) findPreference("apn_mnc");
|
||||||
|
mApnType = (EditTextPreference) findPreference("apn_type");
|
||||||
|
mAuthType = (ListPreference) findPreference(KEY_AUTH_TYPE);
|
||||||
|
mProtocol = (ListPreference) findPreference(KEY_PROTOCOL);
|
||||||
|
mRoamingProtocol = (ListPreference) findPreference(KEY_ROAMING_PROTOCOL);
|
||||||
|
mCarrierEnabled = (SwitchPreference) findPreference(KEY_CARRIER_ENABLED);
|
||||||
|
mBearerMulti = (MultiSelectListPreference) findPreference(KEY_BEARER_MULTI);
|
||||||
|
mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
|
||||||
|
mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCarrierCustomizedConfig() {
|
||||||
|
mReadOnlyApn = false;
|
||||||
|
mReadOnlyApnTypes = null;
|
||||||
|
mReadOnlyApnFields = null;
|
||||||
|
|
||||||
|
final CarrierConfigManager configManager = (CarrierConfigManager)
|
||||||
|
getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||||
|
if (configManager != null) {
|
||||||
|
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
|
||||||
|
if (b != null) {
|
||||||
|
mReadOnlyApnTypes = b.getStringArray(
|
||||||
|
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
||||||
|
if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
||||||
|
Log.d(TAG,
|
||||||
|
"onCreate: read only APN type: " + Arrays.toString(mReadOnlyApnTypes));
|
||||||
|
}
|
||||||
|
mReadOnlyApnFields = b.getStringArray(
|
||||||
|
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
|
||||||
|
|
||||||
|
mDefaultApnTypes = b.getStringArray(
|
||||||
|
CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY);
|
||||||
|
|
||||||
|
if (!ArrayUtils.isEmpty(mDefaultApnTypes)) {
|
||||||
|
Log.d(TAG, "onCreate: default apn types: " + Arrays.toString(mDefaultApnTypes));
|
||||||
|
}
|
||||||
|
|
||||||
|
mDefaultApnProtocol = b.getString(
|
||||||
|
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_PROTOCOL_STRING);
|
||||||
|
if (!TextUtils.isEmpty(mDefaultApnProtocol)) {
|
||||||
|
Log.d(TAG, "onCreate: default apn protocol: " + mDefaultApnProtocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
mDefaultApnRoamingProtocol = b.getString(
|
||||||
|
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING);
|
||||||
|
if (!TextUtils.isEmpty(mDefaultApnRoamingProtocol)) {
|
||||||
|
Log.d(TAG, "onCreate: default apn roaming protocol: "
|
||||||
|
+ mDefaultApnRoamingProtocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ErrorDialog extends InstrumentedDialogFragment {
|
public static class ErrorDialog extends InstrumentedDialogFragment {
|
||||||
|
|
||||||
public static void showError(ApnEditor editor) {
|
public static void showError(ApnEditor editor) {
|
||||||
|
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -99,6 +100,8 @@ public class ApnEditorTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private FragmentActivity mActivity;
|
private FragmentActivity mActivity;
|
||||||
|
@Mock
|
||||||
|
private ProxySubscriptionManager mProxySubscriptionMgr;
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<Uri> mUriCaptor;
|
private ArgumentCaptor<Uri> mUriCaptor;
|
||||||
@@ -450,6 +453,8 @@ public class ApnEditorTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowFragment.class)
|
@Config(shadows = ShadowFragment.class)
|
||||||
public void onCreate_noAction_shouldFinishAndNoCrash() {
|
public void onCreate_noAction_shouldFinishAndNoCrash() {
|
||||||
|
ProxySubscriptionManager proxySubscriptionMgr = mock(ProxySubscriptionManager.class);
|
||||||
|
mApnEditorUT.mProxySubscriptionMgr = proxySubscriptionMgr;
|
||||||
doReturn(new Intent()).when(mActivity).getIntent();
|
doReturn(new Intent()).when(mActivity).getIntent();
|
||||||
doNothing().when(mApnEditorUT).addPreferencesFromResource(anyInt());
|
doNothing().when(mApnEditorUT).addPreferencesFromResource(anyInt());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user