diff --git a/src/com/android/settings/ResetNetwork.java b/src/com/android/settings/ResetNetwork.java index ad9f35e889b..f86e29f14d1 100644 --- a/src/com/android/settings/ResetNetwork.java +++ b/src/com/android/settings/ResetNetwork.java @@ -18,8 +18,11 @@ package com.android.settings; import android.app.Activity; import android.app.settings.SettingsEnums; +import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Resources; import android.os.Bundle; import android.provider.Settings; @@ -66,7 +69,7 @@ import java.util.Optional; * prompt, followed by a keyguard pattern trace if the user has defined one, followed by a final * strongly-worded "THIS WILL RESET EVERYTHING" prompt. If at any time the phone is allowed to go * to sleep, is locked, et cetera, then the confirmation sequence is abandoned. - * + *

* This is the initial screen. */ public class ResetNetwork extends InstrumentedFragment { @@ -81,8 +84,20 @@ public class ResetNetwork extends InstrumentedFragment { private View mContentView; private Spinner mSubscriptionSpinner; private Button mInitiateButton; - @VisibleForTesting View mEsimContainer; - @VisibleForTesting CheckBox mEsimCheckbox; + @VisibleForTesting + View mEsimContainer; + @VisibleForTesting + CheckBox mEsimCheckbox; + + private BroadcastReceiver mDefaultSubChangeReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction() != SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED) { + return; + } + establishInitialState(getActiveSubscriptionInfoList()); + } + }; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -97,6 +112,7 @@ public class ResetNetwork extends InstrumentedFragment { /** * Keyguard validation is run using the standard {@link ConfirmLockPattern} * component as a subactivity + * * @param request the request code to be returned once confirmation finishes * @return true if confirmation launched */ @@ -139,7 +155,7 @@ public class ResetNetwork extends InstrumentedFragment { SubscriptionInfo subscription = mSubscriptions.get(selectedIndex); int subId = subscription.getSubscriptionId(); request.setResetTelephonyAndNetworkPolicyManager(subId) - .setResetApn(subId); + .setResetApn(subId); if (Flags.resetMobileNetworkSettings()) { request.setResetImsSubId(subId); } @@ -215,7 +231,6 @@ public class ResetNetwork extends InstrumentedFragment { } int selectedIndex = 0; - int size = mSubscriptions.size(); List subscriptionNames = new ArrayList<>(); for (SubscriptionInfo record : mSubscriptions) { if (record.getSubscriptionId() == defaultSubscription) { @@ -281,6 +296,8 @@ public class ResetNetwork extends InstrumentedFragment { @Override public void onResume() { super.onResume(); + getContext().registerReceiver(mDefaultSubChangeReceiver, + new IntentFilter(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED)); if (mContentView == null) { return; @@ -297,6 +314,12 @@ public class ResetNetwork extends InstrumentedFragment { establishInitialState(updatedSubscriptions); } + @Override + public void onPause() { + super.onPause(); + getContext().unregisterReceiver(mDefaultSubChangeReceiver); + } + private boolean showEuiccSettings(Context context) { if (!SubscriptionUtil.isSimHardwareVisible(context)) { return false;