Loading res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -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 --> Loading src/com/android/settings/ApnEditor.java +76 −13 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; Loading Loading @@ -117,6 +118,7 @@ public class ApnEditor extends SettingsPreferenceFragment private String[] mReadOnlyApnTypes; private String[] mReadOnlyApnFields; private boolean mReadOnlyApn; private String mUserEnteredApnType; /** * Standard projection for the interesting columns of a normal note. Loading Loading @@ -212,14 +214,8 @@ public class ApnEditor extends SettingsPreferenceFragment mReadOnlyApn = false; mReadOnlyApnTypes = null; mReadOnlyApnFields = null; mUserEnteredApnType = null; if (action.equals(Intent.ACTION_EDIT)) { Uri uri = intent.getData(); if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) { Log.e(TAG, "Edit request not for carrier table. Uri: " + uri); finish(); return; } CarrierConfigManager configManager = (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager != null) { Loading @@ -227,10 +223,23 @@ public class ApnEditor extends SettingsPreferenceFragment if (b != null) { 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); } } 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)) { Log.e(TAG, "Edit request not for carrier table. Uri: " + uri); finish(); return; } mUri = uri; } else if (action.equals(Intent.ACTION_INSERT)) { if (mFirstTime || icicle.getInt(SAVED_POS) == 0) { Loading Loading @@ -295,7 +304,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; } Loading Loading @@ -950,7 +959,7 @@ public class ApnEditor extends SettingsPreferenceFragment callUpdate = setStringValueAndCheckIfDiff(values, Telephony.Carriers.TYPE, checkNotSet(mApnType.getText()), checkNotSet(getUserEnteredApnType()), callUpdate, TYPE_INDEX); Loading Loading @@ -1052,6 +1061,25 @@ 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 (!ArrayUtils.isEmpty(mReadOnlyApnTypes) && apnTypesMatch(mReadOnlyApnTypes, getUserEnteredApnType())) { StringBuilder stringBuilder = new StringBuilder(); for (String type : mReadOnlyApnTypes) { stringBuilder.append(type).append(", "); Log.d(TAG, "getErrorMsg: appending type: " + type); } // 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; } Loading Loading @@ -1088,6 +1116,41 @@ public class ApnEditor extends SettingsPreferenceFragment } } private String getUserEnteredApnType() { if (mUserEnteredApnType != null) { return mUserEnteredApnType; } // if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY" mUserEnteredApnType = mApnType.getText(); if (mUserEnteredApnType != null) mUserEnteredApnType = mUserEnteredApnType.trim(); if ((TextUtils.isEmpty(mUserEnteredApnType) || PhoneConstants.APN_TYPE_ALL.equals(mUserEnteredApnType)) && !ArrayUtils.isEmpty(mReadOnlyApnTypes)) { StringBuilder editableApnTypes = new StringBuilder(); List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes); boolean first = true; for (String apnType : PhoneConstants.APN_TYPES) { // add APN type if it is not read-only and is not wild-cardable if (!readOnlyApnTypes.contains(apnType) && !apnType.equals(PhoneConstants.APN_TYPE_IA) && !apnType.equals(PhoneConstants.APN_TYPE_EMERGENCY)) { if (first) { first = false; } else { editableApnTypes.append(","); } editableApnTypes.append(apnType); } } mUserEnteredApnType = editableApnTypes.toString(); Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: " + mUserEnteredApnType); } return mUserEnteredApnType; } public static class ErrorDialog extends InstrumentedDialogFragment { public static void showError(ApnEditor editor) { Loading src/com/android/settings/ApnSettings.java +9 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading
res/values/strings.xml +2 −0 Original line number Diff line number Diff line Loading @@ -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 --> Loading
src/com/android/settings/ApnEditor.java +76 −13 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.internal.telephony.PhoneConstants; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; Loading Loading @@ -117,6 +118,7 @@ public class ApnEditor extends SettingsPreferenceFragment private String[] mReadOnlyApnTypes; private String[] mReadOnlyApnFields; private boolean mReadOnlyApn; private String mUserEnteredApnType; /** * Standard projection for the interesting columns of a normal note. Loading Loading @@ -212,14 +214,8 @@ public class ApnEditor extends SettingsPreferenceFragment mReadOnlyApn = false; mReadOnlyApnTypes = null; mReadOnlyApnFields = null; mUserEnteredApnType = null; if (action.equals(Intent.ACTION_EDIT)) { Uri uri = intent.getData(); if (!uri.isPathPrefixMatch(Telephony.Carriers.CONTENT_URI)) { Log.e(TAG, "Edit request not for carrier table. Uri: " + uri); finish(); return; } CarrierConfigManager configManager = (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager != null) { Loading @@ -227,10 +223,23 @@ public class ApnEditor extends SettingsPreferenceFragment if (b != null) { 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); } } 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)) { Log.e(TAG, "Edit request not for carrier table. Uri: " + uri); finish(); return; } mUri = uri; } else if (action.equals(Intent.ACTION_INSERT)) { if (mFirstTime || icicle.getInt(SAVED_POS) == 0) { Loading Loading @@ -295,7 +304,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; } Loading Loading @@ -950,7 +959,7 @@ public class ApnEditor extends SettingsPreferenceFragment callUpdate = setStringValueAndCheckIfDiff(values, Telephony.Carriers.TYPE, checkNotSet(mApnType.getText()), checkNotSet(getUserEnteredApnType()), callUpdate, TYPE_INDEX); Loading Loading @@ -1052,6 +1061,25 @@ 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 (!ArrayUtils.isEmpty(mReadOnlyApnTypes) && apnTypesMatch(mReadOnlyApnTypes, getUserEnteredApnType())) { StringBuilder stringBuilder = new StringBuilder(); for (String type : mReadOnlyApnTypes) { stringBuilder.append(type).append(", "); Log.d(TAG, "getErrorMsg: appending type: " + type); } // 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; } Loading Loading @@ -1088,6 +1116,41 @@ public class ApnEditor extends SettingsPreferenceFragment } } private String getUserEnteredApnType() { if (mUserEnteredApnType != null) { return mUserEnteredApnType; } // if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY" mUserEnteredApnType = mApnType.getText(); if (mUserEnteredApnType != null) mUserEnteredApnType = mUserEnteredApnType.trim(); if ((TextUtils.isEmpty(mUserEnteredApnType) || PhoneConstants.APN_TYPE_ALL.equals(mUserEnteredApnType)) && !ArrayUtils.isEmpty(mReadOnlyApnTypes)) { StringBuilder editableApnTypes = new StringBuilder(); List<String> readOnlyApnTypes = Arrays.asList(mReadOnlyApnTypes); boolean first = true; for (String apnType : PhoneConstants.APN_TYPES) { // add APN type if it is not read-only and is not wild-cardable if (!readOnlyApnTypes.contains(apnType) && !apnType.equals(PhoneConstants.APN_TYPE_IA) && !apnType.equals(PhoneConstants.APN_TYPE_EMERGENCY)) { if (first) { first = false; } else { editableApnTypes.append(","); } editableApnTypes.append(apnType); } } mUserEnteredApnType = editableApnTypes.toString(); Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: " + mUserEnteredApnType); } return mUserEnteredApnType; } public static class ErrorDialog extends InstrumentedDialogFragment { public static void showError(ApnEditor editor) { Loading
src/com/android/settings/ApnSettings.java +9 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading