Disallow adding/editing dun APNs unless allowed by carrier.
Test: WIP Bug: 38186417 Change-Id: If1cc34ad979659a56a3886da2a02fdbf642739ac
This commit is contained in:
@@ -2982,6 +2982,8 @@
|
||||
<string name="error_mcc_not3">MCC field must be 3 digits.</string>
|
||||
<!-- APN error dialog messages: -->
|
||||
<string name="error_mnc_not23">MNC field must be 2 or 3 digits.</string>
|
||||
<!-- APN error dialog messages: -->
|
||||
<string name="error_adding_apn_type">Carrier does not allow adding APNs of type %s.</string>
|
||||
<!-- The message of dialog indicated restoring default APN settings in progress -->
|
||||
<string name="restore_default_apn">Restoring default APN settings.</string>
|
||||
<!-- APNs screen menu option to reset default APN settings -->
|
||||
|
@@ -213,6 +213,18 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
mReadOnlyApnTypes = null;
|
||||
mReadOnlyApnFields = null;
|
||||
|
||||
CarrierConfigManager configManager = (CarrierConfigManager)
|
||||
getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||
if (configManager != null) {
|
||||
PersistableBundle b = configManager.getConfig();
|
||||
if (b != null) {
|
||||
mReadOnlyApnTypes = b.getStringArray(
|
||||
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
||||
mReadOnlyApnFields = b.getStringArray(
|
||||
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equals(Intent.ACTION_EDIT)) {
|
||||
Uri uri = intent.getData();
|
||||
if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) {
|
||||
@@ -220,17 +232,6 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
CarrierConfigManager configManager = (CarrierConfigManager)
|
||||
getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||
if (configManager != null) {
|
||||
PersistableBundle b = configManager.getConfig();
|
||||
if (b != null) {
|
||||
mReadOnlyApnTypes = b.getStringArray(
|
||||
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
||||
mReadOnlyApnFields = b.getStringArray(
|
||||
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY);
|
||||
}
|
||||
}
|
||||
mUri = uri;
|
||||
} else if (action.equals(Intent.ACTION_INSERT)) {
|
||||
if (mFirstTime || icicle.getInt(SAVED_POS) == 0) {
|
||||
@@ -295,7 +296,7 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
* @param apnTypes array of APN types. "*" indicates all types.
|
||||
* @return true if all apn types are included in the array, false otherwise
|
||||
*/
|
||||
private boolean hasAllApns(String[] apnTypes) {
|
||||
static boolean hasAllApns(String[] apnTypes) {
|
||||
if (ArrayUtils.isEmpty(apnTypes)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1052,6 +1053,24 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
errorMsg = mRes.getString(R.string.error_mnc_not23);
|
||||
}
|
||||
|
||||
if (errorMsg == null) {
|
||||
// if carrier does not allow editing certain apn types, make sure type does not include
|
||||
// those
|
||||
if (mReadOnlyApnTypes.length > 0
|
||||
&& apnTypesMatch(mReadOnlyApnTypes, mApnType.getText())) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String type : mReadOnlyApnTypes) {
|
||||
stringBuilder.append(type).append(", ");
|
||||
}
|
||||
// remove last ", "
|
||||
if (stringBuilder.length() >= 2) {
|
||||
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
|
||||
}
|
||||
errorMsg = String.format(mRes.getString(R.string.error_adding_apn_type),
|
||||
stringBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
|
@@ -173,6 +173,15 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
PersistableBundle b = configManager.getConfig();
|
||||
mHideImsApn = b.getBoolean(CarrierConfigManager.KEY_HIDE_IMS_APN_BOOL);
|
||||
mAllowAddingApns = b.getBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL);
|
||||
if (mAllowAddingApns) {
|
||||
String[] readOnlyApnTypes = b.getStringArray(
|
||||
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY);
|
||||
// if no apn type can be edited, do not allow adding APNs
|
||||
if (ApnEditor.hasAllApns(readOnlyApnTypes)) {
|
||||
Log.d(TAG, "not allowing adding APN because all APN types are read only");
|
||||
mAllowAddingApns = false;
|
||||
}
|
||||
}
|
||||
mUserManager = UserManager.get(activity);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user