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.content.Intent; 20 import android.os.Bundle; 21 import android.telephony.TelephonyManager; 22 import android.util.Log; 23 24 import com.android.settings.R; 25 import com.android.settings.SidecarFragment; 26 import com.android.settings.network.EnableMultiSimSidecar; 27 import com.android.settings.network.telephony.ConfirmDialogFragment; 28 import com.android.settings.network.telephony.SubscriptionActionDialogActivity; 29 30 /** Activity to show the enabling DSDS dialog. */ 31 public class DsdsDialogActivity extends SubscriptionActionDialogActivity 32 implements SidecarFragment.Listener, ConfirmDialogFragment.OnConfirmListener { 33 34 private static final String TAG = "DsdsDialogActivity"; 35 // Dialog tags 36 private static final int DIALOG_TAG_ENABLE_DSDS_CONFIRMATION = 1; 37 private static final int DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION = 2; 38 // Number of SIMs for DSDS 39 private static final int NUM_OF_SIMS_FOR_DSDS = 2; 40 41 private EnableMultiSimSidecar mEnableMultiSimSidecar; 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 47 mEnableMultiSimSidecar = EnableMultiSimSidecar.get(getFragmentManager()); 48 if (savedInstanceState == null) { 49 showEnableDsdsConfirmDialog(); 50 } 51 } 52 53 @Override onResume()54 protected void onResume() { 55 super.onResume(); 56 mEnableMultiSimSidecar.addListener(this); 57 } 58 59 @Override onPause()60 protected void onPause() { 61 mEnableMultiSimSidecar.removeListener(this); 62 super.onPause(); 63 } 64 65 @Override onStateChange(SidecarFragment fragment)66 public void onStateChange(SidecarFragment fragment) { 67 if (fragment == mEnableMultiSimSidecar) { 68 switch (fragment.getState()) { 69 case SidecarFragment.State.SUCCESS: 70 mEnableMultiSimSidecar.reset(); 71 Log.i(TAG, "Enabled DSDS successfully"); 72 dismissProgressDialog(); 73 finish(); 74 break; 75 case SidecarFragment.State.ERROR: 76 mEnableMultiSimSidecar.reset(); 77 Log.e(TAG, "Failed to enable DSDS"); 78 dismissProgressDialog(); 79 showErrorDialog( 80 getString(R.string.dsds_activation_failure_title), 81 getString(R.string.dsds_activation_failure_body_msg2)); 82 break; 83 } 84 } 85 } 86 87 @Override onConfirm(int tag, boolean confirmed, int itemPosition)88 public void onConfirm(int tag, boolean confirmed, int itemPosition) { 89 if (!confirmed) { 90 Log.i(TAG, "User cancel the dialog to enable DSDS."); 91 startChooseSimActivity(); 92 return; 93 } 94 95 TelephonyManager telephonyManager = getSystemService(TelephonyManager.class); 96 switch (tag) { 97 case DIALOG_TAG_ENABLE_DSDS_CONFIRMATION: 98 if (telephonyManager.doesSwitchMultiSimConfigTriggerReboot()) { 99 Log.i(TAG, "Device does not support reboot free DSDS."); 100 showRebootConfirmDialog(); 101 return; 102 } 103 Log.i(TAG, "Enabling DSDS without rebooting."); 104 showProgressDialog( 105 getString(R.string.sim_action_enabling_sim_without_carrier_name)); 106 mEnableMultiSimSidecar.run(NUM_OF_SIMS_FOR_DSDS); 107 break; 108 case DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION: 109 Log.i(TAG, "User confirmed reboot to enable DSDS."); 110 SimActivationNotifier.setShowSimSettingsNotification(this, true); 111 telephonyManager.switchMultiSimConfig(NUM_OF_SIMS_FOR_DSDS); 112 break; 113 default: 114 Log.e(TAG, "Unrecognized confirmation dialog tag: " + tag); 115 break; 116 } 117 } 118 showEnableDsdsConfirmDialog()119 private void showEnableDsdsConfirmDialog() { 120 ConfirmDialogFragment.show( 121 this, 122 ConfirmDialogFragment.OnConfirmListener.class, 123 DIALOG_TAG_ENABLE_DSDS_CONFIRMATION, 124 getString(R.string.sim_action_enable_dsds_title), 125 getString(R.string.sim_action_enable_dsds_text), 126 getString(R.string.sim_action_yes), 127 getString(R.string.sim_action_no_thanks)); 128 } 129 showRebootConfirmDialog()130 private void showRebootConfirmDialog() { 131 ConfirmDialogFragment.show( 132 this, 133 ConfirmDialogFragment.OnConfirmListener.class, 134 DIALOG_TAG_ENABLE_DSDS_REBOOT_CONFIRMATION, 135 getString(R.string.sim_action_restart_title), 136 getString(R.string.sim_action_enable_dsds_text), 137 getString(R.string.sim_action_reboot), 138 getString(R.string.cancel)); 139 } 140 startChooseSimActivity()141 private void startChooseSimActivity() { 142 Intent intent = ChooseSimActivity.getIntent(this); 143 intent.putExtra(ChooseSimActivity.KEY_HAS_PSIM, true); 144 startActivity(intent); 145 finish(); 146 } 147 } 148