1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.sim; 18 19 import android.os.Bundle; 20 import android.telephony.SubscriptionInfo; 21 import android.util.Log; 22 23 import com.android.settings.R; 24 import com.android.settings.SidecarFragment; 25 import com.android.settings.network.SwitchToEuiccSubscriptionSidecar; 26 import com.android.settings.network.UiccSlotUtil; 27 import com.android.settings.network.telephony.AlertDialogFragment; 28 import com.android.settings.network.telephony.ConfirmDialogFragment; 29 import com.android.settings.network.telephony.SubscriptionActionDialogActivity; 30 31 /** 32 * Starts a confirm dialog asking the user to switch to the eSIM slot/subscription. The caller needs 33 * to pass in the current enabled eSIM subscription, which is also the subscription to switch to. 34 */ 35 public class SwitchToEsimConfirmDialogActivity extends SubscriptionActionDialogActivity 36 implements SidecarFragment.Listener, ConfirmDialogFragment.OnConfirmListener { 37 38 public static final String KEY_SUB_TO_ENABLE = "sub_to_enable"; 39 40 private static final String TAG = "SwitchToEsimConfirmDialogActivity"; 41 private static final int TAG_CONFIRM = 1; 42 43 private SubscriptionInfo mSubToEnabled = null; 44 private SwitchToEuiccSubscriptionSidecar mSwitchToEuiccSubscriptionSidecar; 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 50 mSubToEnabled = getIntent().getParcelableExtra(KEY_SUB_TO_ENABLE); 51 mSwitchToEuiccSubscriptionSidecar = 52 SwitchToEuiccSubscriptionSidecar.get(getFragmentManager()); 53 54 if (mSubToEnabled == null) { 55 Log.e(TAG, "Cannot find SIM to enable."); 56 finish(); 57 return; 58 } 59 60 if (savedInstanceState == null) { 61 ConfirmDialogFragment.show( 62 this, 63 ConfirmDialogFragment.OnConfirmListener.class, 64 TAG_CONFIRM, 65 getString(R.string.switch_sim_dialog_title, mSubToEnabled.getDisplayName()), 66 getString(R.string.switch_sim_dialog_text, mSubToEnabled.getDisplayName()), 67 getString(R.string.okay), 68 getString(R.string.cancel)); 69 } 70 } 71 72 @Override onResume()73 public void onResume() { 74 super.onResume(); 75 mSwitchToEuiccSubscriptionSidecar.addListener(this); 76 } 77 78 @Override onPause()79 public void onPause() { 80 mSwitchToEuiccSubscriptionSidecar.removeListener(this); 81 super.onPause(); 82 } 83 84 @Override onStateChange(SidecarFragment fragment)85 public void onStateChange(SidecarFragment fragment) { 86 if (fragment == mSwitchToEuiccSubscriptionSidecar) { 87 switch (mSwitchToEuiccSubscriptionSidecar.getState()) { 88 case SidecarFragment.State.SUCCESS: 89 mSwitchToEuiccSubscriptionSidecar.reset(); 90 Log.i(TAG, "Successfully switched to eSIM slot."); 91 dismissProgressDialog(); 92 finish(); 93 break; 94 case SidecarFragment.State.ERROR: 95 mSwitchToEuiccSubscriptionSidecar.reset(); 96 Log.e(TAG, "Failed switching to eSIM slot."); 97 dismissProgressDialog(); 98 finish(); 99 break; 100 } 101 } 102 } 103 104 @Override onConfirm(int tag, boolean confirmed, int itemPosition)105 public void onConfirm(int tag, boolean confirmed, int itemPosition) { 106 if (!confirmed) { 107 AlertDialogFragment.show( 108 this, 109 getString(R.string.switch_sim_dialog_no_switch_title), 110 getString(R.string.switch_sim_dialog_no_switch_text)); 111 return; 112 } 113 Log.i(TAG, "User confirmed to switch to embedded slot."); 114 mSwitchToEuiccSubscriptionSidecar.run(mSubToEnabled.getSubscriptionId(), 115 UiccSlotUtil.INVALID_PORT_ID, null); 116 showProgressDialog( 117 getString( 118 R.string.sim_action_switch_sub_dialog_progress, 119 mSubToEnabled.getDisplayName())); 120 } 121 } 122