Loading src/com/android/settings/network/ApnEditor.java +23 −7 Original line number Diff line number Diff line Loading @@ -135,7 +135,10 @@ public class ApnEditor extends SettingsPreferenceFragment private int mBearerInitialVal = 0; private String mMvnoTypeStr; private String mMvnoMatchDataStr; private String[] mReadOnlyApnTypes; @VisibleForTesting String[] mReadOnlyApnTypes; @VisibleForTesting String[] mDefaultApnTypes; private String[] mReadOnlyApnFields; private boolean mReadOnlyApn; private Uri mCarrierUri; Loading Loading @@ -189,7 +192,8 @@ public class ApnEditor extends SettingsPreferenceFragment private static final int MMSPROXY_INDEX = 12; private static final int MMSPORT_INDEX = 13; 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; @VisibleForTesting static final int CARRIER_ENABLED_INDEX = 17; Loading Loading @@ -250,12 +254,17 @@ public class ApnEditor extends SettingsPreferenceFragment mReadOnlyApnTypes = b.getStringArray( CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY); if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) { for (String apnType : mReadOnlyApnTypes) { Log.d(TAG, "onCreate: read only APN type: " + apnType); } 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)); } } } Loading Loading @@ -1150,17 +1159,24 @@ public class ApnEditor extends SettingsPreferenceFragment 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" // but if user enter empty type, map it just for default String userEnteredApnType = mApnType.getText(); if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim(); if ((TextUtils.isEmpty(userEnteredApnType) || PhoneConstants.APN_TYPE_ALL.equals(userEnteredApnType)) && !ArrayUtils.isEmpty(mReadOnlyApnTypes)) { String[] apnTypeList = PhoneConstants.APN_TYPES; if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) { apnTypeList = mDefaultApnTypes; } StringBuilder editableApnTypes = new StringBuilder(); List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes); 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 if (!readOnlyApnTypes.contains(apnType) && !apnType.equals(PhoneConstants.APN_TYPE_IA) Loading tests/robotests/src/com/android/settings/network/ApnEditorTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,43 @@ public class ApnEditorTest { 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() { doReturn(2).when(mCursor).getColumnCount(); doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX); Loading Loading
src/com/android/settings/network/ApnEditor.java +23 −7 Original line number Diff line number Diff line Loading @@ -135,7 +135,10 @@ public class ApnEditor extends SettingsPreferenceFragment private int mBearerInitialVal = 0; private String mMvnoTypeStr; private String mMvnoMatchDataStr; private String[] mReadOnlyApnTypes; @VisibleForTesting String[] mReadOnlyApnTypes; @VisibleForTesting String[] mDefaultApnTypes; private String[] mReadOnlyApnFields; private boolean mReadOnlyApn; private Uri mCarrierUri; Loading Loading @@ -189,7 +192,8 @@ public class ApnEditor extends SettingsPreferenceFragment private static final int MMSPROXY_INDEX = 12; private static final int MMSPORT_INDEX = 13; 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; @VisibleForTesting static final int CARRIER_ENABLED_INDEX = 17; Loading Loading @@ -250,12 +254,17 @@ public class ApnEditor extends SettingsPreferenceFragment mReadOnlyApnTypes = b.getStringArray( CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY); if (!ArrayUtils.isEmpty(mReadOnlyApnTypes)) { for (String apnType : mReadOnlyApnTypes) { Log.d(TAG, "onCreate: read only APN type: " + apnType); } 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)); } } } Loading Loading @@ -1150,17 +1159,24 @@ public class ApnEditor extends SettingsPreferenceFragment 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" // but if user enter empty type, map it just for default String userEnteredApnType = mApnType.getText(); if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim(); if ((TextUtils.isEmpty(userEnteredApnType) || PhoneConstants.APN_TYPE_ALL.equals(userEnteredApnType)) && !ArrayUtils.isEmpty(mReadOnlyApnTypes)) { String[] apnTypeList = PhoneConstants.APN_TYPES; if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) { apnTypeList = mDefaultApnTypes; } StringBuilder editableApnTypes = new StringBuilder(); List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes); 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 if (!readOnlyApnTypes.contains(apnType) && !apnType.equals(PhoneConstants.APN_TYPE_IA) Loading
tests/robotests/src/com/android/settings/network/ApnEditorTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -463,6 +463,43 @@ public class ApnEditorTest { 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() { doReturn(2).when(mCursor).getColumnCount(); doReturn(2).when(mCursor).getInt(CURSOR_INTEGER_INDEX); Loading