[Settings] Support default value for APN protocol

Add default value on APN (roaming) protocol based on configuration when user leave it empty during editing APN.

Bug: 142440775
Test: manual
Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=ApnEditorTest
Change-Id: I3f1ca0ef17ceaaf2a94b21b6034cd74e56081b61
This commit is contained in:
Bonian Chen
2020-01-17 05:12:04 +08:00
parent a65636ad64
commit 5fcb8ee011
2 changed files with 75 additions and 39 deletions

View File

@@ -137,6 +137,10 @@ public class ApnEditor extends SettingsPreferenceFragment
String[] mReadOnlyApnTypes;
@VisibleForTesting
String[] mDefaultApnTypes;
@VisibleForTesting
String mDefaultApnProtocol;
@VisibleForTesting
String mDefaultApnRoamingProtocol;
private String[] mReadOnlyApnFields;
private boolean mReadOnlyApn;
private Uri mCarrierUri;
@@ -241,12 +245,14 @@ public class ApnEditor extends SettingsPreferenceFragment
private static final int AUTH_TYPE_INDEX = 14;
@VisibleForTesting
static final int TYPE_INDEX = 15;
private static final int PROTOCOL_INDEX = 16;
@VisibleForTesting
static final int PROTOCOL_INDEX = 16;
@VisibleForTesting
static final int CARRIER_ENABLED_INDEX = 17;
private static final int BEARER_INDEX = 18;
private static final int BEARER_BITMASK_INDEX = 19;
private static final int ROAMING_PROTOCOL_INDEX = 20;
@VisibleForTesting
static final int ROAMING_PROTOCOL_INDEX = 20;
private static final int MVNO_TYPE_INDEX = 21;
private static final int MVNO_MATCH_DATA_INDEX = 22;
private static final int EDITED_INDEX = 23;
@@ -317,6 +323,19 @@ public class ApnEditor extends SettingsPreferenceFragment
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);
}
}
}
@@ -1029,13 +1048,13 @@ public class ApnEditor extends SettingsPreferenceFragment
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.PROTOCOL,
checkNotSet(mProtocol.getValue()),
getUserEnteredApnProtocol(mProtocol, mDefaultApnProtocol),
callUpdate,
PROTOCOL_INDEX);
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.ROAMING_PROTOCOL,
checkNotSet(mRoamingProtocol.getValue()),
getUserEnteredApnProtocol(mRoamingProtocol, mDefaultApnRoamingProtocol),
callUpdate,
ROAMING_PROTOCOL_INDEX);
@@ -1231,6 +1250,17 @@ public class ApnEditor extends SettingsPreferenceFragment
return sNotSet.equals(value) ? null : value;
}
@VisibleForTesting
String getUserEnteredApnProtocol(ListPreference preference, String defaultApnProtocol) {
// if user has not specified a protocol or enter empty type, map it just for default
final String userEnteredApnProtocol = checkNotSet(
((preference == null) ? null : preference.getValue()));
if (TextUtils.isEmpty(userEnteredApnProtocol)) {
return defaultApnProtocol;
}
return userEnteredApnProtocol.trim();
}
@VisibleForTesting
String getUserEnteredApnType() {
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"