Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.phone; |
| 18 | |
| 19 | import android.app.ActivityManager; |
| 20 | import android.app.AppOpsManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 24 | import android.content.SharedPreferences; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageInfo; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.pm.Signature; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 28 | import android.net.ConnectivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
| 30 | import android.os.AsyncResult; |
| 31 | import android.os.Binder; |
| 32 | import android.os.Bundle; |
| 33 | import android.os.Handler; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 34 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.os.Looper; |
| 36 | import android.os.Message; |
| 37 | import android.os.Process; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 38 | import android.os.RemoteException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.ServiceManager; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 40 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 43 | import android.provider.Settings; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.telephony.CellInfo; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 45 | import android.telephony.IccOpenLogicalChannelResponse; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 46 | import android.telephony.NeighboringCellInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.telephony.ServiceState; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 48 | import android.telephony.SubscriptionManager; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 49 | import android.telephony.SubInfoRecord; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 50 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.text.TextUtils; |
| 52 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 53 | import android.util.Pair; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.CallManager; |
| 56 | import com.android.internal.telephony.CommandException; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.Connection; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 60 | import com.android.internal.telephony.IccCard; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.Phone; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.PhoneFactory; |
| 63 | import com.android.internal.telephony.CallManager; |
| 64 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 66 | import com.android.internal.telephony.TelephonyIntents; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 67 | import com.android.internal.telephony.dataconnection.DctController; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 68 | import com.android.internal.telephony.uicc.AdnRecord; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 69 | import com.android.internal.telephony.uicc.IccIoResult; |
| 70 | import com.android.internal.telephony.uicc.IccUtils; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 71 | import com.android.internal.telephony.uicc.UiccCard; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 72 | import com.android.internal.telephony.uicc.UiccCarrierPrivilegeRules; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 73 | import com.android.internal.telephony.uicc.UiccController; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 74 | import com.android.internal.util.HexDump; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 76 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 77 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 79 | import java.util.HashMap; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 80 | import java.util.HashSet; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 81 | import java.util.Iterator; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import java.util.List; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 83 | import java.util.Map; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 84 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Implementation of the ITelephony interface. |
| 88 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 89 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 91 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 92 | private static final boolean DBG_LOC = false; |
| 93 | |
| 94 | // Message codes used with mMainThreadHandler |
| 95 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| 96 | private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; |
| 97 | private static final int EVENT_NEIGHBORING_CELL_DONE = 3; |
| 98 | private static final int CMD_ANSWER_RINGING_CALL = 4; |
| 99 | private static final int CMD_END_CALL = 5; // not used yet |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 100 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 101 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 102 | private static final int CMD_OPEN_CHANNEL = 9; |
| 103 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 104 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 105 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 106 | private static final int CMD_NV_READ_ITEM = 13; |
| 107 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 108 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 109 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 110 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 111 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| 112 | private static final int CMD_NV_RESET_CONFIG = 19; |
| 113 | private static final int EVENT_NV_RESET_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 114 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 115 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 116 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 117 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 118 | private static final int CMD_SEND_ENVELOPE = 25; |
| 119 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 120 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 121 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
| 122 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 123 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 124 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 125 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | |
| 127 | /** The singleton instance. */ |
| 128 | private static PhoneInterfaceManager sInstance; |
| 129 | |
| 130 | PhoneGlobals mApp; |
| 131 | Phone mPhone; |
| 132 | CallManager mCM; |
| 133 | AppOpsManager mAppOps; |
| 134 | MainThreadHandler mMainThreadHandler; |
| 135 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 136 | SharedPreferences carrierPrivilegeConfigs; |
| 137 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 138 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
| 139 | private static final String PREF_CARRIERS_SIMPLIFIED_NETWORK_SETTINGS_PREFIX = |
| 140 | "carrier_simplified_network_settings_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 143 | * A request object to use for transmitting data to an ICC. |
| 144 | */ |
| 145 | private static final class IccAPDUArgument { |
| 146 | public int channel, cla, command, p1, p2, p3; |
| 147 | public String data; |
| 148 | |
| 149 | public IccAPDUArgument(int channel, int cla, int command, |
| 150 | int p1, int p2, int p3, String data) { |
| 151 | this.channel = channel; |
| 152 | this.cla = cla; |
| 153 | this.command = command; |
| 154 | this.p1 = p1; |
| 155 | this.p2 = p2; |
| 156 | this.p3 = p3; |
| 157 | this.data = data; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 163 | * request after sending. The main thread will notify the request when it is complete. |
| 164 | */ |
| 165 | private static final class MainThreadRequest { |
| 166 | /** The argument to use for the request */ |
| 167 | public Object argument; |
| 168 | /** The result of the request that is run on the main thread */ |
| 169 | public Object result; |
| 170 | |
| 171 | public MainThreadRequest(Object argument) { |
| 172 | this.argument = argument; |
| 173 | } |
| 174 | } |
| 175 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 176 | private static final class IncomingThirdPartyCallArgs { |
| 177 | public final ComponentName component; |
| 178 | public final String callId; |
| 179 | public final String callerDisplayName; |
| 180 | |
| 181 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 182 | String callerDisplayName) { |
| 183 | this.component = component; |
| 184 | this.callId = callId; |
| 185 | this.callerDisplayName = callerDisplayName; |
| 186 | } |
| 187 | } |
| 188 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | /** |
| 190 | * A handler that processes messages on the main thread in the phone process. Since many |
| 191 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 192 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 193 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 194 | * on, which will be notified when the operation completes and will contain the result of the |
| 195 | * request. |
| 196 | * |
| 197 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 198 | * note that request.result must be set to something non-null for the calling thread to |
| 199 | * unblock. |
| 200 | */ |
| 201 | private final class MainThreadHandler extends Handler { |
| 202 | @Override |
| 203 | public void handleMessage(Message msg) { |
| 204 | MainThreadRequest request; |
| 205 | Message onCompleted; |
| 206 | AsyncResult ar; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 207 | UiccCard uiccCard = UiccController.getInstance().getUiccCard(); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 208 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 209 | |
| 210 | switch (msg.what) { |
| 211 | case CMD_HANDLE_PIN_MMI: |
| 212 | request = (MainThreadRequest) msg.obj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 213 | request.result = mPhone.handlePinMmi((String) request.argument); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 | // Wake up the requesting thread |
| 215 | synchronized (request) { |
| 216 | request.notifyAll(); |
| 217 | } |
| 218 | break; |
| 219 | |
| 220 | case CMD_HANDLE_NEIGHBORING_CELL: |
| 221 | request = (MainThreadRequest) msg.obj; |
| 222 | onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, |
| 223 | request); |
| 224 | mPhone.getNeighboringCids(onCompleted); |
| 225 | break; |
| 226 | |
| 227 | case EVENT_NEIGHBORING_CELL_DONE: |
| 228 | ar = (AsyncResult) msg.obj; |
| 229 | request = (MainThreadRequest) ar.userObj; |
| 230 | if (ar.exception == null && ar.result != null) { |
| 231 | request.result = ar.result; |
| 232 | } else { |
| 233 | // create an empty list to notify the waiting thread |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 234 | request.result = new ArrayList<NeighboringCellInfo>(0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | } |
| 236 | // Wake up the requesting thread |
| 237 | synchronized (request) { |
| 238 | request.notifyAll(); |
| 239 | } |
| 240 | break; |
| 241 | |
| 242 | case CMD_ANSWER_RINGING_CALL: |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 243 | request = (MainThreadRequest) msg.obj; |
| 244 | long answer_subId = ((Long)request.argument).longValue(); |
| 245 | answerRingingCallInternal(answer_subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 246 | break; |
| 247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | case CMD_END_CALL: |
| 249 | request = (MainThreadRequest) msg.obj; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 250 | long end_subId = ((Long)request.argument).longValue(); |
| 251 | final boolean hungUp; |
| 252 | int phoneType = getPhone(end_subId).getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 254 | // CDMA: If the user presses the Power button we treat it as |
| 255 | // ending the complete call session |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 256 | hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
| 258 | // GSM: End the call as per the Phone state |
| 259 | hungUp = PhoneUtils.hangup(mCM); |
| 260 | } else { |
| 261 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 262 | } |
| 263 | if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); |
| 264 | request.result = hungUp; |
| 265 | // Wake up the requesting thread |
| 266 | synchronized (request) { |
| 267 | request.notifyAll(); |
| 268 | } |
| 269 | break; |
| 270 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 271 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 272 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 273 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 274 | if (uiccCard == null) { |
| 275 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 276 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 277 | synchronized (request) { |
| 278 | request.notifyAll(); |
| 279 | } |
| 280 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 281 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 282 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 283 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 284 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 285 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 286 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 287 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 288 | break; |
| 289 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 290 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 291 | ar = (AsyncResult) msg.obj; |
| 292 | request = (MainThreadRequest) ar.userObj; |
| 293 | if (ar.exception == null && ar.result != null) { |
| 294 | request.result = ar.result; |
| 295 | } else { |
| 296 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 297 | if (ar.result == null) { |
| 298 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 299 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 300 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 301 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 302 | } else { |
| 303 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 304 | } |
| 305 | } |
| 306 | synchronized (request) { |
| 307 | request.notifyAll(); |
| 308 | } |
| 309 | break; |
| 310 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 311 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 312 | request = (MainThreadRequest) msg.obj; |
| 313 | iccArgument = (IccAPDUArgument) request.argument; |
| 314 | if (uiccCard == null) { |
| 315 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 316 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 317 | synchronized (request) { |
| 318 | request.notifyAll(); |
| 319 | } |
| 320 | } else { |
| 321 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 322 | request); |
| 323 | uiccCard.iccTransmitApduBasicChannel( |
| 324 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 325 | iccArgument.p3, iccArgument.data, onCompleted); |
| 326 | } |
| 327 | break; |
| 328 | |
| 329 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 330 | ar = (AsyncResult) msg.obj; |
| 331 | request = (MainThreadRequest) ar.userObj; |
| 332 | if (ar.exception == null && ar.result != null) { |
| 333 | request.result = ar.result; |
| 334 | } else { |
| 335 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 336 | if (ar.result == null) { |
| 337 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 338 | } else if (ar.exception instanceof CommandException) { |
| 339 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 340 | ar.exception); |
| 341 | } else { |
| 342 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 343 | } |
| 344 | } |
| 345 | synchronized (request) { |
| 346 | request.notifyAll(); |
| 347 | } |
| 348 | break; |
| 349 | |
| 350 | case CMD_EXCHANGE_SIM_IO: |
| 351 | request = (MainThreadRequest) msg.obj; |
| 352 | iccArgument = (IccAPDUArgument) request.argument; |
| 353 | if (uiccCard == null) { |
| 354 | loge("iccExchangeSimIO: No UICC"); |
| 355 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 356 | synchronized (request) { |
| 357 | request.notifyAll(); |
| 358 | } |
| 359 | } else { |
| 360 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 361 | request); |
| 362 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 363 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 364 | iccArgument.data, onCompleted); |
| 365 | } |
| 366 | break; |
| 367 | |
| 368 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 369 | ar = (AsyncResult) msg.obj; |
| 370 | request = (MainThreadRequest) ar.userObj; |
| 371 | if (ar.exception == null && ar.result != null) { |
| 372 | request.result = ar.result; |
| 373 | } else { |
| 374 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 375 | } |
| 376 | synchronized (request) { |
| 377 | request.notifyAll(); |
| 378 | } |
| 379 | break; |
| 380 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 381 | case CMD_SEND_ENVELOPE: |
| 382 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 383 | if (uiccCard == null) { |
| 384 | loge("sendEnvelopeWithStatus: No UICC"); |
| 385 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 386 | synchronized (request) { |
| 387 | request.notifyAll(); |
| 388 | } |
| 389 | } else { |
| 390 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 391 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 392 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 393 | break; |
| 394 | |
| 395 | case EVENT_SEND_ENVELOPE_DONE: |
| 396 | ar = (AsyncResult) msg.obj; |
| 397 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 398 | if (ar.exception == null && ar.result != null) { |
| 399 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 400 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 401 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 402 | if (ar.result == null) { |
| 403 | loge("sendEnvelopeWithStatus: Empty response"); |
| 404 | } else if (ar.exception instanceof CommandException) { |
| 405 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 406 | ar.exception); |
| 407 | } else { |
| 408 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 409 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 410 | } |
| 411 | synchronized (request) { |
| 412 | request.notifyAll(); |
| 413 | } |
| 414 | break; |
| 415 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 416 | case CMD_OPEN_CHANNEL: |
| 417 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 418 | if (uiccCard == null) { |
| 419 | loge("iccOpenLogicalChannel: No UICC"); |
| 420 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 421 | synchronized (request) { |
| 422 | request.notifyAll(); |
| 423 | } |
| 424 | } else { |
| 425 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
| 426 | uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted); |
| 427 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 428 | break; |
| 429 | |
| 430 | case EVENT_OPEN_CHANNEL_DONE: |
| 431 | ar = (AsyncResult) msg.obj; |
| 432 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 434 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 435 | int[] result = (int[]) ar.result; |
| 436 | int channelId = result[0]; |
| 437 | byte[] selectResponse = null; |
| 438 | if (result.length > 1) { |
| 439 | selectResponse = new byte[result.length - 1]; |
| 440 | for (int i = 1; i < result.length; ++i) { |
| 441 | selectResponse[i - 1] = (byte) result[i]; |
| 442 | } |
| 443 | } |
| 444 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 445 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 446 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | if (ar.result == null) { |
| 448 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 450 | if (ar.exception != null) { |
| 451 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 452 | } |
| 453 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 454 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | if ((ar.exception != null) && (ar.exception instanceof CommandException)) { |
| 456 | if (ar.exception.getMessage().compareTo("MISSING_RESOURCE") == 0) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 457 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | } else if (ar.exception.getMessage().compareTo("NO_SUCH_ELEMENT") == 0) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 459 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 463 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 465 | request.result = openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | synchronized (request) { |
| 467 | request.notifyAll(); |
| 468 | } |
| 469 | break; |
| 470 | |
| 471 | case CMD_CLOSE_CHANNEL: |
| 472 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 473 | if (uiccCard == null) { |
| 474 | loge("iccCloseLogicalChannel: No UICC"); |
| 475 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 476 | synchronized (request) { |
| 477 | request.notifyAll(); |
| 478 | } |
| 479 | } else { |
| 480 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 481 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 482 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 483 | break; |
| 484 | |
| 485 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 486 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 487 | break; |
| 488 | |
| 489 | case CMD_NV_READ_ITEM: |
| 490 | request = (MainThreadRequest) msg.obj; |
| 491 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| 492 | mPhone.nvReadItem((Integer) request.argument, onCompleted); |
| 493 | break; |
| 494 | |
| 495 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | ar = (AsyncResult) msg.obj; |
| 497 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 498 | if (ar.exception == null && ar.result != null) { |
| 499 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 501 | request.result = ""; |
| 502 | if (ar.result == null) { |
| 503 | loge("nvReadItem: Empty response"); |
| 504 | } else if (ar.exception instanceof CommandException) { |
| 505 | loge("nvReadItem: CommandException: " + |
| 506 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 507 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 508 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | synchronized (request) { |
| 512 | request.notifyAll(); |
| 513 | } |
| 514 | break; |
| 515 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 516 | case CMD_NV_WRITE_ITEM: |
| 517 | request = (MainThreadRequest) msg.obj; |
| 518 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 519 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| 520 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); |
| 521 | break; |
| 522 | |
| 523 | case EVENT_NV_WRITE_ITEM_DONE: |
| 524 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 525 | break; |
| 526 | |
| 527 | case CMD_NV_WRITE_CDMA_PRL: |
| 528 | request = (MainThreadRequest) msg.obj; |
| 529 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 530 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 531 | break; |
| 532 | |
| 533 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 534 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 535 | break; |
| 536 | |
| 537 | case CMD_NV_RESET_CONFIG: |
| 538 | request = (MainThreadRequest) msg.obj; |
| 539 | onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); |
| 540 | mPhone.nvResetConfig((Integer) request.argument, onCompleted); |
| 541 | break; |
| 542 | |
| 543 | case EVENT_NV_RESET_CONFIG_DONE: |
| 544 | handleNullReturnEvent(msg, "nvResetConfig"); |
| 545 | break; |
| 546 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 547 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 548 | request = (MainThreadRequest) msg.obj; |
| 549 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 550 | mPhone.getPreferredNetworkType(onCompleted); |
| 551 | break; |
| 552 | |
| 553 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 554 | ar = (AsyncResult) msg.obj; |
| 555 | request = (MainThreadRequest) ar.userObj; |
| 556 | if (ar.exception == null && ar.result != null) { |
| 557 | request.result = ar.result; // Integer |
| 558 | } else { |
| 559 | request.result = -1; |
| 560 | if (ar.result == null) { |
| 561 | loge("getPreferredNetworkType: Empty response"); |
| 562 | } else if (ar.exception instanceof CommandException) { |
| 563 | loge("getPreferredNetworkType: CommandException: " + |
| 564 | ar.exception); |
| 565 | } else { |
| 566 | loge("getPreferredNetworkType: Unknown exception"); |
| 567 | } |
| 568 | } |
| 569 | synchronized (request) { |
| 570 | request.notifyAll(); |
| 571 | } |
| 572 | break; |
| 573 | |
| 574 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 575 | request = (MainThreadRequest) msg.obj; |
| 576 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 577 | int networkType = (Integer) request.argument; |
| 578 | mPhone.setPreferredNetworkType(networkType, onCompleted); |
| 579 | break; |
| 580 | |
| 581 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 582 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 583 | break; |
| 584 | |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 585 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 586 | request = (MainThreadRequest)msg.obj; |
| 587 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
| 588 | mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted); |
| 589 | break; |
| 590 | |
| 591 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 592 | ar = (AsyncResult)msg.obj; |
| 593 | request = (MainThreadRequest)ar.userObj; |
| 594 | request.result = ar; |
| 595 | synchronized (request) { |
| 596 | request.notifyAll(); |
| 597 | } |
| 598 | break; |
| 599 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 600 | default: |
| 601 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 602 | break; |
| 603 | } |
| 604 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 605 | |
| 606 | private void handleNullReturnEvent(Message msg, String command) { |
| 607 | AsyncResult ar = (AsyncResult) msg.obj; |
| 608 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 609 | if (ar.exception == null) { |
| 610 | request.result = true; |
| 611 | } else { |
| 612 | request.result = false; |
| 613 | if (ar.exception instanceof CommandException) { |
| 614 | loge(command + ": CommandException: " + ar.exception); |
| 615 | } else { |
| 616 | loge(command + ": Unknown exception"); |
| 617 | } |
| 618 | } |
| 619 | synchronized (request) { |
| 620 | request.notifyAll(); |
| 621 | } |
| 622 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /** |
| 626 | * Posts the specified command to be executed on the main thread, |
| 627 | * waits for the request to complete, and returns the result. |
| 628 | * @see #sendRequestAsync |
| 629 | */ |
| 630 | private Object sendRequest(int command, Object argument) { |
Santos Cordon | 500b0e0 | 2014-06-17 10:33:33 -0700 | [diff] [blame] | 631 | return sendRequest(command, argument, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Posts the specified command to be executed on the main thread, |
| 636 | * waits for the request to complete, and returns the result. |
| 637 | * @see #sendRequestAsync |
| 638 | */ |
| 639 | private Object sendRequest(int command, Object argument, Object argument2) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 641 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 642 | } |
| 643 | |
| 644 | MainThreadRequest request = new MainThreadRequest(argument); |
| 645 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 646 | msg.sendToTarget(); |
| 647 | |
| 648 | // Wait for the request to complete |
| 649 | synchronized (request) { |
| 650 | while (request.result == null) { |
| 651 | try { |
| 652 | request.wait(); |
| 653 | } catch (InterruptedException e) { |
| 654 | // Do nothing, go back and wait until the request is complete |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | return request.result; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 663 | * Posts the specified command to be executed on the main thread, and |
| 664 | * returns immediately. |
| 665 | * @see #sendRequest |
| 666 | */ |
| 667 | private void sendRequestAsync(int command) { |
| 668 | mMainThreadHandler.sendEmptyMessage(command); |
| 669 | } |
| 670 | |
| 671 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 672 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 673 | * @see {@link #sendRequest(int,Object)} |
| 674 | */ |
| 675 | private void sendRequestAsync(int command, Object argument) { |
| 676 | MainThreadRequest request = new MainThreadRequest(argument); |
| 677 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 678 | msg.sendToTarget(); |
| 679 | } |
| 680 | |
| 681 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 682 | * Initialize the singleton PhoneInterfaceManager instance. |
| 683 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 684 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 685 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 686 | synchronized (PhoneInterfaceManager.class) { |
| 687 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 688 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 689 | } else { |
| 690 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 691 | } |
| 692 | return sInstance; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 697 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 698 | mApp = app; |
| 699 | mPhone = phone; |
| 700 | mCM = PhoneGlobals.getInstance().mCM; |
| 701 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 702 | mMainThreadHandler = new MainThreadHandler(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 703 | carrierPrivilegeConfigs = |
| 704 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 705 | publish(); |
| 706 | } |
| 707 | |
| 708 | private void publish() { |
| 709 | if (DBG) log("publish: " + this); |
| 710 | |
| 711 | ServiceManager.addService("phone", this); |
| 712 | } |
| 713 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 714 | // returns phone associated with the subId. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 715 | private Phone getPhone(long subId) { |
Legler Wu | f8733b4 | 2014-09-25 11:00:54 +0800 | [diff] [blame^] | 716 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 718 | // |
| 719 | // Implementation of the ITelephony interface. |
| 720 | // |
| 721 | |
| 722 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 723 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 726 | public void dialForSubscriber(long subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 727 | if (DBG) log("dial: " + number); |
| 728 | // No permission check needed here: This is just a wrapper around the |
| 729 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 730 | // the UI before it does anything. |
| 731 | |
| 732 | String url = createTelUrl(number); |
| 733 | if (url == null) { |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | // PENDING: should we just silently fail if phone is offhook or ringing? |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 738 | PhoneConstants.State state = mCM.getState(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 739 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 740 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 741 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 742 | mApp.startActivity(intent); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 747 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 750 | public void callForSubscriber(long subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 751 | if (DBG) log("call: " + number); |
| 752 | |
| 753 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 754 | // need to do a permission check since we're calling startActivity() |
| 755 | // from the context of the phone app. |
| 756 | enforceCallPermission(); |
| 757 | |
| 758 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 759 | != AppOpsManager.MODE_ALLOWED) { |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | String url = createTelUrl(number); |
| 764 | if (url == null) { |
| 765 | return; |
| 766 | } |
| 767 | |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 768 | boolean isValid = false; |
Wink Saville | 10aa2e9 | 2014-09-04 10:46:34 -0700 | [diff] [blame] | 769 | List<SubInfoRecord> slist = SubscriptionManager.getActiveSubInfoList(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 770 | for (SubInfoRecord subInfoRecord : slist) { |
Wink Saville | b30c9a2 | 2014-09-04 22:42:02 -0700 | [diff] [blame] | 771 | if (subInfoRecord.subId == subId) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 772 | isValid = true; |
| 773 | break; |
| 774 | } |
| 775 | } |
| 776 | if (isValid == false) { |
| 777 | return; |
| 778 | } |
| 779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 780 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 781 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 782 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 783 | mApp.startActivity(intent); |
| 784 | } |
| 785 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 786 | /** |
| 787 | * End a call based on call state |
| 788 | * @return true is a call was ended |
| 789 | */ |
| 790 | public boolean endCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 791 | return endCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /** |
| 795 | * End a call based on the call state of the subId |
| 796 | * @return true is a call was ended |
| 797 | */ |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 798 | public boolean endCallForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 799 | enforceCallPermission(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 800 | return (Boolean) sendRequest(CMD_END_CALL, new Long(subId), null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | public void answerRingingCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 804 | answerRingingCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 807 | public void answerRingingCallForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 808 | if (DBG) log("answerRingingCall..."); |
| 809 | // TODO: there should eventually be a separate "ANSWER_PHONE" permission, |
| 810 | // but that can probably wait till the big TelephonyManager API overhaul. |
| 811 | // For now, protect this call with the MODIFY_PHONE_STATE permission. |
| 812 | enforceModifyPermission(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 813 | sendRequest(CMD_ANSWER_RINGING_CALL, new Long(subId), null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
| 817 | * Make the actual telephony calls to implement answerRingingCall(). |
| 818 | * This should only be called from the main thread of the Phone app. |
| 819 | * @see #answerRingingCall |
| 820 | * |
| 821 | * TODO: it would be nice to return true if we answered the call, or |
| 822 | * false if there wasn't actually a ringing incoming call, or some |
| 823 | * other error occurred. (In other words, pass back the return value |
| 824 | * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) |
| 825 | * But that would require calling this method via sendRequest() rather |
| 826 | * than sendRequestAsync(), and right now we don't actually *need* that |
| 827 | * return value, so let's just return void for now. |
| 828 | */ |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 829 | private void answerRingingCallInternal(long subId) { |
| 830 | final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 831 | if (hasRingingCall) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 832 | final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle(); |
| 833 | final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 834 | if (hasActiveCall && hasHoldingCall) { |
| 835 | // Both lines are in use! |
| 836 | // TODO: provide a flag to let the caller specify what |
| 837 | // policy to use if both lines are in use. (The current |
| 838 | // behavior is hardwired to "answer incoming, end ongoing", |
| 839 | // which is how the CALL button is specced to behave.) |
| 840 | PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); |
| 841 | return; |
| 842 | } else { |
| 843 | // answerCall() will automatically hold the current active |
| 844 | // call, if there is one. |
| 845 | PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); |
| 846 | return; |
| 847 | } |
| 848 | } else { |
| 849 | // No call was ringing. |
| 850 | return; |
| 851 | } |
| 852 | } |
| 853 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 854 | /** |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 855 | * This method is no longer used and can be removed once TelephonyManager stops referring to it. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 856 | */ |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 857 | public void silenceRinger() { |
| 858 | Log.e(LOG_TAG, "silenseRinger not supported"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | public boolean isOffhook() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 862 | return isOffhookForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 865 | public boolean isOffhookForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 866 | return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | public boolean isRinging() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 870 | return (isRingingForSubscriber(getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 873 | public boolean isRingingForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 874 | return (getPhone(subId).getState() == PhoneConstants.State.RINGING); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | public boolean isIdle() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 878 | return isIdleForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 881 | public boolean isIdleForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 882 | return (getPhone(subId).getState() == PhoneConstants.State.IDLE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | public boolean isSimPinEnabled() { |
| 886 | enforceReadPermission(); |
| 887 | return (PhoneGlobals.getInstance().isSimPinEnabled()); |
| 888 | } |
| 889 | |
| 890 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 891 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 894 | public boolean supplyPinForSubscriber(long subId, String pin) { |
| 895 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 896 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 897 | } |
| 898 | |
| 899 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 900 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 903 | public boolean supplyPukForSubscriber(long subId, String puk, String pin) { |
| 904 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 905 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 906 | } |
| 907 | |
| 908 | /** {@hide} */ |
| 909 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 910 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 913 | public int[] supplyPinReportResultForSubscriber(long subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 914 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 915 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 916 | checkSimPin.start(); |
| 917 | return checkSimPin.unlockSim(null, pin); |
| 918 | } |
| 919 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 920 | /** {@hide} */ |
| 921 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 922 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 925 | public int[] supplyPukReportResultForSubscriber(long subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 926 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 927 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 928 | checkSimPuk.start(); |
| 929 | return checkSimPuk.unlockSim(puk, pin); |
| 930 | } |
| 931 | |
| 932 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 933 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 934 | * a synchronous one. |
| 935 | */ |
| 936 | private static class UnlockSim extends Thread { |
| 937 | |
| 938 | private final IccCard mSimCard; |
| 939 | |
| 940 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 941 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 942 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 943 | |
| 944 | // For replies from SimCard interface |
| 945 | private Handler mHandler; |
| 946 | |
| 947 | // For async handler to identify request type |
| 948 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 949 | |
| 950 | public UnlockSim(IccCard simCard) { |
| 951 | mSimCard = simCard; |
| 952 | } |
| 953 | |
| 954 | @Override |
| 955 | public void run() { |
| 956 | Looper.prepare(); |
| 957 | synchronized (UnlockSim.this) { |
| 958 | mHandler = new Handler() { |
| 959 | @Override |
| 960 | public void handleMessage(Message msg) { |
| 961 | AsyncResult ar = (AsyncResult) msg.obj; |
| 962 | switch (msg.what) { |
| 963 | case SUPPLY_PIN_COMPLETE: |
| 964 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 965 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 966 | mRetryCount = msg.arg1; |
| 967 | if (ar.exception != null) { |
| 968 | if (ar.exception instanceof CommandException && |
| 969 | ((CommandException)(ar.exception)).getCommandError() |
| 970 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 971 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 972 | } else { |
| 973 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 974 | } |
| 975 | } else { |
| 976 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 978 | mDone = true; |
| 979 | UnlockSim.this.notifyAll(); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | }; |
| 985 | UnlockSim.this.notifyAll(); |
| 986 | } |
| 987 | Looper.loop(); |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | * Use PIN or PUK to unlock SIM card |
| 992 | * |
| 993 | * If PUK is null, unlock SIM card with PIN |
| 994 | * |
| 995 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 996 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 997 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 998 | |
| 999 | while (mHandler == null) { |
| 1000 | try { |
| 1001 | wait(); |
| 1002 | } catch (InterruptedException e) { |
| 1003 | Thread.currentThread().interrupt(); |
| 1004 | } |
| 1005 | } |
| 1006 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1007 | |
| 1008 | if (puk == null) { |
| 1009 | mSimCard.supplyPin(pin, callback); |
| 1010 | } else { |
| 1011 | mSimCard.supplyPuk(puk, pin, callback); |
| 1012 | } |
| 1013 | |
| 1014 | while (!mDone) { |
| 1015 | try { |
| 1016 | Log.d(LOG_TAG, "wait for done"); |
| 1017 | wait(); |
| 1018 | } catch (InterruptedException e) { |
| 1019 | // Restore the interrupted status |
| 1020 | Thread.currentThread().interrupt(); |
| 1021 | } |
| 1022 | } |
| 1023 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1024 | int[] resultArray = new int[2]; |
| 1025 | resultArray[0] = mResult; |
| 1026 | resultArray[1] = mRetryCount; |
| 1027 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1032 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1033 | |
| 1034 | } |
| 1035 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1036 | public void updateServiceLocationForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1037 | // No permission check needed here: this call is harmless, and it's |
| 1038 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1039 | // already intentionally exposed to 3rd parties.) |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1040 | getPhone(subId).updateServiceLocation(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | public boolean isRadioOn() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1044 | return isRadioOnForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1047 | public boolean isRadioOnForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1048 | return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1052 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1053 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1054 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1055 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1056 | public void toggleRadioOnOffForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1057 | enforceModifyPermission(); |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1058 | getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1062 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1065 | public boolean setRadioForSubscriber(long subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1066 | enforceModifyPermission(); |
| 1067 | if ((getPhone(subId).getServiceState().getState() != |
| 1068 | ServiceState.STATE_POWER_OFF) != turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1069 | toggleRadioOnOffForSubscriber(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1070 | } |
| 1071 | return true; |
| 1072 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1073 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1074 | public boolean needMobileRadioShutdown() { |
| 1075 | /* |
| 1076 | * If any of the Radios are available, it will need to be |
| 1077 | * shutdown. So return true if any Radio is available. |
| 1078 | */ |
| 1079 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1080 | Phone phone = PhoneFactory.getPhone(i); |
| 1081 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1082 | } |
| 1083 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1084 | return false; |
| 1085 | } |
| 1086 | |
| 1087 | public void shutdownMobileRadios() { |
| 1088 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1089 | logv("Shutting down Phone " + i); |
| 1090 | shutdownRadioUsingPhoneId(i); |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| 1095 | enforceModifyPermission(); |
| 1096 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1097 | if (phone != null && phone.isRadioAvailable()) { |
| 1098 | phone.shutdownRadio(); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1102 | public boolean setRadioPower(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1103 | return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1106 | public boolean setRadioPowerForSubscriber(long subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1107 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1108 | getPhone(subId).setRadioPower(turnOn); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1109 | return true; |
| 1110 | } |
| 1111 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1112 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1113 | public boolean enableDataConnectivity() { |
| 1114 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1115 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 1116 | getPhone(subId).setDataEnabled(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 | return true; |
| 1118 | } |
| 1119 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1120 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1121 | public boolean disableDataConnectivity() { |
| 1122 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1123 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 1124 | getPhone(subId).setDataEnabled(false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1125 | return true; |
| 1126 | } |
| 1127 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1128 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1129 | public boolean isDataConnectivityPossible() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1130 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 1131 | return getPhone(subId).isDataConnectivityPossible(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1135 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1138 | public boolean handlePinMmiForSubscriber(long subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1139 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1140 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1143 | public int getCallState() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1144 | return getCallStateForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1147 | public int getCallStateForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1148 | return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | public int getDataState() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1152 | Phone phone = getPhone(SubscriptionManager.getDefaultDataSubId()); |
| 1153 | return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | public int getDataActivity() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1157 | Phone phone = getPhone(SubscriptionManager.getDefaultDataSubId()); |
| 1158 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | @Override |
| 1162 | public Bundle getCellLocation() { |
| 1163 | try { |
| 1164 | mApp.enforceCallingOrSelfPermission( |
| 1165 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1166 | } catch (SecurityException e) { |
| 1167 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1168 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1169 | // is the weaker precondition |
| 1170 | mApp.enforceCallingOrSelfPermission( |
| 1171 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1172 | } |
| 1173 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1174 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1175 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1176 | Bundle data = new Bundle(); |
| 1177 | mPhone.getCellLocation().fillInNotifierBundle(data); |
| 1178 | return data; |
| 1179 | } else { |
| 1180 | if (DBG_LOC) log("getCellLocation: suppress non-active user"); |
| 1181 | return null; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | @Override |
| 1186 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1187 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1190 | public void enableLocationUpdatesForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1191 | mApp.enforceCallingOrSelfPermission( |
| 1192 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1193 | getPhone(subId).enableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | @Override |
| 1197 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1198 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1201 | public void disableLocationUpdatesForSubscriber(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1202 | mApp.enforceCallingOrSelfPermission( |
| 1203 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1204 | getPhone(subId).disableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | @Override |
| 1208 | @SuppressWarnings("unchecked") |
| 1209 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1210 | try { |
| 1211 | mApp.enforceCallingOrSelfPermission( |
| 1212 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1213 | } catch (SecurityException e) { |
| 1214 | // If we have ACCESS_FINE_LOCATION permission, skip the check |
| 1215 | // for ACCESS_COARSE_LOCATION |
| 1216 | // A failure should throw the SecurityException from |
| 1217 | // ACCESS_COARSE_LOCATION since this is the weaker precondition |
| 1218 | mApp.enforceCallingOrSelfPermission( |
| 1219 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1220 | } |
| 1221 | |
| 1222 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1223 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1224 | return null; |
| 1225 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1226 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1227 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
| 1228 | |
| 1229 | ArrayList<NeighboringCellInfo> cells = null; |
| 1230 | |
| 1231 | try { |
| 1232 | cells = (ArrayList<NeighboringCellInfo>) sendRequest( |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1233 | CMD_HANDLE_NEIGHBORING_CELL, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | } catch (RuntimeException e) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1235 | Log.e(LOG_TAG, "getNeighboringCellInfo " + e); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1236 | } |
| 1237 | return cells; |
| 1238 | } else { |
| 1239 | if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user"); |
| 1240 | return null; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | @Override |
| 1246 | public List<CellInfo> getAllCellInfo() { |
| 1247 | try { |
| 1248 | mApp.enforceCallingOrSelfPermission( |
| 1249 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1250 | } catch (SecurityException e) { |
| 1251 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1252 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1253 | // is the weaker precondition |
| 1254 | mApp.enforceCallingOrSelfPermission( |
| 1255 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1256 | } |
| 1257 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1258 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| 1260 | return mPhone.getAllCellInfo(); |
| 1261 | } else { |
| 1262 | if (DBG_LOC) log("getAllCellInfo: suppress non-active user"); |
| 1263 | return null; |
| 1264 | } |
| 1265 | } |
| 1266 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1267 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | public void setCellInfoListRate(int rateInMillis) { |
| 1269 | mPhone.setCellInfoListRate(rateInMillis); |
| 1270 | } |
| 1271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1272 | // |
| 1273 | // Internal helper methods. |
| 1274 | // |
| 1275 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1276 | private static boolean checkIfCallerIsSelfOrForegroundUser() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1277 | boolean ok; |
| 1278 | |
| 1279 | boolean self = Binder.getCallingUid() == Process.myUid(); |
| 1280 | if (!self) { |
| 1281 | // Get the caller's user id then clear the calling identity |
| 1282 | // which will be restored in the finally clause. |
| 1283 | int callingUser = UserHandle.getCallingUserId(); |
| 1284 | long ident = Binder.clearCallingIdentity(); |
| 1285 | |
| 1286 | try { |
| 1287 | // With calling identity cleared the current user is the foreground user. |
| 1288 | int foregroundUser = ActivityManager.getCurrentUser(); |
| 1289 | ok = (foregroundUser == callingUser); |
| 1290 | if (DBG_LOC) { |
| 1291 | log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser |
| 1292 | + " callingUser=" + callingUser + " ok=" + ok); |
| 1293 | } |
| 1294 | } catch (Exception ex) { |
| 1295 | if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex); |
| 1296 | ok = false; |
| 1297 | } finally { |
| 1298 | Binder.restoreCallingIdentity(ident); |
| 1299 | } |
| 1300 | } else { |
| 1301 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self"); |
| 1302 | ok = true; |
| 1303 | } |
| 1304 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok); |
| 1305 | return ok; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * Make sure the caller has the READ_PHONE_STATE permission. |
| 1310 | * |
| 1311 | * @throws SecurityException if the caller does not have the required permission |
| 1312 | */ |
| 1313 | private void enforceReadPermission() { |
| 1314 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 1315 | } |
| 1316 | |
| 1317 | /** |
| 1318 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 1319 | * |
| 1320 | * @throws SecurityException if the caller does not have the required permission |
| 1321 | */ |
| 1322 | private void enforceModifyPermission() { |
| 1323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 1324 | } |
| 1325 | |
| 1326 | /** |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1327 | * Make sure either system app or the caller has carrier privilege. |
| 1328 | * |
| 1329 | * @throws SecurityException if the caller does not have the required permission/privilege |
| 1330 | */ |
| 1331 | private void enforceModifyPermissionOrCarrierPrivilege() { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1332 | int permission = mApp.checkCallingOrSelfPermission( |
| 1333 | android.Manifest.permission.MODIFY_PHONE_STATE); |
| 1334 | if (permission == PackageManager.PERMISSION_GRANTED) { |
| 1335 | return; |
| 1336 | } |
| 1337 | |
| 1338 | log("No modify permission, check carrier privilege next."); |
| 1339 | if (hasCarrierPrivileges() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 1340 | loge("No Carrier Privilege."); |
| 1341 | throw new SecurityException("No modify permission or carrier privilege."); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Make sure the caller has carrier privilege. |
| 1347 | * |
| 1348 | * @throws SecurityException if the caller does not have the required permission |
| 1349 | */ |
| 1350 | private void enforceCarrierPrivilege() { |
| 1351 | if (hasCarrierPrivileges() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1352 | loge("No Carrier Privilege."); |
| 1353 | throw new SecurityException("No Carrier Privilege."); |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1358 | * Make sure the caller has the CALL_PHONE permission. |
| 1359 | * |
| 1360 | * @throws SecurityException if the caller does not have the required permission |
| 1361 | */ |
| 1362 | private void enforceCallPermission() { |
| 1363 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 1364 | } |
| 1365 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1366 | /** |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 1367 | * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission. |
| 1368 | * |
| 1369 | * @throws SecurityException if the caller does not have the required permission |
| 1370 | */ |
| 1371 | private void enforcePrivilegedPhoneStatePermission() { |
| 1372 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 1373 | null); |
| 1374 | } |
| 1375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1376 | private String createTelUrl(String number) { |
| 1377 | if (TextUtils.isEmpty(number)) { |
| 1378 | return null; |
| 1379 | } |
| 1380 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1381 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1384 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1385 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1386 | } |
| 1387 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1388 | private static void logv(String msg) { |
| 1389 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1390 | } |
| 1391 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1392 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1394 | } |
| 1395 | |
| 1396 | public int getActivePhoneType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1397 | return getActivePhoneTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1400 | public int getActivePhoneTypeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1401 | return getPhone(subId).getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * Returns the CDMA ERI icon index to display |
| 1406 | */ |
| 1407 | public int getCdmaEriIconIndex() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1408 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1409 | |
| 1410 | } |
| 1411 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1412 | public int getCdmaEriIconIndexForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1413 | return getPhone(subId).getCdmaEriIconIndex(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /** |
| 1417 | * Returns the CDMA ERI icon mode, |
| 1418 | * 0 - ON |
| 1419 | * 1 - FLASHING |
| 1420 | */ |
| 1421 | public int getCdmaEriIconMode() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1422 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1425 | public int getCdmaEriIconModeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1426 | return getPhone(subId).getCdmaEriIconMode(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * Returns the CDMA ERI text, |
| 1431 | */ |
| 1432 | public String getCdmaEriText() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1433 | return getCdmaEriTextForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1436 | public String getCdmaEriTextForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1437 | return getPhone(subId).getCdmaEriText(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1441 | * Returns the CDMA MDN. |
| 1442 | */ |
| 1443 | public String getCdmaMdn(long subId) { |
| 1444 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1445 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1446 | return getPhone(subId).getLine1Number(); |
| 1447 | } else { |
| 1448 | return null; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * Returns the CDMA MIN. |
| 1454 | */ |
| 1455 | public String getCdmaMin(long subId) { |
| 1456 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1457 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 1458 | return getPhone(subId).getCdmaMin(); |
| 1459 | } else { |
| 1460 | return null; |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1465 | * Returns true if CDMA provisioning needs to run. |
| 1466 | */ |
| 1467 | public boolean needsOtaServiceProvisioning() { |
| 1468 | return mPhone.needsOtaServiceProvisioning(); |
| 1469 | } |
| 1470 | |
| 1471 | /** |
| 1472 | * Returns the unread count of voicemails |
| 1473 | */ |
| 1474 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1475 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * Returns the unread count of voicemails for a subId |
| 1480 | */ |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1481 | public int getVoiceMessageCountForSubscriber( long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1482 | return getPhone(subId).getVoiceMessageCount(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * Returns the data network type |
| 1487 | * |
| 1488 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 1489 | */ |
| 1490 | @Override |
| 1491 | public int getNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1492 | return getNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * Returns the network type for a subId |
| 1497 | */ |
| 1498 | @Override |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1499 | public int getNetworkTypeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1500 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /** |
| 1504 | * Returns the data network type |
| 1505 | */ |
| 1506 | @Override |
| 1507 | public int getDataNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1508 | return getDataNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Returns the data network type for a subId |
| 1513 | */ |
| 1514 | @Override |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1515 | public int getDataNetworkTypeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1516 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * Returns the data network type |
| 1521 | */ |
| 1522 | @Override |
| 1523 | public int getVoiceNetworkType() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1524 | return getVoiceNetworkTypeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * Returns the Voice network type for a subId |
| 1529 | */ |
| 1530 | @Override |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1531 | public int getVoiceNetworkTypeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1532 | return getPhone(subId).getServiceState().getVoiceNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * @return true if a ICC card is present |
| 1537 | */ |
| 1538 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1539 | // FIXME Make changes to pass defaultSimId of type int |
| 1540 | return hasIccCardUsingSlotId(getDefaultSubscription()); |
| 1541 | } |
| 1542 | |
| 1543 | /** |
| 1544 | * @return true if a ICC card is present for a slotId |
| 1545 | */ |
| 1546 | public boolean hasIccCardUsingSlotId(long slotId) { |
| 1547 | return getPhone(slotId).getIccCard().hasIccCard(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * Return if the current radio is LTE on CDMA. This |
| 1552 | * is a tri-state return value as for a period of time |
| 1553 | * the mode may be unknown. |
| 1554 | * |
| 1555 | * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE} |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1556 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1557 | */ |
| 1558 | public int getLteOnCdmaMode() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1559 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1562 | public int getLteOnCdmaModeForSubscriber(long subId) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1563 | return getPhone(subId).getLteOnCdmaMode(); |
| 1564 | } |
| 1565 | |
| 1566 | public void setPhone(Phone phone) { |
| 1567 | mPhone = phone; |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * {@hide} |
| 1572 | * Returns Default subId, 0 in the case of single standby. |
| 1573 | */ |
| 1574 | private long getDefaultSubscription() { |
| 1575 | return SubscriptionManager.getDefaultSubId(); |
| 1576 | } |
| 1577 | |
| 1578 | private long getPreferredVoiceSubscription() { |
| 1579 | return SubscriptionManager.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1580 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1581 | |
| 1582 | /** |
| 1583 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1584 | */ |
| 1585 | public int getWhenToMakeWifiCalls() { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1586 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 1587 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1592 | */ |
| 1593 | public void setWhenToMakeWifiCalls(int preference) { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1594 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 1595 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 1596 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1599 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 1600 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 1601 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1602 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 1603 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1604 | @Override |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1605 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1606 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1607 | |
| 1608 | if (DBG) log("iccOpenLogicalChannel: " + AID); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1609 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest( |
| 1610 | CMD_OPEN_CHANNEL, AID); |
| 1611 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 1612 | return response; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | @Override |
| 1616 | public boolean iccCloseLogicalChannel(int channel) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1617 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1618 | |
| 1619 | if (DBG) log("iccCloseLogicalChannel: " + channel); |
| 1620 | if (channel < 0) { |
| 1621 | return false; |
| 1622 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1623 | Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1624 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 1625 | return success; |
| 1626 | } |
| 1627 | |
| 1628 | @Override |
| 1629 | public String iccTransmitApduLogicalChannel(int channel, int cla, |
| 1630 | int command, int p1, int p2, int p3, String data) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1631 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1632 | |
| 1633 | if (DBG) { |
| 1634 | log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla + |
| 1635 | " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + |
| 1636 | " data=" + data); |
| 1637 | } |
| 1638 | |
| 1639 | if (channel < 0) { |
| 1640 | return ""; |
| 1641 | } |
| 1642 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1643 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1644 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data)); |
| 1645 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
| 1646 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1647 | // Append the returned status code to the end of the response payload. |
| 1648 | String s = Integer.toHexString( |
| 1649 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 1650 | if (response.payload != null) { |
| 1651 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1652 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1653 | return s; |
| 1654 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1655 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1656 | @Override |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1657 | public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2, |
| 1658 | int p3, String data) { |
| 1659 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1660 | |
| 1661 | if (DBG) { |
| 1662 | log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1=" |
| 1663 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 1664 | } |
| 1665 | |
| 1666 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 1667 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data)); |
| 1668 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
| 1669 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1670 | // Append the returned status code to the end of the response payload. |
| 1671 | String s = Integer.toHexString( |
| 1672 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 1673 | if (response.payload != null) { |
| 1674 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1675 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 1676 | return s; |
| 1677 | } |
| 1678 | |
| 1679 | @Override |
| 1680 | public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, |
| 1681 | String filePath) { |
| 1682 | enforceModifyPermissionOrCarrierPrivilege(); |
| 1683 | |
| 1684 | if (DBG) { |
| 1685 | log("Exchange SIM_IO " + fileID + ":" + command + " " + |
| 1686 | p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 1687 | } |
| 1688 | |
| 1689 | IccIoResult response = |
| 1690 | (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO, |
| 1691 | new IccAPDUArgument(fileID, command, -1, p1, p2, p3, filePath)); |
| 1692 | |
| 1693 | if (DBG) { |
| 1694 | log("Exchange SIM_IO [R]" + response); |
| 1695 | } |
| 1696 | |
| 1697 | byte[] result = null; |
| 1698 | int length = 2; |
| 1699 | if (response.payload != null) { |
| 1700 | length = 2 + response.payload.length; |
| 1701 | result = new byte[length]; |
| 1702 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 1703 | } else { |
| 1704 | result = new byte[length]; |
| 1705 | } |
| 1706 | |
| 1707 | result[length - 1] = (byte) response.sw2; |
| 1708 | result[length - 2] = (byte) response.sw1; |
| 1709 | return result; |
| 1710 | } |
| 1711 | |
| 1712 | @Override |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1713 | public String sendEnvelopeWithStatus(String content) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1714 | enforceModifyPermissionOrCarrierPrivilege(); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1715 | |
| 1716 | IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content); |
| 1717 | if (response.payload == null) { |
| 1718 | return ""; |
| 1719 | } |
| 1720 | |
| 1721 | // Append the returned status code to the end of the response payload. |
| 1722 | String s = Integer.toHexString( |
| 1723 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 1724 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1725 | return s; |
| 1726 | } |
| 1727 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1728 | /** |
| 1729 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1730 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1731 | * |
| 1732 | * @param itemID the ID of the item to read |
| 1733 | * @return the NV item as a String, or null on error. |
| 1734 | */ |
| 1735 | @Override |
| 1736 | public String nvReadItem(int itemID) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1737 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1738 | if (DBG) log("nvReadItem: item " + itemID); |
| 1739 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); |
| 1740 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 1741 | return value; |
| 1742 | } |
| 1743 | |
| 1744 | /** |
| 1745 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1746 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1747 | * |
| 1748 | * @param itemID the ID of the item to read |
| 1749 | * @param itemValue the value to write, as a String |
| 1750 | * @return true on success; false on any failure |
| 1751 | */ |
| 1752 | @Override |
| 1753 | public boolean nvWriteItem(int itemID, String itemValue) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1754 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1755 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 1756 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| 1757 | new Pair<Integer, String>(itemID, itemValue)); |
| 1758 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 1759 | return success; |
| 1760 | } |
| 1761 | |
| 1762 | /** |
| 1763 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 1764 | * Used for device configuration by some CDMA operators. |
| 1765 | * |
| 1766 | * @param preferredRoamingList byte array containing the new PRL |
| 1767 | * @return true on success; false on any failure |
| 1768 | */ |
| 1769 | @Override |
| 1770 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1771 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1772 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 1773 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 1774 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 1775 | return success; |
| 1776 | } |
| 1777 | |
| 1778 | /** |
| 1779 | * Perform the specified type of NV config reset. |
| 1780 | * Used for device configuration by some CDMA operators. |
| 1781 | * |
| 1782 | * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) |
| 1783 | * @return true on success; false on any failure |
| 1784 | */ |
| 1785 | @Override |
| 1786 | public boolean nvResetConfig(int resetType) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1787 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1788 | if (DBG) log("nvResetConfig: type " + resetType); |
| 1789 | Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); |
| 1790 | if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); |
| 1791 | return success; |
| 1792 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1793 | |
| 1794 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1795 | * {@hide} |
| 1796 | * Returns Default sim, 0 in the case of single standby. |
| 1797 | */ |
| 1798 | public int getDefaultSim() { |
| 1799 | //TODO Need to get it from Telephony Devcontroller |
| 1800 | return 0; |
| 1801 | } |
| 1802 | |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 1803 | public String[] getPcscfAddress(String apnType) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1804 | enforceReadPermission(); |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 1805 | return mPhone.getPcscfAddress(apnType); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | public void setImsRegistrationState(boolean registered) { |
| 1809 | enforceModifyPermission(); |
| 1810 | mPhone.setImsRegistrationState(registered); |
| 1811 | } |
| 1812 | |
| 1813 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 1814 | * Get the calculated preferred network type. |
| 1815 | * Used for debugging incorrect network type. |
| 1816 | * |
| 1817 | * @return the preferred network type, defined in RILConstants.java. |
| 1818 | */ |
| 1819 | @Override |
| 1820 | public int getCalculatedPreferredNetworkType() { |
| 1821 | enforceReadPermission(); |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1822 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get PhoneId from somewhere. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1826 | * Get the preferred network type. |
| 1827 | * Used for device configuration by some CDMA operators. |
| 1828 | * |
| 1829 | * @return the preferred network type, defined in RILConstants.java. |
| 1830 | */ |
| 1831 | @Override |
| 1832 | public int getPreferredNetworkType() { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1833 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1834 | if (DBG) log("getPreferredNetworkType"); |
| 1835 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null); |
| 1836 | int networkType = (result != null ? result[0] : -1); |
| 1837 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 1838 | return networkType; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Set the preferred network type. |
| 1843 | * Used for device configuration by some CDMA operators. |
| 1844 | * |
| 1845 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 1846 | * @return true on success; false on any failure. |
| 1847 | */ |
| 1848 | @Override |
| 1849 | public boolean setPreferredNetworkType(int networkType) { |
Junda Liu | a2e3601 | 2014-07-09 18:30:01 -0700 | [diff] [blame] | 1850 | enforceModifyPermissionOrCarrierPrivilege(); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1851 | if (DBG) log("setPreferredNetworkType: type " + networkType); |
| 1852 | Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType); |
| 1853 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 1854 | if (success) { |
| 1855 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 1856 | Settings.Global.PREFERRED_NETWORK_MODE, networkType); |
| 1857 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1858 | return success; |
| 1859 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1860 | |
| 1861 | /** |
| 1862 | * Set mobile data enabled |
| 1863 | * Used by the user through settings etc to turn on/off mobile data |
| 1864 | * |
| 1865 | * @param enable {@code true} turn turn data on, else {@code false} |
| 1866 | */ |
| 1867 | @Override |
| 1868 | public void setDataEnabled(boolean enable) { |
| 1869 | enforceModifyPermission(); |
| 1870 | mPhone.setDataEnabled(enable); |
| 1871 | } |
| 1872 | |
| 1873 | /** |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1874 | * Get whether mobile data is enabled. |
| 1875 | * |
| 1876 | * Note that this used to be available from ConnectivityService, gated by |
| 1877 | * ACCESS_NETWORK_STATE permission, so this will accept either that or |
| 1878 | * our MODIFY_PHONE_STATE. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1879 | * |
| 1880 | * @return {@code true} if data is enabled else {@code false} |
| 1881 | */ |
| 1882 | @Override |
| 1883 | public boolean getDataEnabled() { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1884 | try { |
| 1885 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 1886 | null); |
| 1887 | } catch (Exception e) { |
| 1888 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1889 | null); |
| 1890 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1891 | return mPhone.getDataEnabled(); |
| 1892 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 1893 | |
| 1894 | @Override |
| 1895 | public int hasCarrierPrivileges() { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1896 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1897 | if (card == null) { |
| 1898 | loge("hasCarrierPrivileges: No UICC"); |
| 1899 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 1900 | } |
| 1901 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | f1ac4c9 | 2014-07-14 13:54:28 -0700 | [diff] [blame] | 1902 | mPhone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 1903 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 1904 | |
| 1905 | @Override |
Shishir Agrawal | 6d5a285 | 2014-07-11 16:32:57 -0700 | [diff] [blame] | 1906 | public int checkCarrierPrivilegesForPackage(String pkgname) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 1907 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1908 | if (card == null) { |
| 1909 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 1910 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 1911 | } |
| 1912 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname); |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 1913 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 1914 | |
| 1915 | @Override |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1916 | public List<String> getCarrierPackageNamesForIntent(Intent intent) { |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1917 | UiccCard card = UiccController.getInstance().getUiccCard(); |
| 1918 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1919 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1920 | return null ; |
| 1921 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 1922 | return card.getCarrierPackageNamesForIntent( |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1923 | mPhone.getContext().getPackageManager(), intent); |
| 1924 | } |
| 1925 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1926 | private String getIccId(long subId) { |
| 1927 | UiccCard card = getPhone(subId).getUiccCard(); |
| 1928 | if (card == null) { |
| 1929 | loge("getIccId: No UICC"); |
| 1930 | return null; |
| 1931 | } |
| 1932 | String iccId = card.getIccId(); |
| 1933 | if (TextUtils.isEmpty(iccId)) { |
| 1934 | loge("getIccId: ICC ID is null or empty."); |
| 1935 | return null; |
| 1936 | } |
| 1937 | return iccId; |
| 1938 | } |
| 1939 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 1940 | @Override |
Junda Liu | df6b6b9 | 2014-09-05 18:13:46 -0700 | [diff] [blame] | 1941 | public void enableSimplifiedNetworkSettingsForSubscriber(long subId, boolean enable) { |
Derek Tan | 352d8cd | 2014-07-12 12:57:11 -0700 | [diff] [blame] | 1942 | enforceModifyPermissionOrCarrierPrivilege(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1943 | |
| 1944 | String iccId = getIccId(subId); |
| 1945 | if (iccId != null) { |
| 1946 | String snsPrefKey = PREF_CARRIERS_SIMPLIFIED_NETWORK_SETTINGS_PREFIX + iccId; |
| 1947 | SharedPreferences.Editor editor = carrierPrivilegeConfigs.edit(); |
| 1948 | if (enable) { |
| 1949 | editor.putBoolean(snsPrefKey, true); |
| 1950 | } else { |
| 1951 | editor.remove(snsPrefKey); |
| 1952 | } |
| 1953 | editor.commit(); |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | @Override |
Junda Liu | df6b6b9 | 2014-09-05 18:13:46 -0700 | [diff] [blame] | 1958 | public boolean getSimplifiedNetworkSettingsEnabledForSubscriber(long subId) { |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 1959 | enforceReadPermission(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1960 | String iccId = getIccId(subId); |
| 1961 | if (iccId != null) { |
| 1962 | String snsPrefKey = PREF_CARRIERS_SIMPLIFIED_NETWORK_SETTINGS_PREFIX + iccId; |
| 1963 | return carrierPrivilegeConfigs.getBoolean(snsPrefKey, false); |
| 1964 | } |
| 1965 | return false; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 1966 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 1967 | |
| 1968 | @Override |
Junda Liu | df6b6b9 | 2014-09-05 18:13:46 -0700 | [diff] [blame] | 1969 | public void setLine1NumberForDisplayForSubscriber(long subId, String alphaTag, String number) { |
Derek Tan | 352d8cd | 2014-07-12 12:57:11 -0700 | [diff] [blame] | 1970 | enforceModifyPermissionOrCarrierPrivilege(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1971 | |
| 1972 | String iccId = getIccId(subId); |
| 1973 | if (iccId != null) { |
| 1974 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 1975 | SharedPreferences.Editor editor = carrierPrivilegeConfigs.edit(); |
| 1976 | if (alphaTag == null) { |
| 1977 | editor.remove(alphaTagPrefKey); |
| 1978 | } else { |
| 1979 | editor.putString(alphaTagPrefKey, alphaTag); |
| 1980 | } |
| 1981 | |
| 1982 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 1983 | if (number == null) { |
| 1984 | editor.remove(numberPrefKey); |
| 1985 | } else { |
| 1986 | editor.putString(numberPrefKey, number); |
| 1987 | } |
| 1988 | editor.commit(); |
| 1989 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | @Override |
| 1993 | public String getLine1NumberForDisplay(long subId) { |
| 1994 | enforceReadPermission(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1995 | |
| 1996 | String iccId = getIccId(subId); |
| 1997 | if (iccId != null) { |
| 1998 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 1999 | return carrierPrivilegeConfigs.getString(numberPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2000 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2001 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | @Override |
| 2005 | public String getLine1AlphaTagForDisplay(long subId) { |
| 2006 | enforceReadPermission(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2007 | |
| 2008 | String iccId = getIccId(subId); |
| 2009 | if (iccId != null) { |
| 2010 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 2011 | return carrierPrivilegeConfigs.getString(alphaTagPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2012 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 2013 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 2014 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2015 | |
| 2016 | @Override |
Shishir Agrawal | a3dfd75 | 2014-09-04 13:25:42 -0700 | [diff] [blame] | 2017 | public boolean setOperatorBrandOverride(String brand) { |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2018 | enforceModifyPermissionOrCarrierPrivilege(); |
Shishir Agrawal | a3dfd75 | 2014-09-04 13:25:42 -0700 | [diff] [blame] | 2019 | return mPhone.setOperatorBrandOverride(brand); |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 2020 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 2021 | |
| 2022 | @Override |
| 2023 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 2024 | enforceModifyPermission(); |
| 2025 | |
| 2026 | int returnValue = 0; |
| 2027 | try { |
| 2028 | AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
| 2029 | if(result.exception == null) { |
| 2030 | if (result.result != null) { |
| 2031 | byte[] responseData = (byte[])(result.result); |
| 2032 | if(responseData.length > oemResp.length) { |
| 2033 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 2034 | responseData.length + "bytes. Buffer Size is " + |
| 2035 | oemResp.length + "bytes."); |
| 2036 | } |
| 2037 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 2038 | returnValue = responseData.length; |
| 2039 | } |
| 2040 | } else { |
| 2041 | CommandException ex = (CommandException) result.exception; |
| 2042 | returnValue = ex.getCommandError().ordinal(); |
| 2043 | if(returnValue > 0) returnValue *= -1; |
| 2044 | } |
| 2045 | } catch (RuntimeException e) { |
| 2046 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 2047 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 2048 | if(returnValue > 0) returnValue *= -1; |
| 2049 | } |
| 2050 | |
| 2051 | return returnValue; |
| 2052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } |