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; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.settings.SettingsEnums; 22 import android.content.Context; 23 import android.content.DialogInterface; 24 import android.os.AsyncTask; 25 import android.os.Bundle; 26 import android.util.Log; 27 28 import androidx.annotation.NonNull; 29 import androidx.annotation.Nullable; 30 import androidx.fragment.app.Fragment; 31 import androidx.fragment.app.FragmentManager; 32 33 import com.android.settings.R; 34 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 35 import com.android.settings.system.ResetDashboardFragment; 36 import com.android.settings.network.telephony.MobileNetworkUtils; 37 38 public class EraseEuiccDataDialogFragment extends InstrumentedDialogFragment implements 39 DialogInterface.OnClickListener { 40 41 public static final String TAG = "EraseEuiccDataDlg"; 42 private static final String PACKAGE_NAME_EUICC_DATA_MANAGEMENT_CALLBACK = 43 "com.android.settings.network"; 44 show(ResetDashboardFragment host)45 public static void show(ResetDashboardFragment host) { 46 if (host.getActivity() == null) { 47 return; 48 } 49 final EraseEuiccDataDialogFragment dialog = new EraseEuiccDataDialogFragment(); 50 dialog.setTargetFragment(host, 0 /* requestCode */); 51 final FragmentManager manager = host.getActivity().getSupportFragmentManager(); 52 dialog.show(manager, TAG); 53 } 54 55 @Override getMetricsCategory()56 public int getMetricsCategory() { 57 return SettingsEnums.RESET_EUICC; 58 } 59 60 @NonNull 61 @Override onCreateDialog(@ullable Bundle savedInstanceState)62 public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { 63 return new AlertDialog.Builder(getActivity()) 64 .setTitle(R.string.reset_esim_title) 65 .setMessage(R.string.reset_esim_desc) 66 .setPositiveButton(R.string.erase_sim_confirm_button, this) 67 .setNegativeButton(R.string.cancel, null) 68 .setOnDismissListener(this) 69 .create(); 70 } 71 72 @Override onClick(DialogInterface dialog, int which)73 public void onClick(DialogInterface dialog, int which) { 74 final Fragment fragment = getTargetFragment(); 75 if (!(fragment instanceof ResetDashboardFragment)) { 76 Log.e(TAG, "getTargetFragment return unexpected type"); 77 } 78 79 if (which == DialogInterface.BUTTON_POSITIVE) { 80 Context context = getContext(); 81 MobileNetworkUtils.showLockScreen(context, () -> runAsyncWipe(context)); 82 } 83 } 84 runAsyncWipe(Context context)85 private void runAsyncWipe(Context context) { 86 Runnable runnable = (new ResetNetworkOperationBuilder(context)) 87 .resetEsim(PACKAGE_NAME_EUICC_DATA_MANAGEMENT_CALLBACK) 88 .build(); 89 AsyncTask.execute(runnable); 90 } 91 } 92