[Settings] Close reset network confirm dialog when SIM removed

When SIM removed, the network reset confirm UI no longer represents
the wordings which presented to the user.

Proceed on resetting will only reset APN on removed SIM and
lead to some side effect if user inserted a new SIM while
keeping displaying the confirmation dialog.

With this situation, close the confirmation dialog is current
decision in design. And the UI which prior to the confirm UI
also need to be updated to avoid from user accessing that
removed SIM.

Bug: 171070050
Test: manual
Change-Id: I338835ca98593f95d98bafa70f12b177c43bf91a
This commit is contained in:
Bonian Chen
2020-12-15 03:57:43 +08:00
parent 0306871503
commit 0da056b2dd
2 changed files with 102 additions and 5 deletions

View File

@@ -32,11 +32,14 @@ import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Looper;
import android.os.RecoverySystem;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -63,6 +66,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
* This is the confirmation screen.
*/
public class ResetNetworkConfirm extends InstrumentedFragment {
private static final String TAG = "ResetNetworkConfirm";
@VisibleForTesting View mContentView;
@VisibleForTesting boolean mEraseEsim;
@@ -71,6 +75,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private ProgressDialog mProgressDialog;
private AlertDialog mAlertDialog;
private OnSubscriptionsChangedListener mSubscriptionsChangedListener;
/**
* Async task used to do all reset task. If error happens during
@@ -161,6 +166,18 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
return;
}
// abandon execution if subscription no longer active
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
SubscriptionManager mgr = getSubscriptionManager();
// always remove listener
stopMonitorSubscriptionChange(mgr);
if (!isSubscriptionRemainActive(mgr, mSubId)) {
Log.w(TAG, "subId " + mSubId + " disappear when confirm");
mActivity.finish();
return;
}
}
mProgressDialog = getProgressDialog(mActivity);
mProgressDialog.show();
@@ -255,6 +272,56 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
}
mActivity = getActivity();
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
return;
}
// close confirmation dialog when reset specific subscription
// but removed priori to the confirmation button been pressed
startMonitorSubscriptionChange(getSubscriptionManager());
}
private SubscriptionManager getSubscriptionManager() {
SubscriptionManager mgr = mActivity.getSystemService(SubscriptionManager.class);
if (mgr == null) {
Log.w(TAG, "No SubscriptionManager");
}
return mgr;
}
private void startMonitorSubscriptionChange(SubscriptionManager mgr) {
if (mgr == null) {
return;
}
// update monitor listener
mSubscriptionsChangedListener = new OnSubscriptionsChangedListener(
Looper.getMainLooper()) {
@Override
public void onSubscriptionsChanged() {
SubscriptionManager mgr = getSubscriptionManager();
if (isSubscriptionRemainActive(mgr, mSubId)) {
return;
}
// close UI if subscription no longer active
Log.w(TAG, "subId " + mSubId + " no longer active.");
stopMonitorSubscriptionChange(mgr);
mActivity.finish();
}
};
mgr.addOnSubscriptionsChangedListener(
mActivity.getMainExecutor(), mSubscriptionsChangedListener);
}
private boolean isSubscriptionRemainActive(SubscriptionManager mgr, int subscriptionId) {
return (mgr == null) ? false : (mgr.getActiveSubscriptionInfo(subscriptionId) != null);
}
private void stopMonitorSubscriptionChange(SubscriptionManager mgr) {
if ((mgr == null) || (mSubscriptionsChangedListener == null)) {
return;
}
mgr.removeOnSubscriptionsChangedListener(mSubscriptionsChangedListener);
mSubscriptionsChangedListener = null;
}
@Override
@@ -269,6 +336,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
if (mAlertDialog != null) {
mAlertDialog.dismiss();
}
stopMonitorSubscriptionChange(getSubscriptionManager());
super.onDestroy();
}