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; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 24 | import android.net.ConnectivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.net.Uri; |
| 26 | import android.os.AsyncResult; |
| 27 | import android.os.Binder; |
| 28 | import android.os.Bundle; |
| 29 | import android.os.Handler; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 30 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.os.Looper; |
| 32 | import android.os.Message; |
| 33 | import android.os.Process; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 34 | import android.os.RemoteException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.os.ServiceManager; |
| 36 | import android.os.UserHandle; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 37 | import android.provider.Settings; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.telephony.CellInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 39 | import android.telephony.NeighboringCellInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.telephony.ServiceState; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 41 | import android.telephony.SubscriptionManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 42 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.text.TextUtils; |
| 44 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 45 | import android.util.Pair; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 47 | import com.android.internal.telephony.CallManager; |
| 48 | import com.android.internal.telephony.CommandException; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 49 | import com.android.internal.telephony.Connection; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 52 | import com.android.internal.telephony.IccCard; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import com.android.internal.telephony.Phone; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 54 | import com.android.internal.telephony.PhoneFactory; |
| 55 | import com.android.internal.telephony.CallManager; |
| 56 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.dataconnection.DctController; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.uicc.IccIoResult; |
| 60 | import com.android.internal.telephony.uicc.IccUtils; |
| 61 | import com.android.internal.telephony.uicc.UiccController; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 62 | import com.android.internal.util.HexDump; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 64 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 65 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import java.util.ArrayList; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 67 | import java.util.HashMap; |
| 68 | import java.util.Iterator; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import java.util.List; |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 70 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Implementation of the ITelephony interface. |
| 74 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 75 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 77 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 78 | private static final boolean DBG_LOC = false; |
| 79 | |
| 80 | // Message codes used with mMainThreadHandler |
| 81 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| 82 | private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; |
| 83 | private static final int EVENT_NEIGHBORING_CELL_DONE = 3; |
| 84 | private static final int CMD_ANSWER_RINGING_CALL = 4; |
| 85 | private static final int CMD_END_CALL = 5; // not used yet |
| 86 | private static final int CMD_SILENCE_RINGER = 6; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 87 | private static final int CMD_TRANSMIT_APDU = 7; |
| 88 | private static final int EVENT_TRANSMIT_APDU_DONE = 8; |
| 89 | private static final int CMD_OPEN_CHANNEL = 9; |
| 90 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 91 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 92 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | private static final int CMD_NV_READ_ITEM = 13; |
| 94 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 95 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 96 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 97 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 98 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| 99 | private static final int CMD_NV_RESET_CONFIG = 19; |
| 100 | private static final int EVENT_NV_RESET_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 101 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 102 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 103 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 104 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 105 | private static final int CMD_SEND_ENVELOPE = 25; |
| 106 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Junda Liu | 787bc7e | 2014-06-30 13:38:02 -0700 | [diff] [blame] | 107 | private static final int CMD_SET_CDMA_SUBSCRIPTION = 27; |
| 108 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_DONE = 28; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | |
| 110 | /** The singleton instance. */ |
| 111 | private static PhoneInterfaceManager sInstance; |
| 112 | |
| 113 | PhoneGlobals mApp; |
| 114 | Phone mPhone; |
| 115 | CallManager mCM; |
| 116 | AppOpsManager mAppOps; |
| 117 | MainThreadHandler mMainThreadHandler; |
| 118 | |
| 119 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 120 | * A request object to use for transmitting data to an ICC. |
| 121 | */ |
| 122 | private static final class IccAPDUArgument { |
| 123 | public int channel, cla, command, p1, p2, p3; |
| 124 | public String data; |
| 125 | |
| 126 | public IccAPDUArgument(int channel, int cla, int command, |
| 127 | int p1, int p2, int p3, String data) { |
| 128 | this.channel = channel; |
| 129 | this.cla = cla; |
| 130 | this.command = command; |
| 131 | this.p1 = p1; |
| 132 | this.p2 = p2; |
| 133 | this.p3 = p3; |
| 134 | this.data = data; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 140 | * request after sending. The main thread will notify the request when it is complete. |
| 141 | */ |
| 142 | private static final class MainThreadRequest { |
| 143 | /** The argument to use for the request */ |
| 144 | public Object argument; |
| 145 | /** The result of the request that is run on the main thread */ |
| 146 | public Object result; |
| 147 | |
| 148 | public MainThreadRequest(Object argument) { |
| 149 | this.argument = argument; |
| 150 | } |
| 151 | } |
| 152 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 153 | private static final class IncomingThirdPartyCallArgs { |
| 154 | public final ComponentName component; |
| 155 | public final String callId; |
| 156 | public final String callerDisplayName; |
| 157 | |
| 158 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 159 | String callerDisplayName) { |
| 160 | this.component = component; |
| 161 | this.callId = callId; |
| 162 | this.callerDisplayName = callerDisplayName; |
| 163 | } |
| 164 | } |
| 165 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | /** |
| 167 | * A handler that processes messages on the main thread in the phone process. Since many |
| 168 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 169 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 170 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 171 | * on, which will be notified when the operation completes and will contain the result of the |
| 172 | * request. |
| 173 | * |
| 174 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 175 | * note that request.result must be set to something non-null for the calling thread to |
| 176 | * unblock. |
| 177 | */ |
| 178 | private final class MainThreadHandler extends Handler { |
| 179 | @Override |
| 180 | public void handleMessage(Message msg) { |
| 181 | MainThreadRequest request; |
| 182 | Message onCompleted; |
| 183 | AsyncResult ar; |
| 184 | |
| 185 | switch (msg.what) { |
| 186 | case CMD_HANDLE_PIN_MMI: |
| 187 | request = (MainThreadRequest) msg.obj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | request.result = mPhone.handlePinMmi((String) request.argument); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | // Wake up the requesting thread |
| 190 | synchronized (request) { |
| 191 | request.notifyAll(); |
| 192 | } |
| 193 | break; |
| 194 | |
| 195 | case CMD_HANDLE_NEIGHBORING_CELL: |
| 196 | request = (MainThreadRequest) msg.obj; |
| 197 | onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, |
| 198 | request); |
| 199 | mPhone.getNeighboringCids(onCompleted); |
| 200 | break; |
| 201 | |
| 202 | case EVENT_NEIGHBORING_CELL_DONE: |
| 203 | ar = (AsyncResult) msg.obj; |
| 204 | request = (MainThreadRequest) ar.userObj; |
| 205 | if (ar.exception == null && ar.result != null) { |
| 206 | request.result = ar.result; |
| 207 | } else { |
| 208 | // create an empty list to notify the waiting thread |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | request.result = new ArrayList<NeighboringCellInfo>(0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 210 | } |
| 211 | // Wake up the requesting thread |
| 212 | synchronized (request) { |
| 213 | request.notifyAll(); |
| 214 | } |
| 215 | break; |
| 216 | |
| 217 | case CMD_ANSWER_RINGING_CALL: |
| 218 | answerRingingCallInternal(); |
| 219 | break; |
| 220 | |
| 221 | case CMD_SILENCE_RINGER: |
| 222 | silenceRingerInternal(); |
| 223 | break; |
| 224 | |
| 225 | case CMD_END_CALL: |
| 226 | request = (MainThreadRequest) msg.obj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 227 | boolean hungUp; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | int phoneType = mPhone.getPhoneType(); |
| 229 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 230 | // CDMA: If the user presses the Power button we treat it as |
| 231 | // ending the complete call session |
| 232 | hungUp = PhoneUtils.hangupRingingAndActive(mPhone); |
| 233 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
| 234 | // GSM: End the call as per the Phone state |
| 235 | hungUp = PhoneUtils.hangup(mCM); |
| 236 | } else { |
| 237 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 238 | } |
| 239 | if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); |
| 240 | request.result = hungUp; |
| 241 | // Wake up the requesting thread |
| 242 | synchronized (request) { |
| 243 | request.notifyAll(); |
| 244 | } |
| 245 | break; |
| 246 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 247 | case CMD_TRANSMIT_APDU: |
| 248 | request = (MainThreadRequest) msg.obj; |
| 249 | IccAPDUArgument argument = (IccAPDUArgument) request.argument; |
| 250 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_DONE, request); |
| 251 | UiccController.getInstance().getUiccCard().iccTransmitApduLogicalChannel( |
| 252 | argument.channel, argument.cla, argument.command, |
| 253 | argument.p1, argument.p2, argument.p3, argument.data, |
| 254 | onCompleted); |
| 255 | break; |
| 256 | |
| 257 | case EVENT_TRANSMIT_APDU_DONE: |
| 258 | ar = (AsyncResult) msg.obj; |
| 259 | request = (MainThreadRequest) ar.userObj; |
| 260 | if (ar.exception == null && ar.result != null) { |
| 261 | request.result = ar.result; |
| 262 | } else { |
| 263 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 264 | if (ar.result == null) { |
| 265 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 266 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 267 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 268 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 269 | } else { |
| 270 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 271 | } |
| 272 | } |
| 273 | synchronized (request) { |
| 274 | request.notifyAll(); |
| 275 | } |
| 276 | break; |
| 277 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 278 | case CMD_SEND_ENVELOPE: |
| 279 | request = (MainThreadRequest) msg.obj; |
| 280 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 281 | UiccController.getInstance().getUiccCard().sendEnvelopeWithStatus( |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 282 | (String)request.argument, onCompleted); |
| 283 | break; |
| 284 | |
| 285 | case EVENT_SEND_ENVELOPE_DONE: |
| 286 | ar = (AsyncResult) msg.obj; |
| 287 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 288 | if (ar.exception == null && ar.result != null) { |
| 289 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 290 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 291 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 292 | if (ar.result == null) { |
| 293 | loge("sendEnvelopeWithStatus: Empty response"); |
| 294 | } else if (ar.exception instanceof CommandException) { |
| 295 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 296 | ar.exception); |
| 297 | } else { |
| 298 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 299 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 300 | } |
| 301 | synchronized (request) { |
| 302 | request.notifyAll(); |
| 303 | } |
| 304 | break; |
| 305 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 306 | case CMD_OPEN_CHANNEL: |
| 307 | request = (MainThreadRequest) msg.obj; |
| 308 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
| 309 | UiccController.getInstance().getUiccCard().iccOpenLogicalChannel( |
| 310 | (String)request.argument, onCompleted); |
| 311 | break; |
| 312 | |
| 313 | case EVENT_OPEN_CHANNEL_DONE: |
| 314 | ar = (AsyncResult) msg.obj; |
| 315 | request = (MainThreadRequest) ar.userObj; |
| 316 | if (ar.exception == null && ar.result != null) { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 317 | request.result = ((int[]) ar.result)[0]; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 318 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 319 | request.result = -1; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 320 | if (ar.result == null) { |
| 321 | loge("iccOpenLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 322 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 323 | loge("iccOpenLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 324 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 325 | } else { |
| 326 | loge("iccOpenLogicalChannel: Unknown exception"); |
| 327 | } |
| 328 | } |
| 329 | synchronized (request) { |
| 330 | request.notifyAll(); |
| 331 | } |
| 332 | break; |
| 333 | |
| 334 | case CMD_CLOSE_CHANNEL: |
| 335 | request = (MainThreadRequest) msg.obj; |
| 336 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, |
| 337 | request); |
| 338 | UiccController.getInstance().getUiccCard().iccCloseLogicalChannel( |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 339 | (Integer) request.argument, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 340 | onCompleted); |
| 341 | break; |
| 342 | |
| 343 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 344 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 345 | break; |
| 346 | |
| 347 | case CMD_NV_READ_ITEM: |
| 348 | request = (MainThreadRequest) msg.obj; |
| 349 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| 350 | mPhone.nvReadItem((Integer) request.argument, onCompleted); |
| 351 | break; |
| 352 | |
| 353 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 354 | ar = (AsyncResult) msg.obj; |
| 355 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 356 | if (ar.exception == null && ar.result != null) { |
| 357 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 358 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 359 | request.result = ""; |
| 360 | if (ar.result == null) { |
| 361 | loge("nvReadItem: Empty response"); |
| 362 | } else if (ar.exception instanceof CommandException) { |
| 363 | loge("nvReadItem: CommandException: " + |
| 364 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 365 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 366 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | synchronized (request) { |
| 370 | request.notifyAll(); |
| 371 | } |
| 372 | break; |
| 373 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 374 | case CMD_NV_WRITE_ITEM: |
| 375 | request = (MainThreadRequest) msg.obj; |
| 376 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 377 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| 378 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); |
| 379 | break; |
| 380 | |
| 381 | case EVENT_NV_WRITE_ITEM_DONE: |
| 382 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 383 | break; |
| 384 | |
| 385 | case CMD_NV_WRITE_CDMA_PRL: |
| 386 | request = (MainThreadRequest) msg.obj; |
| 387 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 388 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 389 | break; |
| 390 | |
| 391 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 392 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 393 | break; |
| 394 | |
| 395 | case CMD_NV_RESET_CONFIG: |
| 396 | request = (MainThreadRequest) msg.obj; |
| 397 | onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); |
| 398 | mPhone.nvResetConfig((Integer) request.argument, onCompleted); |
| 399 | break; |
| 400 | |
| 401 | case EVENT_NV_RESET_CONFIG_DONE: |
| 402 | handleNullReturnEvent(msg, "nvResetConfig"); |
| 403 | break; |
| 404 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 405 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 406 | request = (MainThreadRequest) msg.obj; |
| 407 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 408 | mPhone.getPreferredNetworkType(onCompleted); |
| 409 | break; |
| 410 | |
| 411 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 412 | ar = (AsyncResult) msg.obj; |
| 413 | request = (MainThreadRequest) ar.userObj; |
| 414 | if (ar.exception == null && ar.result != null) { |
| 415 | request.result = ar.result; // Integer |
| 416 | } else { |
| 417 | request.result = -1; |
| 418 | if (ar.result == null) { |
| 419 | loge("getPreferredNetworkType: Empty response"); |
| 420 | } else if (ar.exception instanceof CommandException) { |
| 421 | loge("getPreferredNetworkType: CommandException: " + |
| 422 | ar.exception); |
| 423 | } else { |
| 424 | loge("getPreferredNetworkType: Unknown exception"); |
| 425 | } |
| 426 | } |
| 427 | synchronized (request) { |
| 428 | request.notifyAll(); |
| 429 | } |
| 430 | break; |
| 431 | |
| 432 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 433 | request = (MainThreadRequest) msg.obj; |
| 434 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 435 | int networkType = (Integer) request.argument; |
| 436 | mPhone.setPreferredNetworkType(networkType, onCompleted); |
| 437 | break; |
| 438 | |
| 439 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 440 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 441 | break; |
| 442 | |
Junda Liu | 787bc7e | 2014-06-30 13:38:02 -0700 | [diff] [blame] | 443 | case CMD_SET_CDMA_SUBSCRIPTION: |
| 444 | request = (MainThreadRequest) msg.obj; |
| 445 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_DONE, request); |
| 446 | int subscriptionType = (Integer) request.argument; |
| 447 | mPhone.setCdmaSubscription(subscriptionType, onCompleted); |
| 448 | break; |
| 449 | |
| 450 | case EVENT_SET_CDMA_SUBSCRIPTION_DONE: |
| 451 | handleNullReturnEvent(msg, "setCdmaSubscription"); |
| 452 | break; |
| 453 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | default: |
| 455 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 456 | break; |
| 457 | } |
| 458 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 459 | |
| 460 | private void handleNullReturnEvent(Message msg, String command) { |
| 461 | AsyncResult ar = (AsyncResult) msg.obj; |
| 462 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 463 | if (ar.exception == null) { |
| 464 | request.result = true; |
| 465 | } else { |
| 466 | request.result = false; |
| 467 | if (ar.exception instanceof CommandException) { |
| 468 | loge(command + ": CommandException: " + ar.exception); |
| 469 | } else { |
| 470 | loge(command + ": Unknown exception"); |
| 471 | } |
| 472 | } |
| 473 | synchronized (request) { |
| 474 | request.notifyAll(); |
| 475 | } |
| 476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Posts the specified command to be executed on the main thread, |
| 481 | * waits for the request to complete, and returns the result. |
| 482 | * @see #sendRequestAsync |
| 483 | */ |
| 484 | private Object sendRequest(int command, Object argument) { |
Santos Cordon | 500b0e0 | 2014-06-17 10:33:33 -0700 | [diff] [blame] | 485 | return sendRequest(command, argument, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Posts the specified command to be executed on the main thread, |
| 490 | * waits for the request to complete, and returns the result. |
| 491 | * @see #sendRequestAsync |
| 492 | */ |
| 493 | private Object sendRequest(int command, Object argument, Object argument2) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 494 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 495 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 496 | } |
| 497 | |
| 498 | MainThreadRequest request = new MainThreadRequest(argument); |
| 499 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 500 | msg.sendToTarget(); |
| 501 | |
| 502 | // Wait for the request to complete |
| 503 | synchronized (request) { |
| 504 | while (request.result == null) { |
| 505 | try { |
| 506 | request.wait(); |
| 507 | } catch (InterruptedException e) { |
| 508 | // Do nothing, go back and wait until the request is complete |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | return request.result; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 517 | * Posts the specified command to be executed on the main thread, and |
| 518 | * returns immediately. |
| 519 | * @see #sendRequest |
| 520 | */ |
| 521 | private void sendRequestAsync(int command) { |
| 522 | mMainThreadHandler.sendEmptyMessage(command); |
| 523 | } |
| 524 | |
| 525 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 526 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 527 | * @see {@link #sendRequest(int,Object)} |
| 528 | */ |
| 529 | private void sendRequestAsync(int command, Object argument) { |
| 530 | MainThreadRequest request = new MainThreadRequest(argument); |
| 531 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 532 | msg.sendToTarget(); |
| 533 | } |
| 534 | |
| 535 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | * Initialize the singleton PhoneInterfaceManager instance. |
| 537 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 538 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 539 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | synchronized (PhoneInterfaceManager.class) { |
| 541 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 542 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 543 | } else { |
| 544 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 545 | } |
| 546 | return sInstance; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 551 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 552 | mApp = app; |
| 553 | mPhone = phone; |
| 554 | mCM = PhoneGlobals.getInstance().mCM; |
| 555 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 556 | mMainThreadHandler = new MainThreadHandler(); |
| 557 | publish(); |
| 558 | } |
| 559 | |
| 560 | private void publish() { |
| 561 | if (DBG) log("publish: " + this); |
| 562 | |
| 563 | ServiceManager.addService("phone", this); |
| 564 | } |
| 565 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 566 | // returns phone associated with the subId. |
| 567 | // getPhone(0) returns default phone in single SIM mode. |
| 568 | private Phone getPhone(long subId) { |
| 569 | // FIXME: hack for the moment |
| 570 | return mPhone; |
| 571 | // return PhoneUtils.getPhoneUsingSubId(subId); |
| 572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 573 | // |
| 574 | // Implementation of the ITelephony interface. |
| 575 | // |
| 576 | |
| 577 | public void dial(String number) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 578 | dialUsingSubId(getPreferredVoiceSubscription(), number); |
| 579 | } |
| 580 | |
| 581 | public void dialUsingSubId(long subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | if (DBG) log("dial: " + number); |
| 583 | // No permission check needed here: This is just a wrapper around the |
| 584 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 585 | // the UI before it does anything. |
| 586 | |
| 587 | String url = createTelUrl(number); |
| 588 | if (url == null) { |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | // PENDING: should we just silently fail if phone is offhook or ringing? |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 593 | PhoneConstants.State state = mCM.getState(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 594 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 595 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 596 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 597 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 598 | mApp.startActivity(intent); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | public void call(String callingPackage, String number) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 603 | callUsingSubId(getPreferredVoiceSubscription(), callingPackage, number); |
| 604 | } |
| 605 | |
| 606 | public void callUsingSubId(long subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 607 | if (DBG) log("call: " + number); |
| 608 | |
| 609 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 610 | // need to do a permission check since we're calling startActivity() |
| 611 | // from the context of the phone app. |
| 612 | enforceCallPermission(); |
| 613 | |
| 614 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 615 | != AppOpsManager.MODE_ALLOWED) { |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | String url = createTelUrl(number); |
| 620 | if (url == null) { |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 625 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 626 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 627 | mApp.startActivity(intent); |
| 628 | } |
| 629 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 630 | /** |
| 631 | * End a call based on call state |
| 632 | * @return true is a call was ended |
| 633 | */ |
| 634 | public boolean endCall() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 635 | return endCallUsingSubId(getDefaultSubscription()); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * End a call based on the call state of the subId |
| 640 | * @return true is a call was ended |
| 641 | */ |
| 642 | public boolean endCallUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 643 | enforceCallPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 644 | return (Boolean) sendRequest(CMD_END_CALL, subId, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | public void answerRingingCall() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 648 | answerRingingCallUsingSubId(getDefaultSubscription()); |
| 649 | } |
| 650 | |
| 651 | public void answerRingingCallUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 652 | if (DBG) log("answerRingingCall..."); |
| 653 | // TODO: there should eventually be a separate "ANSWER_PHONE" permission, |
| 654 | // but that can probably wait till the big TelephonyManager API overhaul. |
| 655 | // For now, protect this call with the MODIFY_PHONE_STATE permission. |
| 656 | enforceModifyPermission(); |
| 657 | sendRequestAsync(CMD_ANSWER_RINGING_CALL); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Make the actual telephony calls to implement answerRingingCall(). |
| 662 | * This should only be called from the main thread of the Phone app. |
| 663 | * @see #answerRingingCall |
| 664 | * |
| 665 | * TODO: it would be nice to return true if we answered the call, or |
| 666 | * false if there wasn't actually a ringing incoming call, or some |
| 667 | * other error occurred. (In other words, pass back the return value |
| 668 | * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) |
| 669 | * But that would require calling this method via sendRequest() rather |
| 670 | * than sendRequestAsync(), and right now we don't actually *need* that |
| 671 | * return value, so let's just return void for now. |
| 672 | */ |
| 673 | private void answerRingingCallInternal() { |
| 674 | final boolean hasRingingCall = !mPhone.getRingingCall().isIdle(); |
| 675 | if (hasRingingCall) { |
| 676 | final boolean hasActiveCall = !mPhone.getForegroundCall().isIdle(); |
| 677 | final boolean hasHoldingCall = !mPhone.getBackgroundCall().isIdle(); |
| 678 | if (hasActiveCall && hasHoldingCall) { |
| 679 | // Both lines are in use! |
| 680 | // TODO: provide a flag to let the caller specify what |
| 681 | // policy to use if both lines are in use. (The current |
| 682 | // behavior is hardwired to "answer incoming, end ongoing", |
| 683 | // which is how the CALL button is specced to behave.) |
| 684 | PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); |
| 685 | return; |
| 686 | } else { |
| 687 | // answerCall() will automatically hold the current active |
| 688 | // call, if there is one. |
| 689 | PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); |
| 690 | return; |
| 691 | } |
| 692 | } else { |
| 693 | // No call was ringing. |
| 694 | return; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | public void silenceRinger() { |
| 699 | if (DBG) log("silenceRinger..."); |
| 700 | // TODO: find a more appropriate permission to check here. |
| 701 | // (That can probably wait till the big TelephonyManager API overhaul. |
| 702 | // For now, protect this call with the MODIFY_PHONE_STATE permission.) |
| 703 | enforceModifyPermission(); |
| 704 | sendRequestAsync(CMD_SILENCE_RINGER); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Internal implemenation of silenceRinger(). |
| 709 | * This should only be called from the main thread of the Phone app. |
| 710 | * @see #silenceRinger |
| 711 | */ |
| 712 | private void silenceRingerInternal() { |
| 713 | if ((mCM.getState() == PhoneConstants.State.RINGING) |
| 714 | && mApp.notifier.isRinging()) { |
| 715 | // Ringer is actually playing, so silence it. |
| 716 | if (DBG) log("silenceRingerInternal: silencing..."); |
| 717 | mApp.notifier.silenceRinger(); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | public boolean isOffhook() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 722 | return isOffhookUsingSubId(getDefaultSubscription()); |
| 723 | } |
| 724 | |
| 725 | public boolean isOffhookUsingSubId(long subId) { |
| 726 | return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | public boolean isRinging() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 730 | return (isRingingUsingSubId(getDefaultSubscription())); |
| 731 | } |
| 732 | |
| 733 | public boolean isRingingUsingSubId(long subId) { |
| 734 | return (getPhone(subId).getState() == PhoneConstants.State.RINGING); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | public boolean isIdle() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 738 | return isIdleUsingSubId(getDefaultSubscription()); |
| 739 | } |
| 740 | |
| 741 | public boolean isIdleUsingSubId(long subId) { |
| 742 | return (getPhone(subId).getState() == PhoneConstants.State.IDLE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | public boolean isSimPinEnabled() { |
| 746 | enforceReadPermission(); |
| 747 | return (PhoneGlobals.getInstance().isSimPinEnabled()); |
| 748 | } |
| 749 | |
| 750 | public boolean supplyPin(String pin) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 751 | return supplyPinUsingSubId(getDefaultSubscription(), pin); |
| 752 | } |
| 753 | |
| 754 | public boolean supplyPinUsingSubId(long subId, String pin) { |
| 755 | int [] resultArray = supplyPinReportResultUsingSubId(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 756 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 757 | } |
| 758 | |
| 759 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 760 | return supplyPukUsingSubId(getDefaultSubscription(), puk, pin); |
| 761 | } |
| 762 | |
| 763 | public boolean supplyPukUsingSubId(long subId, String puk, String pin) { |
| 764 | int [] resultArray = supplyPukReportResultUsingSubId(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 765 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 766 | } |
| 767 | |
| 768 | /** {@hide} */ |
| 769 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 770 | return supplyPinReportResultUsingSubId(getDefaultSubscription(), pin); |
| 771 | } |
| 772 | |
| 773 | public int[] supplyPinReportResultUsingSubId(long subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 774 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 775 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 776 | checkSimPin.start(); |
| 777 | return checkSimPin.unlockSim(null, pin); |
| 778 | } |
| 779 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 780 | /** {@hide} */ |
| 781 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 782 | return supplyPukReportResultUsingSubId(getDefaultSubscription(), puk, pin); |
| 783 | } |
| 784 | |
| 785 | public int[] supplyPukReportResultUsingSubId(long subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 786 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 787 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 788 | checkSimPuk.start(); |
| 789 | return checkSimPuk.unlockSim(puk, pin); |
| 790 | } |
| 791 | |
| 792 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 793 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 794 | * a synchronous one. |
| 795 | */ |
| 796 | private static class UnlockSim extends Thread { |
| 797 | |
| 798 | private final IccCard mSimCard; |
| 799 | |
| 800 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 801 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 802 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 803 | |
| 804 | // For replies from SimCard interface |
| 805 | private Handler mHandler; |
| 806 | |
| 807 | // For async handler to identify request type |
| 808 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 809 | |
| 810 | public UnlockSim(IccCard simCard) { |
| 811 | mSimCard = simCard; |
| 812 | } |
| 813 | |
| 814 | @Override |
| 815 | public void run() { |
| 816 | Looper.prepare(); |
| 817 | synchronized (UnlockSim.this) { |
| 818 | mHandler = new Handler() { |
| 819 | @Override |
| 820 | public void handleMessage(Message msg) { |
| 821 | AsyncResult ar = (AsyncResult) msg.obj; |
| 822 | switch (msg.what) { |
| 823 | case SUPPLY_PIN_COMPLETE: |
| 824 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 825 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 826 | mRetryCount = msg.arg1; |
| 827 | if (ar.exception != null) { |
| 828 | if (ar.exception instanceof CommandException && |
| 829 | ((CommandException)(ar.exception)).getCommandError() |
| 830 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 831 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 832 | } else { |
| 833 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 834 | } |
| 835 | } else { |
| 836 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 838 | mDone = true; |
| 839 | UnlockSim.this.notifyAll(); |
| 840 | } |
| 841 | break; |
| 842 | } |
| 843 | } |
| 844 | }; |
| 845 | UnlockSim.this.notifyAll(); |
| 846 | } |
| 847 | Looper.loop(); |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Use PIN or PUK to unlock SIM card |
| 852 | * |
| 853 | * If PUK is null, unlock SIM card with PIN |
| 854 | * |
| 855 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 856 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 857 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 858 | |
| 859 | while (mHandler == null) { |
| 860 | try { |
| 861 | wait(); |
| 862 | } catch (InterruptedException e) { |
| 863 | Thread.currentThread().interrupt(); |
| 864 | } |
| 865 | } |
| 866 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 867 | |
| 868 | if (puk == null) { |
| 869 | mSimCard.supplyPin(pin, callback); |
| 870 | } else { |
| 871 | mSimCard.supplyPuk(puk, pin, callback); |
| 872 | } |
| 873 | |
| 874 | while (!mDone) { |
| 875 | try { |
| 876 | Log.d(LOG_TAG, "wait for done"); |
| 877 | wait(); |
| 878 | } catch (InterruptedException e) { |
| 879 | // Restore the interrupted status |
| 880 | Thread.currentThread().interrupt(); |
| 881 | } |
| 882 | } |
| 883 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 884 | int[] resultArray = new int[2]; |
| 885 | resultArray[0] = mResult; |
| 886 | resultArray[1] = mRetryCount; |
| 887 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
| 891 | public void updateServiceLocation() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 892 | updateServiceLocationUsingSubId(getDefaultSubscription()); |
| 893 | |
| 894 | } |
| 895 | |
| 896 | public void updateServiceLocationUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 897 | // No permission check needed here: this call is harmless, and it's |
| 898 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 899 | // already intentionally exposed to 3rd parties.) |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 900 | getPhone(subId).updateServiceLocation(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | public boolean isRadioOn() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 904 | return isRadioOnUsingSubId(getDefaultSubscription()); |
| 905 | } |
| 906 | |
| 907 | public boolean isRadioOnUsingSubId(long subId) { |
| 908 | return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | public void toggleRadioOnOff() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 912 | toggleRadioOnOffUsingSubId(getDefaultSubscription()); |
| 913 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 914 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 915 | |
| 916 | public void toggleRadioOnOffUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 917 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 918 | getPhone(subId).setRadioPower(!isRadioOnUsingSubId(subId)); |
| 919 | } |
| 920 | |
| 921 | public boolean setRadio(boolean turnOn) { |
| 922 | return setRadioUsingSubId(getDefaultSubscription(), turnOn); |
| 923 | } |
| 924 | |
| 925 | public boolean setRadioUsingSubId(long subId, boolean turnOn) { |
| 926 | enforceModifyPermission(); |
| 927 | if ((getPhone(subId).getServiceState().getState() != |
| 928 | ServiceState.STATE_POWER_OFF) != turnOn) { |
| 929 | toggleRadioOnOffUsingSubId(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 930 | } |
| 931 | return true; |
| 932 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 933 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 934 | public boolean setRadioPower(boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 935 | return setRadioPowerUsingSubId(getDefaultSubscription(), turnOn); |
| 936 | } |
| 937 | |
| 938 | public boolean setRadioPowerUsingSubId(long subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 939 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 940 | getPhone(subId).setRadioPower(turnOn); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 941 | return true; |
| 942 | } |
| 943 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 944 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 945 | public boolean enableDataConnectivity() { |
| 946 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 947 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 948 | getPhone(subId).setDataEnabled(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 949 | return true; |
| 950 | } |
| 951 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 952 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 953 | public boolean disableDataConnectivity() { |
| 954 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 955 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 956 | getPhone(subId).setDataEnabled(false); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 957 | return true; |
| 958 | } |
| 959 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 960 | // FIXME: subId version needed |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 961 | public boolean isDataConnectivityPossible() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 962 | long subId = SubscriptionManager.getDefaultDataSubId(); |
| 963 | return getPhone(subId).isDataConnectivityPossible(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | public boolean handlePinMmi(String dialString) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 967 | return handlePinMmiUsingSubId(getDefaultSubscription(), dialString); |
| 968 | } |
| 969 | |
| 970 | public boolean handlePinMmiUsingSubId(long subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 971 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 972 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 975 | public int getCallState() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 976 | return getCallStateUsingSubId(getDefaultSubscription()); |
| 977 | } |
| 978 | |
| 979 | public int getCallStateUsingSubId(long subId) { |
| 980 | return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | public int getDataState() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 984 | Phone phone = getPhone(SubscriptionManager.getDefaultDataSubId()); |
| 985 | return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | public int getDataActivity() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 989 | Phone phone = getPhone(SubscriptionManager.getDefaultDataSubId()); |
| 990 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | @Override |
| 994 | public Bundle getCellLocation() { |
| 995 | try { |
| 996 | mApp.enforceCallingOrSelfPermission( |
| 997 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 998 | } catch (SecurityException e) { |
| 999 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1000 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1001 | // is the weaker precondition |
| 1002 | mApp.enforceCallingOrSelfPermission( |
| 1003 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1004 | } |
| 1005 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1006 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1007 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1008 | Bundle data = new Bundle(); |
| 1009 | mPhone.getCellLocation().fillInNotifierBundle(data); |
| 1010 | return data; |
| 1011 | } else { |
| 1012 | if (DBG_LOC) log("getCellLocation: suppress non-active user"); |
| 1013 | return null; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void enableLocationUpdates() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1019 | enableLocationUpdatesUsingSubId(getDefaultSubscription()); |
| 1020 | } |
| 1021 | |
| 1022 | public void enableLocationUpdatesUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1023 | mApp.enforceCallingOrSelfPermission( |
| 1024 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1025 | getPhone(subId).enableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | @Override |
| 1029 | public void disableLocationUpdates() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1030 | disableLocationUpdatesUsingSubId(getDefaultSubscription()); |
| 1031 | } |
| 1032 | |
| 1033 | public void disableLocationUpdatesUsingSubId(long subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1034 | mApp.enforceCallingOrSelfPermission( |
| 1035 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1036 | getPhone(subId).disableLocationUpdates(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | @Override |
| 1040 | @SuppressWarnings("unchecked") |
| 1041 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1042 | try { |
| 1043 | mApp.enforceCallingOrSelfPermission( |
| 1044 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1045 | } catch (SecurityException e) { |
| 1046 | // If we have ACCESS_FINE_LOCATION permission, skip the check |
| 1047 | // for ACCESS_COARSE_LOCATION |
| 1048 | // A failure should throw the SecurityException from |
| 1049 | // ACCESS_COARSE_LOCATION since this is the weaker precondition |
| 1050 | mApp.enforceCallingOrSelfPermission( |
| 1051 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1052 | } |
| 1053 | |
| 1054 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1055 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1056 | return null; |
| 1057 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1058 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1059 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
| 1060 | |
| 1061 | ArrayList<NeighboringCellInfo> cells = null; |
| 1062 | |
| 1063 | try { |
| 1064 | cells = (ArrayList<NeighboringCellInfo>) sendRequest( |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1065 | CMD_HANDLE_NEIGHBORING_CELL, null, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1066 | } catch (RuntimeException e) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1067 | Log.e(LOG_TAG, "getNeighboringCellInfo " + e); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1068 | } |
| 1069 | return cells; |
| 1070 | } else { |
| 1071 | if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user"); |
| 1072 | return null; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | @Override |
| 1078 | public List<CellInfo> getAllCellInfo() { |
| 1079 | try { |
| 1080 | mApp.enforceCallingOrSelfPermission( |
| 1081 | android.Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 1082 | } catch (SecurityException e) { |
| 1083 | // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION |
| 1084 | // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this |
| 1085 | // is the weaker precondition |
| 1086 | mApp.enforceCallingOrSelfPermission( |
| 1087 | android.Manifest.permission.ACCESS_COARSE_LOCATION, null); |
| 1088 | } |
| 1089 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1090 | if (checkIfCallerIsSelfOrForegroundUser()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1091 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
| 1092 | return mPhone.getAllCellInfo(); |
| 1093 | } else { |
| 1094 | if (DBG_LOC) log("getAllCellInfo: suppress non-active user"); |
| 1095 | return null; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1099 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1100 | public void setCellInfoListRate(int rateInMillis) { |
| 1101 | mPhone.setCellInfoListRate(rateInMillis); |
| 1102 | } |
| 1103 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1104 | // |
| 1105 | // Internal helper methods. |
| 1106 | // |
| 1107 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1108 | private static boolean checkIfCallerIsSelfOrForegroundUser() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1109 | boolean ok; |
| 1110 | |
| 1111 | boolean self = Binder.getCallingUid() == Process.myUid(); |
| 1112 | if (!self) { |
| 1113 | // Get the caller's user id then clear the calling identity |
| 1114 | // which will be restored in the finally clause. |
| 1115 | int callingUser = UserHandle.getCallingUserId(); |
| 1116 | long ident = Binder.clearCallingIdentity(); |
| 1117 | |
| 1118 | try { |
| 1119 | // With calling identity cleared the current user is the foreground user. |
| 1120 | int foregroundUser = ActivityManager.getCurrentUser(); |
| 1121 | ok = (foregroundUser == callingUser); |
| 1122 | if (DBG_LOC) { |
| 1123 | log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser |
| 1124 | + " callingUser=" + callingUser + " ok=" + ok); |
| 1125 | } |
| 1126 | } catch (Exception ex) { |
| 1127 | if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex); |
| 1128 | ok = false; |
| 1129 | } finally { |
| 1130 | Binder.restoreCallingIdentity(ident); |
| 1131 | } |
| 1132 | } else { |
| 1133 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self"); |
| 1134 | ok = true; |
| 1135 | } |
| 1136 | if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok); |
| 1137 | return ok; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * Make sure the caller has the READ_PHONE_STATE permission. |
| 1142 | * |
| 1143 | * @throws SecurityException if the caller does not have the required permission |
| 1144 | */ |
| 1145 | private void enforceReadPermission() { |
| 1146 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null); |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 1151 | * |
| 1152 | * @throws SecurityException if the caller does not have the required permission |
| 1153 | */ |
| 1154 | private void enforceModifyPermission() { |
| 1155 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * Make sure the caller has the CALL_PHONE permission. |
| 1160 | * |
| 1161 | * @throws SecurityException if the caller does not have the required permission |
| 1162 | */ |
| 1163 | private void enforceCallPermission() { |
| 1164 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 1165 | } |
| 1166 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1167 | /** |
Gabriel Peal | 36ebb0d | 2014-03-20 09:20:43 -0700 | [diff] [blame] | 1168 | * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission. |
| 1169 | * |
| 1170 | * @throws SecurityException if the caller does not have the required permission |
| 1171 | */ |
| 1172 | private void enforcePrivilegedPhoneStatePermission() { |
| 1173 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 1174 | null); |
| 1175 | } |
| 1176 | |
| 1177 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1178 | * Make sure the caller has SIM_COMMUNICATION permission. |
| 1179 | * |
| 1180 | * @throws SecurityException if the caller does not have the required permission. |
| 1181 | */ |
| 1182 | private void enforceSimCommunicationPermission() { |
| 1183 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.SIM_COMMUNICATION, null); |
| 1184 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1185 | |
| 1186 | private String createTelUrl(String number) { |
| 1187 | if (TextUtils.isEmpty(number)) { |
| 1188 | return null; |
| 1189 | } |
| 1190 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1191 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1194 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1195 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1196 | } |
| 1197 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1198 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1199 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1200 | } |
| 1201 | |
| 1202 | public int getActivePhoneType() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1203 | return getActivePhoneTypeUsingSubId(getDefaultSubscription()); |
| 1204 | } |
| 1205 | |
| 1206 | public int getActivePhoneTypeUsingSubId(long subId) { |
| 1207 | return getPhone(subId).getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Returns the CDMA ERI icon index to display |
| 1212 | */ |
| 1213 | public int getCdmaEriIconIndex() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1214 | return getCdmaEriIconIndexUsingSubId(getDefaultSubscription()); |
| 1215 | |
| 1216 | } |
| 1217 | |
| 1218 | public int getCdmaEriIconIndexUsingSubId(long subId) { |
| 1219 | return getPhone(subId).getCdmaEriIconIndex(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Returns the CDMA ERI icon mode, |
| 1224 | * 0 - ON |
| 1225 | * 1 - FLASHING |
| 1226 | */ |
| 1227 | public int getCdmaEriIconMode() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1228 | return getCdmaEriIconModeUsingSubId(getDefaultSubscription()); |
| 1229 | } |
| 1230 | |
| 1231 | public int getCdmaEriIconModeUsingSubId(long subId) { |
| 1232 | return getPhone(subId).getCdmaEriIconMode(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * Returns the CDMA ERI text, |
| 1237 | */ |
| 1238 | public String getCdmaEriText() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1239 | return getCdmaEriTextUsingSubId(getDefaultSubscription()); |
| 1240 | } |
| 1241 | |
| 1242 | public String getCdmaEriTextUsingSubId(long subId) { |
| 1243 | return getPhone(subId).getCdmaEriText(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Returns true if CDMA provisioning needs to run. |
| 1248 | */ |
| 1249 | public boolean needsOtaServiceProvisioning() { |
| 1250 | return mPhone.needsOtaServiceProvisioning(); |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Returns the unread count of voicemails |
| 1255 | */ |
| 1256 | public int getVoiceMessageCount() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1257 | return getVoiceMessageCountUsingSubId(getDefaultSubscription()); |
| 1258 | } |
| 1259 | |
| 1260 | /** |
| 1261 | * Returns the unread count of voicemails for a subId |
| 1262 | */ |
| 1263 | public int getVoiceMessageCountUsingSubId( long subId) { |
| 1264 | return getPhone(subId).getVoiceMessageCount(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Returns the data network type |
| 1269 | * |
| 1270 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 1271 | */ |
| 1272 | @Override |
| 1273 | public int getNetworkType() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1274 | return getNetworkTypeUsingSubId(getDefaultSubscription()); |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Returns the network type for a subId |
| 1279 | */ |
| 1280 | @Override |
| 1281 | public int getNetworkTypeUsingSubId(long subId) { |
| 1282 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Returns the data network type |
| 1287 | */ |
| 1288 | @Override |
| 1289 | public int getDataNetworkType() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1290 | return getDataNetworkTypeUsingSubId(getDefaultSubscription()); |
| 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * Returns the data network type for a subId |
| 1295 | */ |
| 1296 | @Override |
| 1297 | public int getDataNetworkTypeUsingSubId(long subId) { |
| 1298 | return getPhone(subId).getServiceState().getDataNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /** |
| 1302 | * Returns the data network type |
| 1303 | */ |
| 1304 | @Override |
| 1305 | public int getVoiceNetworkType() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1306 | return getVoiceNetworkTypeUsingSubId(getDefaultSubscription()); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * Returns the Voice network type for a subId |
| 1311 | */ |
| 1312 | @Override |
| 1313 | public int getVoiceNetworkTypeUsingSubId(long subId) { |
| 1314 | return getPhone(subId).getServiceState().getVoiceNetworkType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /** |
| 1318 | * @return true if a ICC card is present |
| 1319 | */ |
| 1320 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1321 | // FIXME Make changes to pass defaultSimId of type int |
| 1322 | return hasIccCardUsingSlotId(getDefaultSubscription()); |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * @return true if a ICC card is present for a slotId |
| 1327 | */ |
| 1328 | public boolean hasIccCardUsingSlotId(long slotId) { |
| 1329 | return getPhone(slotId).getIccCard().hasIccCard(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * Return if the current radio is LTE on CDMA. This |
| 1334 | * is a tri-state return value as for a period of time |
| 1335 | * the mode may be unknown. |
| 1336 | * |
| 1337 | * @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] | 1338 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | */ |
| 1340 | public int getLteOnCdmaMode() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1341 | return getLteOnCdmaModeUsingSubId(getDefaultSubscription()); |
| 1342 | } |
| 1343 | |
| 1344 | public int getLteOnCdmaModeUsingSubId(long subId) { |
| 1345 | return getPhone(subId).getLteOnCdmaMode(); |
| 1346 | } |
| 1347 | |
| 1348 | public void setPhone(Phone phone) { |
| 1349 | mPhone = phone; |
| 1350 | } |
| 1351 | |
| 1352 | /** |
| 1353 | * {@hide} |
| 1354 | * Returns Default subId, 0 in the case of single standby. |
| 1355 | */ |
| 1356 | private long getDefaultSubscription() { |
| 1357 | return SubscriptionManager.getDefaultSubId(); |
| 1358 | } |
| 1359 | |
| 1360 | private long getPreferredVoiceSubscription() { |
| 1361 | return SubscriptionManager.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1362 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1363 | |
| 1364 | /** |
| 1365 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1366 | */ |
| 1367 | public int getWhenToMakeWifiCalls() { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1368 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 1369 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 1374 | */ |
| 1375 | public void setWhenToMakeWifiCalls(int preference) { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1376 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 1377 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 1378 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 1381 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
| 1382 | // TODO(sail): Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 1383 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 1384 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 1385 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1386 | @Override |
| 1387 | public int iccOpenLogicalChannel(String AID) { |
| 1388 | enforceSimCommunicationPermission(); |
| 1389 | |
| 1390 | if (DBG) log("iccOpenLogicalChannel: " + AID); |
| 1391 | Integer channel = (Integer)sendRequest(CMD_OPEN_CHANNEL, AID); |
| 1392 | if (DBG) log("iccOpenLogicalChannel: " + channel); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1393 | return channel; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | @Override |
| 1397 | public boolean iccCloseLogicalChannel(int channel) { |
| 1398 | enforceSimCommunicationPermission(); |
| 1399 | |
| 1400 | if (DBG) log("iccCloseLogicalChannel: " + channel); |
| 1401 | if (channel < 0) { |
| 1402 | return false; |
| 1403 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1404 | Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 1405 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 1406 | return success; |
| 1407 | } |
| 1408 | |
| 1409 | @Override |
| 1410 | public String iccTransmitApduLogicalChannel(int channel, int cla, |
| 1411 | int command, int p1, int p2, int p3, String data) { |
| 1412 | enforceSimCommunicationPermission(); |
| 1413 | |
| 1414 | if (DBG) { |
| 1415 | log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla + |
| 1416 | " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + |
| 1417 | " data=" + data); |
| 1418 | } |
| 1419 | |
| 1420 | if (channel < 0) { |
| 1421 | return ""; |
| 1422 | } |
| 1423 | |
| 1424 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU, |
| 1425 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data)); |
| 1426 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
| 1427 | |
| 1428 | // If the payload is null, there was an error. Indicate that by returning |
| 1429 | // an empty string. |
| 1430 | if (response.payload == null) { |
| 1431 | return ""; |
| 1432 | } |
| 1433 | |
| 1434 | // Append the returned status code to the end of the response payload. |
| 1435 | String s = Integer.toHexString( |
| 1436 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 1437 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1438 | return s; |
| 1439 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1440 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 1441 | @Override |
| 1442 | public String sendEnvelopeWithStatus(String content) { |
| 1443 | enforceSimCommunicationPermission(); |
| 1444 | |
| 1445 | IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content); |
| 1446 | if (response.payload == null) { |
| 1447 | return ""; |
| 1448 | } |
| 1449 | |
| 1450 | // Append the returned status code to the end of the response payload. |
| 1451 | String s = Integer.toHexString( |
| 1452 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 1453 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 1454 | return s; |
| 1455 | } |
| 1456 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1457 | /** |
| 1458 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1459 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1460 | * |
| 1461 | * @param itemID the ID of the item to read |
| 1462 | * @return the NV item as a String, or null on error. |
| 1463 | */ |
| 1464 | @Override |
| 1465 | public String nvReadItem(int itemID) { |
| 1466 | enforceModifyPermission(); |
| 1467 | if (DBG) log("nvReadItem: item " + itemID); |
| 1468 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); |
| 1469 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 1470 | return value; |
| 1471 | } |
| 1472 | |
| 1473 | /** |
| 1474 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 1475 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 1476 | * |
| 1477 | * @param itemID the ID of the item to read |
| 1478 | * @param itemValue the value to write, as a String |
| 1479 | * @return true on success; false on any failure |
| 1480 | */ |
| 1481 | @Override |
| 1482 | public boolean nvWriteItem(int itemID, String itemValue) { |
| 1483 | enforceModifyPermission(); |
| 1484 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 1485 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| 1486 | new Pair<Integer, String>(itemID, itemValue)); |
| 1487 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 1488 | return success; |
| 1489 | } |
| 1490 | |
| 1491 | /** |
| 1492 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 1493 | * Used for device configuration by some CDMA operators. |
| 1494 | * |
| 1495 | * @param preferredRoamingList byte array containing the new PRL |
| 1496 | * @return true on success; false on any failure |
| 1497 | */ |
| 1498 | @Override |
| 1499 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
| 1500 | enforceModifyPermission(); |
| 1501 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 1502 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 1503 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 1504 | return success; |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * Perform the specified type of NV config reset. |
| 1509 | * Used for device configuration by some CDMA operators. |
| 1510 | * |
| 1511 | * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) |
| 1512 | * @return true on success; false on any failure |
| 1513 | */ |
| 1514 | @Override |
| 1515 | public boolean nvResetConfig(int resetType) { |
| 1516 | enforceModifyPermission(); |
| 1517 | if (DBG) log("nvResetConfig: type " + resetType); |
| 1518 | Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); |
| 1519 | if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); |
| 1520 | return success; |
| 1521 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1522 | |
| 1523 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1524 | * {@hide} |
| 1525 | * Returns Default sim, 0 in the case of single standby. |
| 1526 | */ |
| 1527 | public int getDefaultSim() { |
| 1528 | //TODO Need to get it from Telephony Devcontroller |
| 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | public String[] getPcscfAddress() { |
| 1533 | enforceReadPermission(); |
| 1534 | return mPhone.getPcscfAddress(); |
| 1535 | } |
| 1536 | |
| 1537 | public void setImsRegistrationState(boolean registered) { |
| 1538 | enforceModifyPermission(); |
| 1539 | mPhone.setImsRegistrationState(registered); |
| 1540 | } |
| 1541 | |
| 1542 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1543 | * Get the preferred network type. |
| 1544 | * Used for device configuration by some CDMA operators. |
| 1545 | * |
| 1546 | * @return the preferred network type, defined in RILConstants.java. |
| 1547 | */ |
| 1548 | @Override |
| 1549 | public int getPreferredNetworkType() { |
| 1550 | enforceModifyPermission(); |
| 1551 | if (DBG) log("getPreferredNetworkType"); |
| 1552 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null); |
| 1553 | int networkType = (result != null ? result[0] : -1); |
| 1554 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 1555 | return networkType; |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Set the preferred network type. |
| 1560 | * Used for device configuration by some CDMA operators. |
| 1561 | * |
| 1562 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 1563 | * @return true on success; false on any failure. |
| 1564 | */ |
| 1565 | @Override |
| 1566 | public boolean setPreferredNetworkType(int networkType) { |
| 1567 | enforceModifyPermission(); |
| 1568 | if (DBG) log("setPreferredNetworkType: type " + networkType); |
| 1569 | Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType); |
| 1570 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 1571 | return success; |
| 1572 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1573 | |
| 1574 | /** |
Junda Liu | 787bc7e | 2014-06-30 13:38:02 -0700 | [diff] [blame] | 1575 | * Set the CDMA subscription source. |
| 1576 | * Used for device supporting both NV and RUIM for CDMA. |
| 1577 | * |
| 1578 | * @param subscriptionType the subscription type, 0 for RUIM, 1 for NV. |
| 1579 | * @return true on success; false on any failure. |
| 1580 | */ |
| 1581 | @Override |
| 1582 | public boolean setCdmaSubscription(int subscriptionType) { |
| 1583 | enforceModifyPermission(); |
| 1584 | if (DBG) log("setCdmaSubscription: type " + subscriptionType); |
| 1585 | if (subscriptionType != mPhone.CDMA_SUBSCRIPTION_RUIM_SIM && |
| 1586 | subscriptionType != mPhone.CDMA_SUBSCRIPTION_NV) { |
| 1587 | loge("setCdmaSubscription: unsupported subscriptionType."); |
| 1588 | return false; |
| 1589 | } |
| 1590 | Boolean success = (Boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION, subscriptionType); |
| 1591 | if (DBG) log("setCdmaSubscription: " + (success ? "ok" : "fail")); |
| 1592 | if (success) { |
| 1593 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 1594 | Settings.Global.CDMA_SUBSCRIPTION_MODE, subscriptionType); |
| 1595 | } |
| 1596 | return success; |
| 1597 | } |
| 1598 | |
| 1599 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1600 | * Set mobile data enabled |
| 1601 | * Used by the user through settings etc to turn on/off mobile data |
| 1602 | * |
| 1603 | * @param enable {@code true} turn turn data on, else {@code false} |
| 1604 | */ |
| 1605 | @Override |
| 1606 | public void setDataEnabled(boolean enable) { |
| 1607 | enforceModifyPermission(); |
| 1608 | mPhone.setDataEnabled(enable); |
| 1609 | } |
| 1610 | |
| 1611 | /** |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1612 | * Get whether mobile data is enabled. |
| 1613 | * |
| 1614 | * Note that this used to be available from ConnectivityService, gated by |
| 1615 | * ACCESS_NETWORK_STATE permission, so this will accept either that or |
| 1616 | * our MODIFY_PHONE_STATE. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1617 | * |
| 1618 | * @return {@code true} if data is enabled else {@code false} |
| 1619 | */ |
| 1620 | @Override |
| 1621 | public boolean getDataEnabled() { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 1622 | try { |
| 1623 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 1624 | null); |
| 1625 | } catch (Exception e) { |
| 1626 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, |
| 1627 | null); |
| 1628 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 1629 | return mPhone.getDataEnabled(); |
| 1630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1631 | } |