1 /* 2 * Copyright (C) 2019 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.provider.Settings; 22 import android.telephony.SubscriptionInfo; 23 import android.telephony.euicc.EuiccManager; 24 import android.text.TextUtils; 25 26 import androidx.fragment.app.Fragment; 27 import androidx.preference.Preference; 28 29 import com.android.settings.R; 30 import com.android.settings.core.BasePreferenceController; 31 import com.android.settings.network.SubscriptionUtil; 32 import com.android.settings.security.ConfirmSimDeletionPreferenceController; 33 import com.android.settings.wifi.dpp.WifiDppUtils; 34 35 /** This controls a preference allowing the user to delete the profile for an eSIM. */ 36 public class DeleteSimProfilePreferenceController extends BasePreferenceController { 37 38 private SubscriptionInfo mSubscriptionInfo; 39 private Fragment mParentFragment; 40 private int mRequestCode; 41 private boolean mConfirmationDefaultOn; 42 DeleteSimProfilePreferenceController(Context context, String preferenceKey)43 public DeleteSimProfilePreferenceController(Context context, String preferenceKey) { 44 super(context, preferenceKey); 45 mConfirmationDefaultOn = 46 context.getResources() 47 .getBoolean(R.bool.config_sim_deletion_confirmation_default_on); 48 } 49 init(int subscriptionId, Fragment parentFragment, int requestCode)50 public void init(int subscriptionId, Fragment parentFragment, int requestCode) { 51 mParentFragment = parentFragment; 52 53 for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) { 54 if (info.getSubscriptionId() == subscriptionId && info.isEmbedded()) { 55 mSubscriptionInfo = info; 56 break; 57 } 58 } 59 mRequestCode = requestCode; 60 } 61 62 @Override handlePreferenceTreeClick(Preference preference)63 public boolean handlePreferenceTreeClick(Preference preference) { 64 if (TextUtils.equals(preference.getKey(), getPreferenceKey())) { 65 boolean confirmDeletion = 66 Settings.Global.getInt( 67 mContext.getContentResolver(), 68 ConfirmSimDeletionPreferenceController.KEY_CONFIRM_SIM_DELETION, 69 mConfirmationDefaultOn ? 1 : 0) 70 == 1; 71 if (confirmDeletion) { 72 WifiDppUtils.showLockScreen(mContext, () -> deleteSim()); 73 } else { 74 deleteSim(); 75 } 76 77 return true; 78 } 79 80 return false; 81 } 82 deleteSim()83 private void deleteSim() { 84 SubscriptionUtil.startDeleteEuiccSubscriptionDialogActivity( 85 mContext, mSubscriptionInfo.getSubscriptionId()); 86 // result handled in MobileNetworkSettings 87 } 88 89 @Override getAvailabilityStatus()90 public int getAvailabilityStatus() { 91 if (mSubscriptionInfo != null) { 92 return AVAILABLE; 93 } else { 94 return CONDITIONALLY_UNAVAILABLE; 95 } 96 } 97 } 98