Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The LineageOS 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.qualcomm.qti.internal.telephony; |
| 18 | |
| 19 | import android.content.Context; |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.os.AsyncResult; |
| 22 | import android.os.Handler; |
| 23 | import android.os.Message; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 24 | import android.os.ServiceManager; |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 25 | import android.telecom.PhoneAccount; |
| 26 | import android.telecom.PhoneAccountHandle; |
| 27 | import android.telecom.TelecomManager; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 28 | import android.telephony.PhoneNumberUtils; |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 29 | import android.telephony.SubscriptionManager; |
| 30 | import android.telephony.TelephonyManager; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 31 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 32 | import com.android.internal.telephony.CommandsInterface; |
| 33 | import com.android.internal.telephony.Phone; |
| 34 | import com.android.internal.telephony.PhoneConstants; |
| 35 | import com.android.internal.telephony.uicc.IccCardStatus.CardState; |
| 36 | import com.android.internal.telephony.uicc.UiccCard; |
| 37 | import com.android.internal.telephony.uicc.UiccController; |
| 38 | |
LuK1337 | 4db9348 | 2018-12-05 03:19:19 +0100 | [diff] [blame] | 39 | import org.codeaurora.internal.Client; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 40 | import org.codeaurora.internal.IDepersoResCallback; |
| 41 | import org.codeaurora.internal.IDsda; |
| 42 | import org.codeaurora.internal.IExtTelephony; |
LuK1337 | 4db9348 | 2018-12-05 03:19:19 +0100 | [diff] [blame] | 43 | import org.codeaurora.internal.INetworkCallback; |
| 44 | import org.codeaurora.internal.Token; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 45 | |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 46 | import java.util.Iterator; |
| 47 | |
| 48 | import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 49 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 50 | import static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_ACTIVATED; |
| 51 | import static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_DEACTIVATED; |
| 52 | |
Paul Keith | 27c445e | 2018-07-11 18:20:23 +0200 | [diff] [blame] | 53 | import static android.telephony.TelephonyManager.MultiSimVariants.DSDA; |
| 54 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 55 | import static com.android.internal.telephony.uicc.IccCardStatus.CardState.CARDSTATE_PRESENT; |
| 56 | |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 57 | public class LineageExtTelephony extends IExtTelephony.Stub { |
| 58 | |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 59 | class UiccStatus { |
| 60 | |
| 61 | boolean mProvisioned; |
| 62 | int mStatus; |
| 63 | |
| 64 | UiccStatus(int status) { |
| 65 | mProvisioned = true; |
| 66 | mStatus = status; |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 71 | // Service name |
| 72 | private static final String EXT_TELEPHONY_SERVICE_NAME = "extphone"; |
| 73 | |
| 74 | // Intents (+ extras) to broadcast |
| 75 | private static final String ACTION_UICC_MANUAL_PROVISION_STATUS_CHANGED = |
| 76 | "org.codeaurora.intent.action.ACTION_UICC_MANUAL_PROVISION_STATUS_CHANGED"; |
| 77 | private static final String EXTRA_NEW_PROVISION_STATE = "newProvisionState"; |
| 78 | |
| 79 | // UICC States |
| 80 | private static final int PROVISIONED = 1; |
| 81 | private static final int NOT_PROVISIONED = 0; |
| 82 | private static final int INVALID_STATE = -1; |
| 83 | private static final int CARD_NOT_PRESENT = -2; |
| 84 | |
| 85 | // Error codes |
| 86 | private static final int SUCCESS = 0; |
| 87 | private static final int GENERIC_FAILURE = -1; |
| 88 | private static final int INVALID_INPUT = -2; |
| 89 | private static final int BUSY = -3; |
| 90 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 91 | // From IccCardProxy.java |
| 92 | private static final int EVENT_ICC_CHANGED = 3; |
| 93 | |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 94 | private static LineageExtTelephony sInstance; |
| 95 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 96 | private CommandsInterface[] mCommandsInterfaces; |
| 97 | private Context mContext; |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 98 | private Handler mHandler; |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 99 | private Phone[] mPhones; |
| 100 | private SubscriptionManager mSubscriptionManager; |
| 101 | private TelecomManager mTelecomManager; |
| 102 | private TelephonyManager mTelephonyManager; |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 103 | private UiccController mUiccController; |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 104 | private UiccStatus mUiccStatus[]; |
| 105 | private boolean mBusy; |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 106 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 107 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 108 | public static void init(Context context, Phone[] phones, |
| 109 | CommandsInterface[] commandsInterfaces) { |
| 110 | sInstance = getInstance(context, phones, commandsInterfaces); |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 113 | public static LineageExtTelephony getInstance(Context context, Phone[] phones, |
| 114 | CommandsInterface[] commandsInterfaces) { |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 115 | if (sInstance == null) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 116 | sInstance = new LineageExtTelephony(context, phones, commandsInterfaces); |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | return sInstance; |
| 120 | } |
| 121 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 122 | private LineageExtTelephony(Context context, Phone[] phones, |
| 123 | CommandsInterface[] commandsInterfaces) { |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 124 | if (ServiceManager.getService(EXT_TELEPHONY_SERVICE_NAME) == null) { |
| 125 | ServiceManager.addService(EXT_TELEPHONY_SERVICE_NAME, this); |
| 126 | } |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 127 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 128 | mCommandsInterfaces = commandsInterfaces; |
| 129 | |
| 130 | mContext = context; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 131 | |
| 132 | // Keep track of ICC state changes |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 133 | mHandler = new Handler() { |
| 134 | @Override |
| 135 | public void handleMessage(Message msg) { |
| 136 | AsyncResult ar; |
| 137 | |
| 138 | if (msg.what == EVENT_ICC_CHANGED) { |
| 139 | ar = (AsyncResult) msg.obj; |
| 140 | if (ar != null && ar.result != null) { |
| 141 | iccStatusChanged((Integer) ar.result); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | }; |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 146 | |
| 147 | mPhones = phones; |
| 148 | |
| 149 | mSubscriptionManager = (SubscriptionManager) mContext.getSystemService( |
| 150 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 151 | |
| 152 | mTelecomManager = TelecomManager.from(context); |
| 153 | |
| 154 | mTelephonyManager = TelephonyManager.from(context); |
| 155 | |
| 156 | // Assume everything present is provisioned by default |
| 157 | mUiccStatus = new UiccStatus[mPhones.length]; |
| 158 | for (int i = 0; i < mPhones.length; i++) { |
| 159 | if (mPhones[i] == null) { |
| 160 | mUiccStatus[i] = null; |
| 161 | } else if (mPhones[i].getUiccCard() == null) { |
| 162 | mUiccStatus[i] = new UiccStatus(CARD_NOT_PRESENT); |
| 163 | } else { |
| 164 | mUiccStatus[i] = new UiccStatus(mPhones[i].getUiccCard().getCardState() |
| 165 | == CARDSTATE_PRESENT ? PROVISIONED : CARD_NOT_PRESENT); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | mBusy = false; |
| 170 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 171 | mUiccController = UiccController.getInstance(); |
| 172 | mUiccController.registerForIccChanged(mHandler, EVENT_ICC_CHANGED, null); |
| 173 | } |
| 174 | |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 175 | private synchronized void iccStatusChanged(int slotId) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 176 | if (slotId >= mPhones.length || mPhones[slotId] == null) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 180 | UiccCard card = mPhones[slotId].getUiccCard(); |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 181 | |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 182 | if (card == null || card.getCardState() != CARDSTATE_PRESENT) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 183 | mUiccStatus[slotId].mStatus = CARD_NOT_PRESENT; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 184 | } else { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 185 | if (mUiccStatus[slotId].mProvisioned && |
| 186 | mUiccStatus[slotId].mStatus != PROVISIONED) { |
| 187 | mUiccStatus[slotId].mStatus = NOT_PROVISIONED; |
LuK1337 | 8fe9d76 | 2018-05-11 00:09:00 +0200 | [diff] [blame] | 188 | activateUiccCard(slotId); |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 189 | } else if (!mUiccStatus[slotId].mProvisioned && |
| 190 | mUiccStatus[slotId].mStatus != NOT_PROVISIONED) { |
| 191 | mUiccStatus[slotId].mStatus = PROVISIONED; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 192 | deactivateUiccCard(slotId); |
LuK1337 | 8fe9d76 | 2018-05-11 00:09:00 +0200 | [diff] [blame] | 193 | } |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 196 | broadcastUiccActivation(slotId); |
| 197 | } |
| 198 | |
| 199 | private void setUiccActivation(int slotId, boolean activate) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 200 | UiccCard card = mPhones[slotId].getUiccCard(); |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 201 | |
| 202 | int numApps = card.getNumApplications(); |
| 203 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 204 | mUiccStatus[slotId].mProvisioned = activate; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 205 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 206 | for (int i = 0; i < numApps; i++) { |
| 207 | if (card.getApplicationIndex(i) == null) { |
| 208 | continue; |
| 209 | } |
| 210 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 211 | mCommandsInterfaces[slotId].setUiccSubscription(i, activate, null); |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | private void broadcastUiccActivation(int slotId) { |
| 216 | Intent intent = new Intent(ACTION_UICC_MANUAL_PROVISION_STATUS_CHANGED); |
| 217 | intent.putExtra(PhoneConstants.PHONE_KEY, slotId); |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 218 | intent.putExtra(EXTRA_NEW_PROVISION_STATE, mUiccStatus[slotId].mStatus); |
| 219 | mContext.sendBroadcast(intent); |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public int getCurrentUiccCardProvisioningStatus(int slotId) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 224 | if (slotId >= mUiccStatus.length || mUiccStatus[slotId] == null) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 225 | return INVALID_INPUT; |
| 226 | } |
| 227 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 228 | return mUiccStatus[slotId].mStatus; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public int getUiccCardProvisioningUserPreference(int slotId) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 233 | if (slotId >= mUiccStatus.length || mUiccStatus[slotId] == null) { |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 234 | return INVALID_INPUT; |
| 235 | } |
| 236 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 237 | return mUiccStatus[slotId].mProvisioned ? PROVISIONED : NOT_PROVISIONED; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public int activateUiccCard(int slotId) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 242 | if (slotId >= mPhones.length || mPhones[slotId] == null || |
| 243 | slotId >= mCommandsInterfaces.length || mCommandsInterfaces[slotId] == null) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 244 | return INVALID_INPUT; |
| 245 | } |
| 246 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 247 | if (mBusy) { |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 248 | return BUSY; |
| 249 | } |
| 250 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 251 | if (mUiccStatus[slotId].mStatus == PROVISIONED) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 252 | return SUCCESS; |
| 253 | } |
| 254 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 255 | if (mUiccStatus[slotId].mStatus != NOT_PROVISIONED) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 256 | return INVALID_INPUT; |
| 257 | } |
| 258 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 259 | mBusy = true; |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 260 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 261 | mUiccStatus[slotId].mStatus = PROVISIONED; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 262 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 263 | setUiccActivation(slotId, true); |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 264 | mPhones[slotId].setVoiceActivationState(SIM_ACTIVATION_STATE_ACTIVATED); |
| 265 | mPhones[slotId].setDataActivationState(SIM_ACTIVATION_STATE_ACTIVATED); |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 266 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 267 | mBusy = false; |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 268 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 269 | broadcastUiccActivation(slotId); |
| 270 | |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 271 | return SUCCESS; |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public int deactivateUiccCard(int slotId) { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 276 | if (slotId >= mPhones.length || mPhones[slotId] == null || |
| 277 | slotId >= mCommandsInterfaces.length || mCommandsInterfaces[slotId] == null) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 278 | return INVALID_INPUT; |
| 279 | } |
| 280 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 281 | if (mBusy) { |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 282 | return BUSY; |
| 283 | } |
| 284 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 285 | if (mUiccStatus[slotId].mStatus == NOT_PROVISIONED) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 286 | return SUCCESS; |
| 287 | } |
| 288 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 289 | if (mUiccStatus[slotId].mStatus != PROVISIONED) { |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 290 | return INVALID_INPUT; |
| 291 | } |
| 292 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 293 | mBusy = true; |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 294 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 295 | int subIdToDeactivate = mPhones[slotId].getSubId(); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 296 | int subIdToMakeDefault = INVALID_SUBSCRIPTION_ID; |
| 297 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 298 | mUiccStatus[slotId].mStatus = NOT_PROVISIONED; |
Paul Keith | b8e1462 | 2018-05-20 18:46:30 +0200 | [diff] [blame] | 299 | |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 300 | // Find first provisioned sub that isn't what we're deactivating |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 301 | for (int i = 0; i < mPhones.length; i++) { |
| 302 | if (mUiccStatus[i].mStatus == PROVISIONED) { |
| 303 | subIdToMakeDefault = mPhones[i].getSubId(); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 304 | break; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // Make sure defaults are now sane |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 309 | PhoneAccountHandle accountHandle = mTelecomManager.getUserSelectedOutgoingPhoneAccount(); |
| 310 | PhoneAccount account = mTelecomManager.getPhoneAccount(accountHandle); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 311 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 312 | if (mSubscriptionManager.getDefaultSmsSubscriptionId() == subIdToDeactivate) { |
| 313 | mSubscriptionManager.setDefaultSmsSubId(subIdToMakeDefault); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 316 | if (mSubscriptionManager.getDefaultDataSubscriptionId() == subIdToDeactivate) { |
| 317 | mSubscriptionManager.setDefaultDataSubId(subIdToMakeDefault); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 320 | if (mTelephonyManager.getSubIdForPhoneAccount(account) == subIdToDeactivate) { |
| 321 | mTelecomManager.setUserSelectedOutgoingPhoneAccount( |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 322 | subscriptionIdToPhoneAccountHandle(subIdToMakeDefault)); |
| 323 | } |
| 324 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 325 | mPhones[slotId].setVoiceActivationState(SIM_ACTIVATION_STATE_DEACTIVATED); |
| 326 | mPhones[slotId].setDataActivationState(SIM_ACTIVATION_STATE_DEACTIVATED); |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 327 | setUiccActivation(slotId, false); |
| 328 | |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 329 | mBusy = false; |
Paul Keith | 208646f | 2018-05-11 03:05:54 +0200 | [diff] [blame] | 330 | |
Paul Keith | 01b8f28 | 2018-05-09 15:32:27 +0200 | [diff] [blame] | 331 | broadcastUiccActivation(slotId); |
| 332 | |
| 333 | return SUCCESS; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public boolean isSMSPromptEnabled() { |
| 338 | // I hope we don't use this |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public void setSMSPromptEnabled(boolean enabled) { |
| 344 | // I hope we don't use this |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public int getPhoneIdForECall() { |
| 349 | // I hope we don't use this |
| 350 | return -1; |
| 351 | } |
| 352 | |
| 353 | @Override |
| 354 | public void setPrimaryCardOnSlot(int slotId) { |
| 355 | // I hope we don't use this |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public boolean isFdnEnabled() { |
| 360 | // I hope we don't use this |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public int getPrimaryStackPhoneId() { |
| 366 | // I hope we don't use this |
| 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public boolean isEmergencyNumber(String number) { |
| 372 | // This is lame... |
| 373 | return PhoneNumberUtils.isEmergencyNumber(number); |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public boolean isLocalEmergencyNumber(String number) { |
| 378 | // This is lame... |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 379 | return PhoneNumberUtils.isLocalEmergencyNumber(mContext, number); |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public boolean isPotentialEmergencyNumber(String number) { |
| 384 | // This is lame... |
| 385 | return PhoneNumberUtils.isPotentialEmergencyNumber(number); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public boolean isPotentialLocalEmergencyNumber(String number) { |
| 390 | // This is lame... |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 391 | return PhoneNumberUtils.isPotentialLocalEmergencyNumber(mContext, number); |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public boolean isDeviceInSingleStandby() { |
| 396 | // I hope we don't use this |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public boolean setLocalCallHold(int subId, boolean enable) { |
| 402 | // TODO: Do something here |
| 403 | return false; |
| 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public void switchToActiveSub(int subId) { |
| 408 | // I hope we don't use this |
| 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void setDsdaAdapter(IDsda dsdaAdapter) { |
| 413 | // I hope we don't use this |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public int getActiveSubscription() { |
| 418 | // I hope we don't use this |
| 419 | return -1; |
| 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public boolean isDsdaEnabled() { |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 424 | return mTelephonyManager.getMultiSimConfiguration() == DSDA; |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public void supplyIccDepersonalization(String netpin, String type, IDepersoResCallback callback, |
| 429 | int phoneId) { |
| 430 | // I hope we don't use this |
| 431 | } |
| 432 | |
| 433 | @Override |
| 434 | public int getPrimaryCarrierSlotId() { |
| 435 | // I hope we don't use this |
| 436 | return -1; |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public boolean isPrimaryCarrierSlotId(int slotId) { |
| 441 | // I hope we don't use this |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public boolean setSmscAddress(int slotId, String smsc) { |
| 447 | // I hope we don't use this |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | @Override |
| 452 | public String getSmscAddress(int slotId) { |
| 453 | // I hope we don't use this |
| 454 | return null; |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public boolean isVendorApkAvailable(String packageName) { |
| 459 | // I hope we don't use this |
| 460 | return false; |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public int getCurrentPrimaryCardSlotId() { |
| 465 | // I hope we don't use this |
| 466 | return -1; |
| 467 | } |
| 468 | |
LuK1337 | 4db9348 | 2018-12-05 03:19:19 +0100 | [diff] [blame] | 469 | @Override |
| 470 | public Token enable5g(int slotId, Client client) { |
| 471 | // I hope we don't use this |
| 472 | return new Token(-1); |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public Token disable5g(int slotId, Client client) { |
| 477 | // I hope we don't use this |
| 478 | return new Token(-1); |
| 479 | } |
| 480 | |
| 481 | @Override |
| 482 | public Token enable5gOnly(int slotId, Client client) { |
| 483 | // I hope we don't use this |
| 484 | return new Token(-1); |
| 485 | } |
| 486 | |
| 487 | @Override |
| 488 | public Token query5gStatus(int slotId, Client client) { |
| 489 | // I hope we don't use this |
| 490 | return new Token(-1); |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public Token queryNrDcParam(int slotId, Client client) { |
| 495 | // I hope we don't use this |
| 496 | return new Token(-1); |
| 497 | } |
| 498 | |
| 499 | @Override |
| 500 | public Token queryNrBearerAllocation(int slotId, Client client) { |
| 501 | // I hope we don't use this |
| 502 | return new Token(-1); |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public Token queryNrSignalStrength(int slotId, Client client) { |
| 507 | // I hope we don't use this |
| 508 | return new Token(-1); |
| 509 | } |
| 510 | |
| 511 | @Override |
| 512 | public Client registerCallback(String packageName, INetworkCallback callback) { |
| 513 | // I hope we don't use this |
| 514 | return new Client(-1, -1, packageName, callback); |
| 515 | } |
| 516 | |
| 517 | @Override |
| 518 | public void unRegisterCallback(INetworkCallback callback) { |
| 519 | // I hope we don't use this |
| 520 | } |
| 521 | |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 522 | private PhoneAccountHandle subscriptionIdToPhoneAccountHandle(final int subId) { |
| 523 | final Iterator<PhoneAccountHandle> phoneAccounts = |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 524 | mTelecomManager.getCallCapablePhoneAccounts().listIterator(); |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 525 | |
| 526 | while (phoneAccounts.hasNext()) { |
| 527 | final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next(); |
Paul Keith | 0f1392f | 2018-07-15 23:36:35 +0200 | [diff] [blame] | 528 | final PhoneAccount phoneAccount = mTelecomManager.getPhoneAccount(phoneAccountHandle); |
| 529 | if (subId == mTelephonyManager.getSubIdForPhoneAccount(phoneAccount)) { |
LuK1337 | 6374c2a | 2018-05-09 21:37:16 +0200 | [diff] [blame] | 530 | return phoneAccountHandle; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | return null; |
| 535 | } |
| 536 | |
Paul Keith | b18c7bf | 2018-05-09 02:21:19 +0200 | [diff] [blame] | 537 | } |