Merge "If the user add APN with empty APN type, map it for default type" into qt-qpr1-dev
am: 201fc40816
Change-Id: I76ac45fbc93bf01bbc4783fecfd3eed8b9dbb6d2
This commit is contained in:
@@ -135,7 +135,10 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
private int mBearerInitialVal = 0;
|
private int mBearerInitialVal = 0;
|
||||||
private String mMvnoTypeStr;
|
private String mMvnoTypeStr;
|
||||||
private String mMvnoMatchDataStr;
|
private String mMvnoMatchDataStr;
|
||||||
private String[] mReadOnlyApnTypes;
|
@VisibleForTesting
|
||||||
|
String[] mReadOnlyApnTypes;
|
||||||
|
@VisibleForTesting
|
||||||
|
String[] mDefaultApnTypes;
|
||||||
private String[] mReadOnlyApnFields;
|
private String[] mReadOnlyApnFields;
|
||||||
private boolean mReadOnlyApn;
|
private boolean mReadOnlyApn;
|
||||||
private Uri mCarrierUri;
|
private Uri mCarrierUri;
|
||||||
@@ -189,7 +192,8 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
private static final int MMSPROXY_INDEX = 12;
|
private static final int MMSPROXY_INDEX = 12;
|
||||||
private static final int MMSPORT_INDEX = 13;
|
private static final int MMSPORT_INDEX = 13;
|
||||||
private static final int AUTH_TYPE_INDEX = 14;
|
private static final int AUTH_TYPE_INDEX = 14;
|
||||||
private static final int TYPE_INDEX = 15;
|
@VisibleForTesting
|
||||||
|
static final int TYPE_INDEX = 15;
|
||||||
private static final int PROTOCOL_INDEX = 16;
|
private static final int PROTOCOL_INDEX = 16;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int CARRIER_ENABLED_INDEX = 17;
|
static final int CARRIER_ENABLED_INDEX = 17;
|
||||||
@@ -250,12 +254,17 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
mReadOnlyApnTypes = b.getStringArray(
|
mReadOnlyApnTypes = b.getStringArray(
|
||||||
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
||||||
if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
||||||
for (String apnType : mReadOnlyApnTypes) {
|
Log.d(TAG,
|
||||||
Log.d(TAG, "onCreate: read only APN type: " + apnType);
|
"onCreate: read only APN type: " + Arrays.toString(mReadOnlyApnTypes));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mReadOnlyApnFields = b.getStringArray(
|
mReadOnlyApnFields = b.getStringArray(
|
||||||
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1150,17 +1159,24 @@ public class ApnEditor extends SettingsPreferenceFragment
|
|||||||
return sNotSet.equals(value) ? null : value;
|
return sNotSet.equals(value) ? null : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUserEnteredApnType() {
|
@VisibleForTesting
|
||||||
|
String getUserEnteredApnType() {
|
||||||
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
|
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
|
||||||
|
// but if user enter empty type, map it just for default
|
||||||
String userEnteredApnType = mApnType.getText();
|
String userEnteredApnType = mApnType.getText();
|
||||||
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
|
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
|
||||||
if ((TextUtils.isEmpty(userEnteredApnType)
|
if ((TextUtils.isEmpty(userEnteredApnType)
|
||||||
|| PhoneConstants.APN_TYPE_ALL.equals(userEnteredApnType))
|
|| PhoneConstants.APN_TYPE_ALL.equals(userEnteredApnType))
|
||||||
&& !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
&& !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
|
||||||
|
String[] apnTypeList = PhoneConstants.APN_TYPES;
|
||||||
|
if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
|
||||||
|
apnTypeList = mDefaultApnTypes;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder editableApnTypes = new StringBuilder();
|
StringBuilder editableApnTypes = new StringBuilder();
|
||||||
List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes);
|
List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes);
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (String apnType : PhoneConstants.APN_TYPES) {
|
for (String apnType : apnTypeList) {
|
||||||
// add APN type if it is not read-only and is not wild-cardable
|
// add APN type if it is not read-only and is not wild-cardable
|
||||||
if (!readOnlyApnTypes.contains(apnType)
|
if (!readOnlyApnTypes.contains(apnType)
|
||||||
&& !apnType.equals(PhoneConstants.APN_TYPE_IA)
|
&& !apnType.equals(PhoneConstants.APN_TYPE_IA)
|
||||||
|
@@ -463,6 +463,43 @@ public class ApnEditorTest {
|
|||||||
verify(mApnEditorUT).finish();
|
verify(mApnEditorUT).finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUserEnteredApnType_emptyApnType_shouldReturnDefault() {
|
||||||
|
// case 1
|
||||||
|
// GIVEN read only APN types with DUN
|
||||||
|
String[] readOnlyApnTypes = {"dun"};
|
||||||
|
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypes;
|
||||||
|
// GIVEN read specificApnTypeForEmptyInput with DEFAULT,DUN
|
||||||
|
String[] defaultApnTypes = {"default", "dun"};
|
||||||
|
mApnEditorUT.mDefaultApnTypes = defaultApnTypes;
|
||||||
|
|
||||||
|
// Input empty in TYPE
|
||||||
|
final FakeApnData apnData = new FakeApnData(APN_DATA);
|
||||||
|
apnData.mData[ApnEditor.TYPE_INDEX] = "";
|
||||||
|
mApnEditorUT.mApnData = apnData;
|
||||||
|
mApnEditorUT.fillUI(true /* firstTime */);
|
||||||
|
|
||||||
|
// THEN APN type should be default
|
||||||
|
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||||
|
|
||||||
|
// case 2
|
||||||
|
// GIVEN read only APN types with DUN
|
||||||
|
String[] readOnlyApnTypesCase2 = {"dun"};
|
||||||
|
mApnEditorUT.mReadOnlyApnTypes = readOnlyApnTypesCase2;
|
||||||
|
// GIVEN read specificApnTypeForEmptyInput with DEFAULT
|
||||||
|
String[] defaultApnTypesCase2 = {"default"};
|
||||||
|
mApnEditorUT.mDefaultApnTypes = defaultApnTypesCase2;
|
||||||
|
|
||||||
|
// Input empty in TYPE
|
||||||
|
final FakeApnData apnDataCase2 = new FakeApnData(APN_DATA);
|
||||||
|
apnDataCase2.mData[ApnEditor.TYPE_INDEX] = "";
|
||||||
|
mApnEditorUT.mApnData = apnDataCase2;
|
||||||
|
mApnEditorUT.fillUI(true /* firstTime */);
|
||||||
|
|
||||||
|
// THEN APN type should be default
|
||||||
|
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
|
||||||
|
}
|
||||||
|
|
||||||
private void initCursor() {
|
private void initCursor() {
|
||||||
doReturn(2).when(mCursor).getColumnCount();
|
doReturn(2).when(mCursor).getColumnCount();
|
||||||
doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX);
|
doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX);
|
||||||
|
Reference in New Issue
Block a user