1 /* 2 * Copyright (C) 2020 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.network.telephony; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.telephony.SubscriptionInfo; 23 import android.telephony.SubscriptionManager; 24 import android.util.Log; 25 26 import com.android.settings.R; 27 import com.android.settings.SidecarFragment; 28 import com.android.settings.network.SubscriptionUtil; 29 30 import java.util.List; 31 32 /** This dialog activity handles deleting eSIM profiles. */ 33 public class DeleteEuiccSubscriptionDialogActivity extends SubscriptionActionDialogActivity 34 implements SidecarFragment.Listener, ConfirmDialogFragment.OnConfirmListener { 35 36 private static final String TAG = "DeleteEuiccSubscriptionDialogActivity"; 37 // Dialog tags 38 private static final int DIALOG_TAG_DELETE_SIM_CONFIRMATION = 1; 39 40 /** 41 * Returns an intent of DeleteEuiccSubscriptionDialogActivity. 42 * 43 * @param context The context used to start the DeleteEuiccSubscriptionDialogActivity. 44 * @param subId The subscription ID of the subscription needs to be deleted. If the subscription 45 * belongs to a group of subscriptions, all subscriptions from the group will be deleted. 46 */ getIntent(Context context, int subId)47 public static Intent getIntent(Context context, int subId) { 48 Intent intent = new Intent(context, DeleteEuiccSubscriptionDialogActivity.class); 49 intent.putExtra(ARG_SUB_ID, subId); 50 return intent; 51 } 52 53 private DeleteEuiccSubscriptionSidecar mDeleteEuiccSubscriptionSidecar; 54 private List<SubscriptionInfo> mSubscriptionsToBeDeleted; 55 private SubscriptionInfo mSubscriptionToBeDeleted; 56 57 @Override onCreate(Bundle savedInstanceState)58 protected void onCreate(Bundle savedInstanceState) { 59 super.onCreate(savedInstanceState); 60 61 Intent intent = getIntent(); 62 int subId = intent.getIntExtra(ARG_SUB_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID); 63 mSubscriptionToBeDeleted = SubscriptionUtil.getSubById(mSubscriptionManager, subId); 64 mSubscriptionsToBeDeleted = 65 SubscriptionUtil.findAllSubscriptionsInGroup(mSubscriptionManager, subId); 66 67 if (mSubscriptionToBeDeleted == null || mSubscriptionsToBeDeleted.isEmpty()) { 68 Log.e(TAG, "Cannot find subscription with sub ID: " + subId); 69 finish(); 70 return; 71 } 72 73 mDeleteEuiccSubscriptionSidecar = DeleteEuiccSubscriptionSidecar.get(getFragmentManager()); 74 if (savedInstanceState == null) { 75 showDeleteSimConfirmDialog(); 76 } 77 } 78 79 @Override onResume()80 protected void onResume() { 81 super.onResume(); 82 mDeleteEuiccSubscriptionSidecar.addListener(this); 83 } 84 85 @Override onPause()86 protected void onPause() { 87 mDeleteEuiccSubscriptionSidecar.removeListener(this); 88 super.onPause(); 89 } 90 91 @Override onStateChange(SidecarFragment fragment)92 public void onStateChange(SidecarFragment fragment) { 93 if (fragment == mDeleteEuiccSubscriptionSidecar) { 94 handleDeleteEuiccSubscriptionSidecarStateChange(); 95 } 96 } 97 98 @Override onConfirm(int tag, boolean confirmed)99 public void onConfirm(int tag, boolean confirmed) { 100 if (!confirmed) { 101 finish(); 102 return; 103 } 104 105 switch (tag) { 106 case DIALOG_TAG_DELETE_SIM_CONFIRMATION: 107 Log.i(TAG, "Subscription deletion confirmed"); 108 showProgressDialog(getString(R.string.erasing_sim)); 109 mDeleteEuiccSubscriptionSidecar.run(mSubscriptionsToBeDeleted); 110 break; 111 default: 112 Log.e(TAG, "Unrecognized confirmation dialog tag: " + tag); 113 break; 114 } 115 } 116 handleDeleteEuiccSubscriptionSidecarStateChange()117 private void handleDeleteEuiccSubscriptionSidecarStateChange() { 118 switch (mDeleteEuiccSubscriptionSidecar.getState()) { 119 case SidecarFragment.State.SUCCESS: 120 Log.i(TAG, "Successfully delete the subscription."); 121 mDeleteEuiccSubscriptionSidecar.reset(); 122 dismissProgressDialog(); 123 finish(); 124 break; 125 case SidecarFragment.State.ERROR: 126 Log.e(TAG, "Failed to delete the subscription."); 127 mDeleteEuiccSubscriptionSidecar.reset(); 128 showErrorDialog( 129 getString(R.string.erase_sim_fail_title), 130 getString(R.string.erase_sim_fail_text)); 131 break; 132 } 133 } 134 135 /* Displays the eSIM deleting confirmation dialog. */ showDeleteSimConfirmDialog()136 private void showDeleteSimConfirmDialog() { 137 ConfirmDialogFragment.show( 138 this, 139 ConfirmDialogFragment.OnConfirmListener.class, 140 DIALOG_TAG_DELETE_SIM_CONFIRMATION, 141 getString(R.string.erase_sim_dialog_title), 142 getString( 143 R.string.erase_sim_dialog_text, 144 SubscriptionUtil.getUniqueSubscriptionDisplayName( 145 mSubscriptionToBeDeleted, this)), 146 getString(R.string.erase_sim_confirm_button), 147 getString(R.string.cancel)); 148 } 149 } 150