Merge "[Settings] Not allow APN delete when adding is not an option" into tm-qpr-dev am: d2644b4ea9

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19739248

Change-Id: Id550ed73ab4e6dd7c01504eaf315de23598aff01
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Bonian Chen
2022-08-26 11:17:02 +00:00
committed by Automerger Merge Worker
2 changed files with 50 additions and 10 deletions

View File

@@ -78,7 +78,8 @@ public class ApnEditor extends SettingsPreferenceFragment
private static final String KEY_MVNO_TYPE = "mvno_type";
private static final String KEY_PASSWORD = "apn_password";
private static final int MENU_DELETE = Menu.FIRST;
@VisibleForTesting
static final int MENU_DELETE = Menu.FIRST;
private static final int MENU_SAVE = Menu.FIRST + 1;
private static final int MENU_CANCEL = Menu.FIRST + 2;
@@ -148,6 +149,17 @@ public class ApnEditor extends SettingsPreferenceFragment
String mDefaultApnRoamingProtocol;
private String[] mReadOnlyApnFields;
private boolean mReadOnlyApn;
/**
* The APN deletion feature within menu is aligned with the APN adding feature.
* Having only one of them could lead to a UX which not that make sense from user's
* perspective.
*
* mIsAddApnAllowed stores the configuration value reading from
* CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL to support the presentation
* control of the menu options. When false, delete option would be invisible to
* the end user.
*/
private boolean mIsAddApnAllowed;
private Uri mCarrierUri;
private boolean mIsCarrierIdApn;
@@ -282,7 +294,7 @@ public class ApnEditor extends SettingsPreferenceFragment
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
initApnEditorUi();
getCarrierCustomizedConfig();
getCarrierCustomizedConfig(getContext());
Uri uri = null;
if (action.equals(Intent.ACTION_EDIT)) {
@@ -826,7 +838,8 @@ public class ApnEditor extends SettingsPreferenceFragment
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
// If it's a new APN, then cancel will delete the new entry in onPause
if (!mNewApn && !mReadOnlyApn) {
// If APN add is not allowed, delete might lead to issue regarding recovery
if (!mNewApn && !mReadOnlyApn && mIsAddApnAllowed) {
menu.add(0, MENU_DELETE, 0, R.string.menu_delete)
.setIcon(R.drawable.ic_delete);
}
@@ -1319,13 +1332,15 @@ public class ApnEditor extends SettingsPreferenceFragment
mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
}
private void getCarrierCustomizedConfig() {
@VisibleForTesting
protected void getCarrierCustomizedConfig(Context context) {
mReadOnlyApn = false;
mReadOnlyApnTypes = null;
mReadOnlyApnFields = null;
mIsAddApnAllowed = true;
final CarrierConfigManager configManager = (CarrierConfigManager)
getSystemService(Context.CARRIER_CONFIG_SERVICE);
context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
if (configManager != null) {
final PersistableBundle b = configManager.getConfigForSubId(mSubId);
if (b != null) {
@@ -1357,6 +1372,11 @@ public class ApnEditor extends SettingsPreferenceFragment
Log.d(TAG, "onCreate: default apn roaming protocol: "
+ mDefaultApnRoamingProtocol);
}
mIsAddApnAllowed = b.getBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL);
if (!mIsAddApnAllowed) {
Log.d(TAG, "onCreate: not allow to add new APN");
}
}
}
}