[SIM Dialog Migration] Migrate SIM enable dialog from LPA to Settings

Migrates SIM enabling and DSDS dialog from LPA to Settings.
Design: https://docs.google.com/document/d/1wb5_hoBkZVbkXGNWHbx4Jf61swjfxsJzkytiTzJosYo/edit?usp=sharing
Bug: 160819390
Test: Manually tested eSIM profile enabling.

Change-Id: I9ce690a1594adfc90b62840819237acd54418469
This commit is contained in:
Jiashen Wang
2020-10-29 16:55:43 -07:00
parent 903a211665
commit 7840ae7569
9 changed files with 1095 additions and 14 deletions

View File

@@ -22,15 +22,22 @@ import android.os.Bundle;
import android.os.UserManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccSlotInfo;
import android.text.TextUtils;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.SidecarFragment;
import com.android.settings.network.EnableMultiSimSidecar;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.SwitchToEuiccSubscriptionSidecar;
import com.android.settings.network.SwitchToRemovableSlotSidecar;
import com.android.settings.network.UiccSlotUtil;
import com.google.common.collect.ImmutableList;
import java.util.List;
/** This dialog activity handles both eSIM and pSIM subscriptions enabling and disabling. */
public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogActivity
@@ -41,6 +48,11 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
private static final String ARG_enable = "enable";
// Dialog tags
private static final int DIALOG_TAG_DISABLE_SIM_CONFIRMATION = 1;
private static final int DIALOG_TAG_ENABLE_SIM_CONFIRMATION = 2;
private static final int DIALOG_TAG_ENABLE_DSDS_CONFIRMATION = 3;
private static final int DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION = 4;
// Number of SIMs for DSDS
private static final int NUM_OF_SIMS_FOR_DSDS = 2;
/**
* Returns an intent of ToggleSubscriptionDialogActivity.
@@ -58,8 +70,11 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
private SubscriptionInfo mSubInfo;
private SwitchToEuiccSubscriptionSidecar mSwitchToEuiccSubscriptionSidecar;
private AlertDialog mToggleSimConfirmDialog;
private SwitchToRemovableSlotSidecar mSwitchToRemovableSlotSidecar;
private EnableMultiSimSidecar mEnableMultiSimSidecar;
private boolean mEnable;
private boolean mIsEsimOperation;
private TelephonyManager mTelMgr;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -67,6 +82,7 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
Intent intent = getIntent();
int subId = intent.getIntExtra(ARG_SUB_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
mTelMgr = getSystemService(TelephonyManager.class);
UserManager userManager = getSystemService(UserManager.class);
if (!userManager.isAdminUser()) {
@@ -82,13 +98,16 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
}
mSubInfo = SubscriptionUtil.getSubById(mSubscriptionManager, subId);
mIsEsimOperation = mSubInfo != null && mSubInfo.isEmbedded();
mSwitchToEuiccSubscriptionSidecar =
SwitchToEuiccSubscriptionSidecar.get(getFragmentManager());
mSwitchToRemovableSlotSidecar = SwitchToRemovableSlotSidecar.get(getFragmentManager());
mEnableMultiSimSidecar = EnableMultiSimSidecar.get(getFragmentManager());
mEnable = intent.getBooleanExtra(ARG_enable, true);
if (savedInstanceState == null) {
if (mEnable) {
handleEnablingSubAction();
showEnableSubDialog();
} else {
showDisableSimConfirmDialog();
}
@@ -99,10 +118,14 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
protected void onResume() {
super.onResume();
mSwitchToEuiccSubscriptionSidecar.addListener(this);
mSwitchToRemovableSlotSidecar.addListener(this);
mEnableMultiSimSidecar.addListener(this);
}
@Override
protected void onPause() {
mEnableMultiSimSidecar.removeListener(this);
mSwitchToRemovableSlotSidecar.removeListener(this);
mSwitchToEuiccSubscriptionSidecar.removeListener(this);
super.onPause();
}
@@ -111,19 +134,25 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
public void onStateChange(SidecarFragment fragment) {
if (fragment == mSwitchToEuiccSubscriptionSidecar) {
handleSwitchToEuiccSubscriptionSidecarStateChange();
} else if (fragment == mSwitchToRemovableSlotSidecar) {
handleSwitchToRemovableSlotSidecarStateChange();
} else if (fragment == mEnableMultiSimSidecar) {
handleEnableMultiSimSidecarStateChange();
}
}
@Override
public void onConfirm(int tag, boolean confirmed) {
if (!confirmed) {
if (!confirmed
&& tag != DIALOG_TAG_ENABLE_DSDS_CONFIRMATION
&& tag != DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION) {
finish();
return;
}
switch (tag) {
case DIALOG_TAG_DISABLE_SIM_CONFIRMATION:
if (mSubInfo.isEmbedded()) {
if (mIsEsimOperation) {
Log.i(TAG, "Disabling the eSIM profile.");
showProgressDialog(
getString(R.string.privileged_action_disable_sub_dialog_progress));
@@ -132,6 +161,51 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
return;
}
Log.i(TAG, "Disabling the pSIM profile.");
handleTogglePsimAction();
break;
case DIALOG_TAG_ENABLE_DSDS_CONFIRMATION:
if (!confirmed) {
Log.i(TAG, "User cancel the dialog to enable DSDS.");
showEnableSimConfirmDialog();
return;
}
if (mTelMgr.doesSwitchMultiSimConfigTriggerReboot()) {
Log.i(TAG, "Device does not support reboot free DSDS.");
showRebootConfirmDialog();
return;
}
Log.i(
TAG,
"Enabling DSDS without rebooting. "
+ getString(R.string.sim_action_enabling_sim_without_carrier_name));
showProgressDialog(
getString(R.string.sim_action_enabling_sim_without_carrier_name));
mEnableMultiSimSidecar.run(NUM_OF_SIMS_FOR_DSDS);
break;
case DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION:
if (!confirmed) {
Log.i(TAG, "User cancel the dialog to reboot to enable DSDS.");
showEnableSimConfirmDialog();
return;
}
Log.i(TAG, "User confirmed reboot to enable DSDS.");
mTelMgr.switchMultiSimConfig(NUM_OF_SIMS_FOR_DSDS);
// TODO(b/170507290): Store a bit in preferences for displaying the notification
// after the reboot.
break;
case DIALOG_TAG_ENABLE_SIM_CONFIRMATION:
Log.i(TAG, "User confirmed to enable the subscription.");
if (mIsEsimOperation) {
showProgressDialog(
getString(
R.string.sim_action_switch_sub_dialog_progress,
mSubInfo.getDisplayName()));
mSwitchToEuiccSubscriptionSidecar.run(mSubInfo.getSubscriptionId());
return;
}
showProgressDialog(
getString(R.string.sim_action_enabling_sim_without_carrier_name));
mSwitchToRemovableSlotSidecar.run(UiccSlotUtil.INVALID_PHYSICAL_SLOT_ID);
break;
default:
Log.e(TAG, "Unrecognized confirmation dialog tag: " + tag);
@@ -165,10 +239,105 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
}
}
private void handleSwitchToRemovableSlotSidecarStateChange() {
switch (mSwitchToRemovableSlotSidecar.getState()) {
case SidecarFragment.State.SUCCESS:
Log.i(TAG, "Successfully switched to removable slot.");
mSwitchToRemovableSlotSidecar.reset();
handleTogglePsimAction();
dismissProgressDialog();
finish();
break;
case SidecarFragment.State.ERROR:
Log.e(TAG, "Failed switching to removable slot.");
mSwitchToRemovableSlotSidecar.reset();
dismissProgressDialog();
showErrorDialog(
getString(R.string.sim_action_enable_sim_fail_title),
getString(R.string.sim_action_enable_sim_fail_text));
break;
}
}
private void handleEnableMultiSimSidecarStateChange() {
switch (mEnableMultiSimSidecar.getState()) {
case SidecarFragment.State.SUCCESS:
mEnableMultiSimSidecar.reset();
Log.i(TAG, "Successfully switched to DSDS without reboot.");
handleEnableSubscriptionAfterEnablingDsds();
break;
case SidecarFragment.State.ERROR:
mEnableMultiSimSidecar.reset();
Log.i(TAG, "Failed to switch to DSDS without rebooting.");
ProgressDialogFragment.dismiss(getFragmentManager());
showErrorDialog(
getString(R.string.dsds_activation_failure_title),
getString(R.string.dsds_activation_failure_body_msg2));
break;
}
}
private void handleEnableSubscriptionAfterEnablingDsds() {
if (mIsEsimOperation) {
Log.i(TAG, "DSDS enabled, start to enable profile: " + mSubInfo.getSubscriptionId());
// For eSIM operations, we simply switch to the selected eSIM profile.
mSwitchToEuiccSubscriptionSidecar.run(mSubInfo.getSubscriptionId());
return;
}
Log.i(TAG, "DSDS enabled, start to enable pSIM profile.");
handleTogglePsimAction();
ProgressDialogFragment.dismiss(getFragmentManager());
finish();
}
private void handleTogglePsimAction() {
if (mSubscriptionManager.canDisablePhysicalSubscription() && mSubInfo != null) {
mSubscriptionManager.setUiccApplicationsEnabled(mSubInfo.getSubscriptionId(), mEnable);
} else {
Log.i(
TAG,
"The device does not support toggling pSIM. It is enough to just "
+ "enable the removable slot.");
}
}
/* Handles the enabling SIM action. */
private void handleEnablingSubAction() {
Log.i(TAG, "handleEnableSub");
// TODO(b/160819390): Implement enabling eSIM/pSIM profile.
private void showEnableSubDialog() {
Log.i(TAG, "Handle subscription enabling.");
if (isDsdsConditionSatisfied()) {
showEnableDsdsConfirmDialog();
return;
}
if (!mIsEsimOperation && mTelMgr.isMultiSimEnabled()) {
Log.i(TAG, "Toggle on pSIM, no dialog displayed.");
handleTogglePsimAction();
finish();
return;
}
showEnableSimConfirmDialog();
}
private void showEnableDsdsConfirmDialog() {
ConfirmDialogFragment.show(
this,
ConfirmDialogFragment.OnConfirmListener.class,
DIALOG_TAG_ENABLE_DSDS_CONFIRMATION,
getString(R.string.sim_action_enable_dsds_title),
getString(R.string.sim_action_enable_dsds_text),
getString(R.string.sim_action_continue),
getString(R.string.sim_action_no_thanks));
}
private void showRebootConfirmDialog() {
ConfirmDialogFragment.show(
this,
ConfirmDialogFragment.OnConfirmListener.class,
DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION,
getString(R.string.sim_action_restart_title),
getString(R.string.sim_action_enable_dsds_text),
getString(R.string.sim_action_reboot),
getString(R.string.cancel));
}
/* Displays the SIM toggling confirmation dialog. */
@@ -191,10 +360,116 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc
getString(R.string.cancel));
}
/* Dismisses the SIM toggling confirmation dialog. */
private void dismissToggleSimConfirmDialog() {
if (mToggleSimConfirmDialog != null) {
mToggleSimConfirmDialog.dismiss();
private void showEnableSimConfirmDialog() {
List<SubscriptionInfo> activeSubs =
SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager);
SubscriptionInfo activeSub = activeSubs.isEmpty() ? null : activeSubs.get(0);
if (activeSub == null) {
Log.i(TAG, "No active subscriptions available.");
showNonSwitchSimConfirmDialog();
return;
}
Log.i(TAG, "Found active subscription.");
boolean isBetweenEsim = mIsEsimOperation && activeSub.isEmbedded();
if (mTelMgr.isMultiSimEnabled() && !isBetweenEsim) {
showNonSwitchSimConfirmDialog();
return;
}
ConfirmDialogFragment.show(
this,
ConfirmDialogFragment.OnConfirmListener.class,
DIALOG_TAG_ENABLE_SIM_CONFIRMATION,
getSwitchSubscriptionTitle(),
getSwitchDialogBodyMsg(activeSub, isBetweenEsim),
getSwitchDialogPosBtnText(),
getString(android.R.string.cancel));
}
private void showNonSwitchSimConfirmDialog() {
ConfirmDialogFragment.show(
this,
ConfirmDialogFragment.OnConfirmListener.class,
DIALOG_TAG_ENABLE_SIM_CONFIRMATION,
getEnableSubscriptionTitle(),
null /* msg */,
getString(R.string.yes),
getString(android.R.string.cancel));
}
private String getSwitchDialogPosBtnText() {
return mIsEsimOperation
? getString(
R.string.sim_action_switch_sub_dialog_confirm, mSubInfo.getDisplayName())
: getString(R.string.sim_switch_button);
}
private String getEnableSubscriptionTitle() {
if (mSubInfo == null || TextUtils.isEmpty(mSubInfo.getDisplayName())) {
return getString(R.string.sim_action_enable_sub_dialog_title_without_carrier_name);
}
return getString(R.string.sim_action_enable_sub_dialog_title, mSubInfo.getDisplayName());
}
private String getSwitchSubscriptionTitle() {
if (mIsEsimOperation) {
return getString(
R.string.sim_action_switch_sub_dialog_title, mSubInfo.getDisplayName());
}
return getString(R.string.sim_action_switch_psim_dialog_title);
}
private String getSwitchDialogBodyMsg(SubscriptionInfo activeSub, boolean betweenEsim) {
if (betweenEsim && mIsEsimOperation) {
return getString(
R.string.sim_action_switch_sub_dialog_text_downloaded,
mSubInfo.getDisplayName(),
activeSub.getDisplayName());
} else if (mIsEsimOperation) {
return getString(
R.string.sim_action_switch_sub_dialog_text,
mSubInfo.getDisplayName(),
activeSub.getDisplayName());
} else {
return getString(
R.string.sim_action_switch_sub_dialog_text_single_sim,
activeSub.getDisplayName());
}
}
private boolean isDsdsConditionSatisfied() {
if (mTelMgr.isMultiSimEnabled()) {
Log.i(TAG, "DSDS is already enabled. Condition not satisfied.");
return false;
}
if (mTelMgr.isMultiSimSupported() != TelephonyManager.MULTISIM_ALLOWED) {
Log.i(TAG, "Hardware does not support DSDS.");
return false;
}
ImmutableList<UiccSlotInfo> slotInfos = UiccSlotUtil.getSlotInfos(mTelMgr);
boolean isRemovableSimEnabled =
slotInfos.stream()
.anyMatch(
slot ->
slot != null
&& slot.isRemovable()
&& slot.getIsActive()
&& slot.getCardStateInfo()
== UiccSlotInfo.CARD_STATE_INFO_PRESENT);
if (mIsEsimOperation && isRemovableSimEnabled) {
Log.i(TAG, "eSIM operation and removable SIM is enabled. DSDS condition satisfied.");
return true;
}
boolean isEsimProfileEnabled =
SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager).stream()
.anyMatch(SubscriptionInfo::isEmbedded);
if (!mIsEsimOperation && isEsimProfileEnabled) {
Log.i(
TAG,
"Removable SIM operation and eSIM profile is enabled. DSDS condition"
+ " satisfied.");
return true;
}
Log.i(TAG, "DSDS condition not satisfied.");
return false;
}
}