[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:
@@ -32,6 +32,7 @@ import android.telephony.SubscriptionInfo;
|
|||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.euicc.EuiccManager;
|
import android.telephony.euicc.EuiccManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -53,7 +54,9 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
|
|||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirm and execute a reset of the device's network settings to a clean "just out of the box"
|
* Confirm and execute a reset of the device's network settings to a clean "just out of the box"
|
||||||
@@ -112,7 +115,7 @@ public class ResetNetwork extends InstrumentedFragment {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
showFinalConfirmation();
|
showFinalConfirmation();
|
||||||
} else {
|
} else {
|
||||||
establishInitialState();
|
establishInitialState(getActiveSubscriptionInfoList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,14 +164,15 @@ public class ResetNetwork extends InstrumentedFragment {
|
|||||||
* inflate each view, caching all of the widget pointers we'll need at the
|
* inflate each view, caching all of the widget pointers we'll need at the
|
||||||
* time, then simply reuse the inflated views directly whenever we need
|
* time, then simply reuse the inflated views directly whenever we need
|
||||||
* to change contents.
|
* to change contents.
|
||||||
|
*
|
||||||
|
* @param subscriptionsList is a list of SubscriptionInfo(s) which allow user to select from
|
||||||
*/
|
*/
|
||||||
private void establishInitialState() {
|
private void establishInitialState(List<SubscriptionInfo> subscriptionsList) {
|
||||||
mSubscriptionSpinner = (Spinner) mContentView.findViewById(R.id.reset_network_subscription);
|
mSubscriptionSpinner = (Spinner) mContentView.findViewById(R.id.reset_network_subscription);
|
||||||
mEsimContainer = mContentView.findViewById(R.id.erase_esim_container);
|
mEsimContainer = mContentView.findViewById(R.id.erase_esim_container);
|
||||||
mEsimCheckbox = mContentView.findViewById(R.id.erase_esim);
|
mEsimCheckbox = mContentView.findViewById(R.id.erase_esim);
|
||||||
|
|
||||||
mSubscriptions = SubscriptionManager.from(getActivity())
|
mSubscriptions = subscriptionsList;
|
||||||
.getActiveSubscriptionInfoList();
|
|
||||||
if (mSubscriptions != null && mSubscriptions.size() > 0) {
|
if (mSubscriptions != null && mSubscriptions.size() > 0) {
|
||||||
// Get the default subscription in the order of data, voice, sms, first up.
|
// Get the default subscription in the order of data, voice, sms, first up.
|
||||||
int defaultSubscription = SubscriptionManager.getDefaultDataSubscriptionId();
|
int defaultSubscription = SubscriptionManager.getDefaultDataSubscriptionId();
|
||||||
@@ -231,6 +235,31 @@ public class ResetNetwork extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
|
||||||
|
SubscriptionManager mgr = getActivity().getSystemService(SubscriptionManager.class);
|
||||||
|
if (mgr == null) {
|
||||||
|
Log.w(TAG, "No SubscriptionManager");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(mgr.getActiveSubscriptionInfoList())
|
||||||
|
.orElse(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// update options if subcription has been changed
|
||||||
|
List<SubscriptionInfo> updatedSubscriptions = getActiveSubscriptionInfoList();
|
||||||
|
if ((mSubscriptions != null)
|
||||||
|
&& (mSubscriptions.size() == updatedSubscriptions.size())
|
||||||
|
&& mSubscriptions.containsAll(updatedSubscriptions)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "subcription list changed");
|
||||||
|
establishInitialState(updatedSubscriptions);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean showEuiccSettings(Context context) {
|
private boolean showEuiccSettings(Context context) {
|
||||||
EuiccManager euiccManager =
|
EuiccManager euiccManager =
|
||||||
(EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
|
(EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
|
||||||
@@ -261,7 +290,7 @@ public class ResetNetwork extends InstrumentedFragment {
|
|||||||
|
|
||||||
mContentView = inflater.inflate(R.layout.reset_network, null);
|
mContentView = inflater.inflate(R.layout.reset_network, null);
|
||||||
|
|
||||||
establishInitialState();
|
establishInitialState(getActiveSubscriptionInfoList());
|
||||||
return mContentView;
|
return mContentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,11 +32,14 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.net.wifi.p2p.WifiP2pManager;
|
import android.net.wifi.p2p.WifiP2pManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.RecoverySystem;
|
import android.os.RecoverySystem;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -63,6 +66,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
|
|||||||
* This is the confirmation screen.
|
* This is the confirmation screen.
|
||||||
*/
|
*/
|
||||||
public class ResetNetworkConfirm extends InstrumentedFragment {
|
public class ResetNetworkConfirm extends InstrumentedFragment {
|
||||||
|
private static final String TAG = "ResetNetworkConfirm";
|
||||||
|
|
||||||
@VisibleForTesting View mContentView;
|
@VisibleForTesting View mContentView;
|
||||||
@VisibleForTesting boolean mEraseEsim;
|
@VisibleForTesting boolean mEraseEsim;
|
||||||
@@ -71,6 +75,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
private ProgressDialog mProgressDialog;
|
private ProgressDialog mProgressDialog;
|
||||||
private AlertDialog mAlertDialog;
|
private AlertDialog mAlertDialog;
|
||||||
|
private OnSubscriptionsChangedListener mSubscriptionsChangedListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async task used to do all reset task. If error happens during
|
* Async task used to do all reset task. If error happens during
|
||||||
@@ -161,6 +166,18 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
return;
|
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 = getProgressDialog(mActivity);
|
||||||
mProgressDialog.show();
|
mProgressDialog.show();
|
||||||
|
|
||||||
@@ -255,6 +272,56 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mActivity = getActivity();
|
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
|
@Override
|
||||||
@@ -269,6 +336,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
|||||||
if (mAlertDialog != null) {
|
if (mAlertDialog != null) {
|
||||||
mAlertDialog.dismiss();
|
mAlertDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
stopMonitorSubscriptionChange(getSubscriptionManager());
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user