blob: 2f75089774e33f9eb8a4f7089f28f5e6faf17e84 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
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
17package com.android.phone;
18
19import android.app.ActivityManager;
20import android.app.AppOpsManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070021import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.Context;
23import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070024import android.content.SharedPreferences;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070025import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.net.Uri;
27import android.os.AsyncResult;
28import android.os.Binder;
29import android.os.Bundle;
30import android.os.Handler;
31import android.os.Looper;
32import android.os.Message;
33import android.os.Process;
34import android.os.ServiceManager;
35import android.os.UserHandle;
Derek Tan97ebb422014-09-05 16:55:38 -070036import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080037import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080038import android.telecom.PhoneAccount;
Andrew Lee9431b832015-03-09 18:46:45 -070039import android.telecom.TelecomManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.telephony.CellInfo;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070041import android.telephony.IccOpenLogicalChannelResponse;
Jake Hambye994d462014-02-03 13:10:13 -080042import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070043import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080045import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080046import android.telephony.SubscriptionManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080047import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080049import android.util.ArrayMap;
50import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080052import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080053import android.util.Slog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054
Andrew Lee312e8172014-10-23 17:01:36 -070055import com.android.ims.ImsManager;
Shishir Agrawal566b7612013-10-28 14:41:00 -070056import com.android.internal.telephony.CallManager;
57import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080060import com.android.internal.telephony.IccCard;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.Phone;
Wink Saville36469e72014-06-11 15:17:00 -070062import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import com.android.internal.telephony.ProxyController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.PhoneConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080065import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070066import com.android.internal.telephony.uicc.IccIoResult;
67import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070068import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070069import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080070import com.android.internal.util.HexDump;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071
Wink Saville36469e72014-06-11 15:17:00 -070072import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
73
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import java.util.Arrays;
Shishir Agrawal621a47c2014-12-01 10:25:09 -080076import java.util.HashMap;
77import java.util.Iterator;
Jake Hambye994d462014-02-03 13:10:13 -080078import java.util.List;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import java.util.Map;
80import java.util.Objects;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
82/**
83 * Implementation of the ITelephony interface.
84 */
Santos Cordon117fee72014-05-16 17:56:12 -070085public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086 private static final String LOG_TAG = "PhoneInterfaceManager";
87 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
88 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090
91 // Message codes used with mMainThreadHandler
92 private static final int CMD_HANDLE_PIN_MMI = 1;
93 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
94 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
95 private static final int CMD_ANSWER_RINGING_CALL = 4;
96 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070097 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
98 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099 private static final int CMD_OPEN_CHANNEL = 9;
100 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
101 private static final int CMD_CLOSE_CHANNEL = 11;
102 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800103 private static final int CMD_NV_READ_ITEM = 13;
104 private static final int EVENT_NV_READ_ITEM_DONE = 14;
105 private static final int CMD_NV_WRITE_ITEM = 15;
106 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
107 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
108 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
109 private static final int CMD_NV_RESET_CONFIG = 19;
110 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800111 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
112 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
113 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
114 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800115 private static final int CMD_SEND_ENVELOPE = 25;
116 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700117 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
118 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
119 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
120 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
121 private static final int CMD_EXCHANGE_SIM_IO = 31;
122 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800123 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
124 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125
126 /** The singleton instance. */
127 private static PhoneInterfaceManager sInstance;
128
Wink Saville3ab207e2014-11-20 13:07:20 -0800129 private PhoneGlobals mApp;
130 private Phone mPhone;
131 private CallManager mCM;
132 private AppOpsManager mAppOps;
133 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800134 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800135 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
Derek Tan97ebb422014-09-05 16:55:38 -0700137 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
138 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Andrew Leedf14ead2014-10-17 14:22:52 -0700140 private static final String PREF_ENABLE_VIDEO_CALLING = "enable_video_calling";
Derek Tan89e89d42014-07-08 17:00:10 -0700141
142 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143 * 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 Cordon7d4ddf62013-07-10 11:58:08 -0700162 * 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;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800170 /** The subscriber id that this request applies to. Null if default. */
171 public Integer subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172
173 public MainThreadRequest(Object argument) {
174 this.argument = argument;
175 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800176
177 public MainThreadRequest(Object argument, Integer subId) {
178 this.argument = argument;
179 this.subId = subId;
180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181 }
182
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800183 private static final class IncomingThirdPartyCallArgs {
184 public final ComponentName component;
185 public final String callId;
186 public final String callerDisplayName;
187
188 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
189 String callerDisplayName) {
190 this.component = component;
191 this.callId = callId;
192 this.callerDisplayName = callerDisplayName;
193 }
194 }
195
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 /**
197 * A handler that processes messages on the main thread in the phone process. Since many
198 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
199 * inbound binder threads to the main thread in the phone process. The Binder thread
200 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
201 * on, which will be notified when the operation completes and will contain the result of the
202 * request.
203 *
204 * <p>If a MainThreadRequest object is provided in the msg.obj field,
205 * note that request.result must be set to something non-null for the calling thread to
206 * unblock.
207 */
208 private final class MainThreadHandler extends Handler {
209 @Override
210 public void handleMessage(Message msg) {
211 MainThreadRequest request;
212 Message onCompleted;
213 AsyncResult ar;
Shishir Agrawal21409252015-01-15 23:33:50 -0800214 UiccCard uiccCard = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700215 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217 switch (msg.what) {
218 case CMD_HANDLE_PIN_MMI:
219 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800220 request.result = getPhoneFromRequest(request).handlePinMmi(
221 (String) request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222 // Wake up the requesting thread
223 synchronized (request) {
224 request.notifyAll();
225 }
226 break;
227
228 case CMD_HANDLE_NEIGHBORING_CELL:
229 request = (MainThreadRequest) msg.obj;
230 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
231 request);
232 mPhone.getNeighboringCids(onCompleted);
233 break;
234
235 case EVENT_NEIGHBORING_CELL_DONE:
236 ar = (AsyncResult) msg.obj;
237 request = (MainThreadRequest) ar.userObj;
238 if (ar.exception == null && ar.result != null) {
239 request.result = ar.result;
240 } else {
241 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800242 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 }
244 // Wake up the requesting thread
245 synchronized (request) {
246 request.notifyAll();
247 }
248 break;
249
250 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700251 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800252 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700253 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 break;
255
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 case CMD_END_CALL:
257 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800258 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700259 final boolean hungUp;
260 int phoneType = getPhone(end_subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
262 // CDMA: If the user presses the Power button we treat it as
263 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700264 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
266 // GSM: End the call as per the Phone state
267 hungUp = PhoneUtils.hangup(mCM);
268 } else {
269 throw new IllegalStateException("Unexpected phone type: " + phoneType);
270 }
271 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
272 request.result = hungUp;
273 // Wake up the requesting thread
274 synchronized (request) {
275 request.notifyAll();
276 }
277 break;
278
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700279 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700281 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700282 if (uiccCard == null) {
283 loge("iccTransmitApduLogicalChannel: No UICC");
284 request.result = new IccIoResult(0x6F, 0, (byte[])null);
285 synchronized (request) {
286 request.notifyAll();
287 }
288 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700289 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
290 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700291 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700292 iccArgument.channel, iccArgument.cla, iccArgument.command,
293 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700294 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700295 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700296 break;
297
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700298 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700299 ar = (AsyncResult) msg.obj;
300 request = (MainThreadRequest) ar.userObj;
301 if (ar.exception == null && ar.result != null) {
302 request.result = ar.result;
303 } else {
304 request.result = new IccIoResult(0x6F, 0, (byte[])null);
305 if (ar.result == null) {
306 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800307 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700308 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800309 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 } else {
311 loge("iccTransmitApduLogicalChannel: Unknown exception");
312 }
313 }
314 synchronized (request) {
315 request.notifyAll();
316 }
317 break;
318
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700319 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
320 request = (MainThreadRequest) msg.obj;
321 iccArgument = (IccAPDUArgument) request.argument;
322 if (uiccCard == null) {
323 loge("iccTransmitApduBasicChannel: No UICC");
324 request.result = new IccIoResult(0x6F, 0, (byte[])null);
325 synchronized (request) {
326 request.notifyAll();
327 }
328 } else {
329 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
330 request);
331 uiccCard.iccTransmitApduBasicChannel(
332 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
333 iccArgument.p3, iccArgument.data, onCompleted);
334 }
335 break;
336
337 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
338 ar = (AsyncResult) msg.obj;
339 request = (MainThreadRequest) ar.userObj;
340 if (ar.exception == null && ar.result != null) {
341 request.result = ar.result;
342 } else {
343 request.result = new IccIoResult(0x6F, 0, (byte[])null);
344 if (ar.result == null) {
345 loge("iccTransmitApduBasicChannel: Empty response");
346 } else if (ar.exception instanceof CommandException) {
347 loge("iccTransmitApduBasicChannel: CommandException: " +
348 ar.exception);
349 } else {
350 loge("iccTransmitApduBasicChannel: Unknown exception");
351 }
352 }
353 synchronized (request) {
354 request.notifyAll();
355 }
356 break;
357
358 case CMD_EXCHANGE_SIM_IO:
359 request = (MainThreadRequest) msg.obj;
360 iccArgument = (IccAPDUArgument) request.argument;
361 if (uiccCard == null) {
362 loge("iccExchangeSimIO: No UICC");
363 request.result = new IccIoResult(0x6F, 0, (byte[])null);
364 synchronized (request) {
365 request.notifyAll();
366 }
367 } else {
368 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
369 request);
370 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
371 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
372 iccArgument.data, onCompleted);
373 }
374 break;
375
376 case EVENT_EXCHANGE_SIM_IO_DONE:
377 ar = (AsyncResult) msg.obj;
378 request = (MainThreadRequest) ar.userObj;
379 if (ar.exception == null && ar.result != null) {
380 request.result = ar.result;
381 } else {
382 request.result = new IccIoResult(0x6f, 0, (byte[])null);
383 }
384 synchronized (request) {
385 request.notifyAll();
386 }
387 break;
388
Derek Tan4d5e5c12014-02-04 11:54:58 -0800389 case CMD_SEND_ENVELOPE:
390 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700391 if (uiccCard == null) {
392 loge("sendEnvelopeWithStatus: No UICC");
393 request.result = new IccIoResult(0x6F, 0, (byte[])null);
394 synchronized (request) {
395 request.notifyAll();
396 }
397 } else {
398 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
399 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
400 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800401 break;
402
403 case EVENT_SEND_ENVELOPE_DONE:
404 ar = (AsyncResult) msg.obj;
405 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700406 if (ar.exception == null && ar.result != null) {
407 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800408 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700409 request.result = new IccIoResult(0x6F, 0, (byte[])null);
410 if (ar.result == null) {
411 loge("sendEnvelopeWithStatus: Empty response");
412 } else if (ar.exception instanceof CommandException) {
413 loge("sendEnvelopeWithStatus: CommandException: " +
414 ar.exception);
415 } else {
416 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
417 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800418 }
419 synchronized (request) {
420 request.notifyAll();
421 }
422 break;
423
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 case CMD_OPEN_CHANNEL:
425 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 if (uiccCard == null) {
427 loge("iccOpenLogicalChannel: No UICC");
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 synchronized (request) {
430 request.notifyAll();
431 }
432 } else {
433 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
434 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
435 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 break;
437
438 case EVENT_OPEN_CHANNEL_DONE:
439 ar = (AsyncResult) msg.obj;
440 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 int[] result = (int[]) ar.result;
444 int channelId = result[0];
445 byte[] selectResponse = null;
446 if (result.length > 1) {
447 selectResponse = new byte[result.length - 1];
448 for (int i = 1; i < result.length; ++i) {
449 selectResponse[i - 1] = (byte) result[i];
450 }
451 }
452 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700453 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 if (ar.result == null) {
456 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 if (ar.exception != null) {
459 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
460 }
461
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700462 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 if ((ar.exception != null) && (ar.exception instanceof CommandException)) {
464 if (ar.exception.getMessage().compareTo("MISSING_RESOURCE") == 0) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700465 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 } else if (ar.exception.getMessage().compareTo("NO_SUCH_ELEMENT") == 0) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700467 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 }
469 }
470 openChannelResp = new IccOpenLogicalChannelResponse(
471 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700473 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 synchronized (request) {
475 request.notifyAll();
476 }
477 break;
478
479 case CMD_CLOSE_CHANNEL:
480 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700481 if (uiccCard == null) {
482 loge("iccCloseLogicalChannel: No UICC");
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 synchronized (request) {
485 request.notifyAll();
486 }
487 } else {
488 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
489 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 break;
492
493 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800494 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
495 break;
496
497 case CMD_NV_READ_ITEM:
498 request = (MainThreadRequest) msg.obj;
499 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
500 mPhone.nvReadItem((Integer) request.argument, onCompleted);
501 break;
502
503 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800509 request.result = "";
510 if (ar.result == null) {
511 loge("nvReadItem: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("nvReadItem: CommandException: " +
514 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800516 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 }
518 }
519 synchronized (request) {
520 request.notifyAll();
521 }
522 break;
523
Jake Hambye994d462014-02-03 13:10:13 -0800524 case CMD_NV_WRITE_ITEM:
525 request = (MainThreadRequest) msg.obj;
526 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
527 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
528 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
529 break;
530
531 case EVENT_NV_WRITE_ITEM_DONE:
532 handleNullReturnEvent(msg, "nvWriteItem");
533 break;
534
535 case CMD_NV_WRITE_CDMA_PRL:
536 request = (MainThreadRequest) msg.obj;
537 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
538 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
539 break;
540
541 case EVENT_NV_WRITE_CDMA_PRL_DONE:
542 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
543 break;
544
545 case CMD_NV_RESET_CONFIG:
546 request = (MainThreadRequest) msg.obj;
547 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
548 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
549 break;
550
551 case EVENT_NV_RESET_CONFIG_DONE:
552 handleNullReturnEvent(msg, "nvResetConfig");
553 break;
554
Jake Hamby7c27be32014-03-03 13:25:59 -0800555 case CMD_GET_PREFERRED_NETWORK_TYPE:
556 request = (MainThreadRequest) msg.obj;
557 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
558 mPhone.getPreferredNetworkType(onCompleted);
559 break;
560
561 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
562 ar = (AsyncResult) msg.obj;
563 request = (MainThreadRequest) ar.userObj;
564 if (ar.exception == null && ar.result != null) {
565 request.result = ar.result; // Integer
566 } else {
567 request.result = -1;
568 if (ar.result == null) {
569 loge("getPreferredNetworkType: Empty response");
570 } else if (ar.exception instanceof CommandException) {
571 loge("getPreferredNetworkType: CommandException: " +
572 ar.exception);
573 } else {
574 loge("getPreferredNetworkType: Unknown exception");
575 }
576 }
577 synchronized (request) {
578 request.notifyAll();
579 }
580 break;
581
582 case CMD_SET_PREFERRED_NETWORK_TYPE:
583 request = (MainThreadRequest) msg.obj;
584 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
585 int networkType = (Integer) request.argument;
586 mPhone.setPreferredNetworkType(networkType, onCompleted);
587 break;
588
589 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
590 handleNullReturnEvent(msg, "setPreferredNetworkType");
591 break;
592
Steven Liu4bf01bc2014-07-17 11:05:29 -0500593 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
594 request = (MainThreadRequest)msg.obj;
595 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
596 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
597 break;
598
599 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
600 ar = (AsyncResult)msg.obj;
601 request = (MainThreadRequest)ar.userObj;
602 request.result = ar;
603 synchronized (request) {
604 request.notifyAll();
605 }
606 break;
607
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800608 case CMD_SET_VOICEMAIL_NUMBER:
609 request = (MainThreadRequest) msg.obj;
610 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
611 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800612 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
613 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800614 break;
615
616 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
617 handleNullReturnEvent(msg, "setVoicemailNumber");
618 break;
619
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620 default:
621 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
622 break;
623 }
624 }
Jake Hambye994d462014-02-03 13:10:13 -0800625
626 private void handleNullReturnEvent(Message msg, String command) {
627 AsyncResult ar = (AsyncResult) msg.obj;
628 MainThreadRequest request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null) {
630 request.result = true;
631 } else {
632 request.result = false;
633 if (ar.exception instanceof CommandException) {
634 loge(command + ": CommandException: " + ar.exception);
635 } else {
636 loge(command + ": Unknown exception");
637 }
638 }
639 synchronized (request) {
640 request.notifyAll();
641 }
642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700643 }
644
645 /**
646 * Posts the specified command to be executed on the main thread,
647 * waits for the request to complete, and returns the result.
648 * @see #sendRequestAsync
649 */
650 private Object sendRequest(int command, Object argument) {
Santos Cordon500b0e02014-06-17 10:33:33 -0700651 return sendRequest(command, argument, null);
Wink Saville36469e72014-06-11 15:17:00 -0700652 }
653
654 /**
655 * Posts the specified command to be executed on the main thread,
656 * waits for the request to complete, and returns the result.
657 * @see #sendRequestAsync
658 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800659 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700660 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
661 throw new RuntimeException("This method will deadlock if called from the main thread.");
662 }
663
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800664 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700665 Message msg = mMainThreadHandler.obtainMessage(command, request);
666 msg.sendToTarget();
667
668 // Wait for the request to complete
669 synchronized (request) {
670 while (request.result == null) {
671 try {
672 request.wait();
673 } catch (InterruptedException e) {
674 // Do nothing, go back and wait until the request is complete
675 }
676 }
677 }
678 return request.result;
679 }
680
681 /**
682 * Asynchronous ("fire and forget") version of sendRequest():
683 * Posts the specified command to be executed on the main thread, and
684 * returns immediately.
685 * @see #sendRequest
686 */
687 private void sendRequestAsync(int command) {
688 mMainThreadHandler.sendEmptyMessage(command);
689 }
690
691 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700692 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
693 * @see {@link #sendRequest(int,Object)}
694 */
695 private void sendRequestAsync(int command, Object argument) {
696 MainThreadRequest request = new MainThreadRequest(argument);
697 Message msg = mMainThreadHandler.obtainMessage(command, request);
698 msg.sendToTarget();
699 }
700
701 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 * Initialize the singleton PhoneInterfaceManager instance.
703 * This is only done once, at startup, from PhoneApp.onCreate().
704 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700705 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 synchronized (PhoneInterfaceManager.class) {
707 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700708 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700709 } else {
710 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
711 }
712 return sInstance;
713 }
714 }
715
716 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700717 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700718 mApp = app;
719 mPhone = phone;
720 mCM = PhoneGlobals.getInstance().mCM;
721 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
722 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700723 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700724 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800725 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800726
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700727 publish();
728 }
729
730 private void publish() {
731 if (DBG) log("publish: " + this);
732
733 ServiceManager.addService("phone", this);
734 }
735
Stuart Scott584921c2015-01-15 17:10:34 -0800736 private Phone getPhoneFromRequest(MainThreadRequest request) {
737 return (request.subId == null) ? mPhone : getPhone(request.subId);
738 }
739
Wink Saville36469e72014-06-11 15:17:00 -0700740 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700741 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800742 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700744 //
745 // Implementation of the ITelephony interface.
746 //
747
748 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700749 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700750 }
751
Wink Savilleb564aae2014-10-23 10:18:09 -0700752 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700753 if (DBG) log("dial: " + number);
754 // No permission check needed here: This is just a wrapper around the
755 // ACTION_DIAL intent, which is available to any app since it puts up
756 // the UI before it does anything.
757
758 String url = createTelUrl(number);
759 if (url == null) {
760 return;
761 }
762
763 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -0700764 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700765 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
766 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
767 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
768 mApp.startActivity(intent);
769 }
770 }
771
772 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700773 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -0700774 }
775
Wink Savilleb564aae2014-10-23 10:18:09 -0700776 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700777 if (DBG) log("call: " + number);
778
779 // This is just a wrapper around the ACTION_CALL intent, but we still
780 // need to do a permission check since we're calling startActivity()
781 // from the context of the phone app.
782 enforceCallPermission();
783
784 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
785 != AppOpsManager.MODE_ALLOWED) {
786 return;
787 }
788
789 String url = createTelUrl(number);
790 if (url == null) {
791 return;
792 }
793
Wink Saville08874612014-08-31 19:19:58 -0700794 boolean isValid = false;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800795 List<SubscriptionInfo> slist = mSubscriptionController.getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -0800796 if (slist != null) {
797 for (SubscriptionInfo subInfoRecord : slist) {
798 if (subInfoRecord.getSubscriptionId() == subId) {
799 isValid = true;
800 break;
801 }
Wink Saville08874612014-08-31 19:19:58 -0700802 }
803 }
804 if (isValid == false) {
805 return;
806 }
807
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700808 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -0700809 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700810 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
811 mApp.startActivity(intent);
812 }
813
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700814 /**
815 * End a call based on call state
816 * @return true is a call was ended
817 */
818 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700819 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700820 }
821
822 /**
823 * End a call based on the call state of the subId
824 * @return true is a call was ended
825 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700826 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700827 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800828 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700829 }
830
831 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700832 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700833 }
834
Wink Savilleb564aae2014-10-23 10:18:09 -0700835 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700836 if (DBG) log("answerRingingCall...");
837 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
838 // but that can probably wait till the big TelephonyManager API overhaul.
839 // For now, protect this call with the MODIFY_PHONE_STATE permission.
840 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800841 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700842 }
843
844 /**
845 * Make the actual telephony calls to implement answerRingingCall().
846 * This should only be called from the main thread of the Phone app.
847 * @see #answerRingingCall
848 *
849 * TODO: it would be nice to return true if we answered the call, or
850 * false if there wasn't actually a ringing incoming call, or some
851 * other error occurred. (In other words, pass back the return value
852 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
853 * But that would require calling this method via sendRequest() rather
854 * than sendRequestAsync(), and right now we don't actually *need* that
855 * return value, so let's just return void for now.
856 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700857 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -0700858 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700859 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -0700860 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
861 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700862 if (hasActiveCall && hasHoldingCall) {
863 // Both lines are in use!
864 // TODO: provide a flag to let the caller specify what
865 // policy to use if both lines are in use. (The current
866 // behavior is hardwired to "answer incoming, end ongoing",
867 // which is how the CALL button is specced to behave.)
868 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
869 return;
870 } else {
871 // answerCall() will automatically hold the current active
872 // call, if there is one.
873 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
874 return;
875 }
876 } else {
877 // No call was ringing.
878 return;
879 }
880 }
881
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700882 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -0700883 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700884 */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700885 public void silenceRinger() {
886 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700887 }
888
889 public boolean isOffhook() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700890 return isOffhookForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700891 }
892
Wink Savilleb564aae2014-10-23 10:18:09 -0700893 public boolean isOffhookForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700894 return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895 }
896
897 public boolean isRinging() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700898 return (isRingingForSubscriber(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -0700899 }
900
Wink Savilleb564aae2014-10-23 10:18:09 -0700901 public boolean isRingingForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700902 return (getPhone(subId).getState() == PhoneConstants.State.RINGING);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 }
904
905 public boolean isIdle() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700906 return isIdleForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700907 }
908
Wink Savilleb564aae2014-10-23 10:18:09 -0700909 public boolean isIdleForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700910 return (getPhone(subId).getState() == PhoneConstants.State.IDLE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700911 }
912
913 public boolean isSimPinEnabled() {
914 enforceReadPermission();
915 return (PhoneGlobals.getInstance().isSimPinEnabled());
916 }
917
918 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700919 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700920 }
921
Wink Savilleb564aae2014-10-23 10:18:09 -0700922 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700923 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700924 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
925 }
926
927 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700928 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700929 }
930
Wink Savilleb564aae2014-10-23 10:18:09 -0700931 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700932 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700933 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
934 }
935
936 /** {@hide} */
937 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700938 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700939 }
940
Wink Savilleb564aae2014-10-23 10:18:09 -0700941 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700943 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700944 checkSimPin.start();
945 return checkSimPin.unlockSim(null, pin);
946 }
947
Wink Saville9de0f752013-10-22 19:04:03 -0700948 /** {@hide} */
949 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700950 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700951 }
952
Wink Savilleb564aae2014-10-23 10:18:09 -0700953 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700954 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700955 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700956 checkSimPuk.start();
957 return checkSimPuk.unlockSim(puk, pin);
958 }
959
960 /**
Wink Saville9de0f752013-10-22 19:04:03 -0700961 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700962 * a synchronous one.
963 */
964 private static class UnlockSim extends Thread {
965
966 private final IccCard mSimCard;
967
968 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -0700969 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
970 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700971
972 // For replies from SimCard interface
973 private Handler mHandler;
974
975 // For async handler to identify request type
976 private static final int SUPPLY_PIN_COMPLETE = 100;
977
978 public UnlockSim(IccCard simCard) {
979 mSimCard = simCard;
980 }
981
982 @Override
983 public void run() {
984 Looper.prepare();
985 synchronized (UnlockSim.this) {
986 mHandler = new Handler() {
987 @Override
988 public void handleMessage(Message msg) {
989 AsyncResult ar = (AsyncResult) msg.obj;
990 switch (msg.what) {
991 case SUPPLY_PIN_COMPLETE:
992 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
993 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -0700994 mRetryCount = msg.arg1;
995 if (ar.exception != null) {
996 if (ar.exception instanceof CommandException &&
997 ((CommandException)(ar.exception)).getCommandError()
998 == CommandException.Error.PASSWORD_INCORRECT) {
999 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1000 } else {
1001 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1002 }
1003 } else {
1004 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001006 mDone = true;
1007 UnlockSim.this.notifyAll();
1008 }
1009 break;
1010 }
1011 }
1012 };
1013 UnlockSim.this.notifyAll();
1014 }
1015 Looper.loop();
1016 }
1017
1018 /*
1019 * Use PIN or PUK to unlock SIM card
1020 *
1021 * If PUK is null, unlock SIM card with PIN
1022 *
1023 * If PUK is not null, unlock SIM card with PUK and set PIN code
1024 */
Wink Saville9de0f752013-10-22 19:04:03 -07001025 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026
1027 while (mHandler == null) {
1028 try {
1029 wait();
1030 } catch (InterruptedException e) {
1031 Thread.currentThread().interrupt();
1032 }
1033 }
1034 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1035
1036 if (puk == null) {
1037 mSimCard.supplyPin(pin, callback);
1038 } else {
1039 mSimCard.supplyPuk(puk, pin, callback);
1040 }
1041
1042 while (!mDone) {
1043 try {
1044 Log.d(LOG_TAG, "wait for done");
1045 wait();
1046 } catch (InterruptedException e) {
1047 // Restore the interrupted status
1048 Thread.currentThread().interrupt();
1049 }
1050 }
1051 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001052 int[] resultArray = new int[2];
1053 resultArray[0] = mResult;
1054 resultArray[1] = mRetryCount;
1055 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 }
1057 }
1058
1059 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001060 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001061
1062 }
1063
Wink Savilleb564aae2014-10-23 10:18:09 -07001064 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 // No permission check needed here: this call is harmless, and it's
1066 // needed for the ServiceState.requestStateUpdate() call (which is
1067 // already intentionally exposed to 3rd parties.)
Wink Saville36469e72014-06-11 15:17:00 -07001068 getPhone(subId).updateServiceLocation();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001069 }
1070
1071 public boolean isRadioOn() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001072 return isRadioOnForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001073 }
1074
Wink Savilleb564aae2014-10-23 10:18:09 -07001075 public boolean isRadioOnForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001076 return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 }
1078
1079 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001080 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 }
Wink Saville36469e72014-06-11 15:17:00 -07001083
Wink Savilleb564aae2014-10-23 10:18:09 -07001084 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 enforceModifyPermission();
Wink Savilleadd7cc52014-09-08 14:23:09 -07001086 getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001087 }
1088
1089 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001090 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001091 }
1092
Wink Savilleb564aae2014-10-23 10:18:09 -07001093 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001094 enforceModifyPermission();
1095 if ((getPhone(subId).getServiceState().getState() !=
1096 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001097 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 }
1099 return true;
1100 }
Wink Saville36469e72014-06-11 15:17:00 -07001101
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001102 public boolean needMobileRadioShutdown() {
1103 /*
1104 * If any of the Radios are available, it will need to be
1105 * shutdown. So return true if any Radio is available.
1106 */
1107 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1108 Phone phone = PhoneFactory.getPhone(i);
1109 if (phone != null && phone.isRadioAvailable()) return true;
1110 }
1111 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1112 return false;
1113 }
1114
1115 public void shutdownMobileRadios() {
1116 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1117 logv("Shutting down Phone " + i);
1118 shutdownRadioUsingPhoneId(i);
1119 }
1120 }
1121
1122 private void shutdownRadioUsingPhoneId(int phoneId) {
1123 enforceModifyPermission();
1124 Phone phone = PhoneFactory.getPhone(phoneId);
1125 if (phone != null && phone.isRadioAvailable()) {
1126 phone.shutdownRadio();
1127 }
1128 }
1129
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 public boolean setRadioPower(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001131 return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
1133
Wink Savilleb564aae2014-10-23 10:18:09 -07001134 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001136 getPhone(subId).setRadioPower(turnOn);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 return true;
1138 }
1139
Wink Saville36469e72014-06-11 15:17:00 -07001140 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 public boolean enableDataConnectivity() {
1142 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001143 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001144 getPhone(subId).setDataEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001145 return true;
1146 }
1147
Wink Saville36469e72014-06-11 15:17:00 -07001148 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 public boolean disableDataConnectivity() {
1150 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001151 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001152 getPhone(subId).setDataEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 return true;
1154 }
1155
Wink Saville36469e72014-06-11 15:17:00 -07001156 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001158 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001159 return getPhone(subId).isDataConnectivityPossible();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 }
1161
1162 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001163 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001164 }
1165
Wink Savilleb564aae2014-10-23 10:18:09 -07001166 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001168 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 }
1170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 public int getCallState() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001172 return getCallStateForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001173 }
1174
Wink Savilleb564aae2014-10-23 10:18:09 -07001175 public int getCallStateForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001176 return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 }
1178
1179 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001180 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001181 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 }
1183
1184 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001185 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001186 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 }
1188
1189 @Override
1190 public Bundle getCellLocation() {
1191 try {
1192 mApp.enforceCallingOrSelfPermission(
1193 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1194 } catch (SecurityException e) {
1195 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1196 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1197 // is the weaker precondition
1198 mApp.enforceCallingOrSelfPermission(
1199 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1200 }
1201
Jake Hambye994d462014-02-03 13:10:13 -08001202 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 if (DBG_LOC) log("getCellLocation: is active user");
1204 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001205 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1206 phone.getCellLocation().fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 return data;
1208 } else {
1209 if (DBG_LOC) log("getCellLocation: suppress non-active user");
1210 return null;
1211 }
1212 }
1213
1214 @Override
1215 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001216 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001217 }
1218
Wink Savilleb564aae2014-10-23 10:18:09 -07001219 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 mApp.enforceCallingOrSelfPermission(
1221 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001222 getPhone(subId).enableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 }
1224
1225 @Override
1226 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001227 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001228 }
1229
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 mApp.enforceCallingOrSelfPermission(
1232 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001233 getPhone(subId).disableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 }
1235
1236 @Override
1237 @SuppressWarnings("unchecked")
1238 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1239 try {
1240 mApp.enforceCallingOrSelfPermission(
1241 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1242 } catch (SecurityException e) {
1243 // If we have ACCESS_FINE_LOCATION permission, skip the check
1244 // for ACCESS_COARSE_LOCATION
1245 // A failure should throw the SecurityException from
1246 // ACCESS_COARSE_LOCATION since this is the weaker precondition
1247 mApp.enforceCallingOrSelfPermission(
1248 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1249 }
1250
1251 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1252 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1253 return null;
1254 }
Jake Hambye994d462014-02-03 13:10:13 -08001255 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1257
1258 ArrayList<NeighboringCellInfo> cells = null;
1259
1260 try {
1261 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Wink Saville36469e72014-06-11 15:17:00 -07001262 CMD_HANDLE_NEIGHBORING_CELL, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001264 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 }
1266 return cells;
1267 } else {
1268 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1269 return null;
1270 }
1271 }
1272
1273
1274 @Override
1275 public List<CellInfo> getAllCellInfo() {
1276 try {
1277 mApp.enforceCallingOrSelfPermission(
1278 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1279 } catch (SecurityException e) {
1280 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1281 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1282 // is the weaker precondition
1283 mApp.enforceCallingOrSelfPermission(
1284 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1285 }
1286
Jake Hambye994d462014-02-03 13:10:13 -08001287 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 if (DBG_LOC) log("getAllCellInfo: is active user");
Legler Wu2c01cdf2014-12-08 19:00:59 +08001289 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1290 for (Phone phone : PhoneFactory.getPhones()) {
1291 cellInfos.addAll(phone.getAllCellInfo());
1292 }
1293 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 } else {
1295 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1296 return null;
1297 }
1298 }
1299
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001300 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 public void setCellInfoListRate(int rateInMillis) {
1302 mPhone.setCellInfoListRate(rateInMillis);
1303 }
1304
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 //
1306 // Internal helper methods.
1307 //
1308
Jake Hambye994d462014-02-03 13:10:13 -08001309 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 boolean ok;
1311
1312 boolean self = Binder.getCallingUid() == Process.myUid();
1313 if (!self) {
1314 // Get the caller's user id then clear the calling identity
1315 // which will be restored in the finally clause.
1316 int callingUser = UserHandle.getCallingUserId();
1317 long ident = Binder.clearCallingIdentity();
1318
1319 try {
1320 // With calling identity cleared the current user is the foreground user.
1321 int foregroundUser = ActivityManager.getCurrentUser();
1322 ok = (foregroundUser == callingUser);
1323 if (DBG_LOC) {
1324 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1325 + " callingUser=" + callingUser + " ok=" + ok);
1326 }
1327 } catch (Exception ex) {
1328 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1329 ok = false;
1330 } finally {
1331 Binder.restoreCallingIdentity(ident);
1332 }
1333 } else {
1334 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1335 ok = true;
1336 }
1337 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1338 return ok;
1339 }
1340
1341 /**
1342 * Make sure the caller has the READ_PHONE_STATE permission.
1343 *
1344 * @throws SecurityException if the caller does not have the required permission
1345 */
1346 private void enforceReadPermission() {
1347 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
1348 }
1349
1350 /**
1351 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1352 *
1353 * @throws SecurityException if the caller does not have the required permission
1354 */
1355 private void enforceModifyPermission() {
1356 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1357 }
1358
1359 /**
Junda Liua2e36012014-07-09 18:30:01 -07001360 * Make sure either system app or the caller has carrier privilege.
1361 *
1362 * @throws SecurityException if the caller does not have the required permission/privilege
1363 */
1364 private void enforceModifyPermissionOrCarrierPrivilege() {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001365 int permission = mApp.checkCallingOrSelfPermission(
1366 android.Manifest.permission.MODIFY_PHONE_STATE);
1367 if (permission == PackageManager.PERMISSION_GRANTED) {
1368 return;
1369 }
1370
1371 log("No modify permission, check carrier privilege next.");
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001372 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001373 loge("No Carrier Privilege.");
1374 throw new SecurityException("No modify permission or carrier privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001375 }
1376 }
1377
1378 /**
1379 * Make sure the caller has carrier privilege.
1380 *
1381 * @throws SecurityException if the caller does not have the required permission
1382 */
1383 private void enforceCarrierPrivilege() {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001384 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001385 loge("No Carrier Privilege.");
1386 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001387 }
1388 }
1389
1390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 * Make sure the caller has the CALL_PHONE permission.
1392 *
1393 * @throws SecurityException if the caller does not have the required permission
1394 */
1395 private void enforceCallPermission() {
1396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1397 }
1398
Shishir Agrawal566b7612013-10-28 14:41:00 -07001399 /**
Gabriel Peal36ebb0d2014-03-20 09:20:43 -07001400 * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission.
1401 *
1402 * @throws SecurityException if the caller does not have the required permission
1403 */
1404 private void enforcePrivilegedPhoneStatePermission() {
1405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1406 null);
1407 }
1408
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 private String createTelUrl(String number) {
1410 if (TextUtils.isEmpty(number)) {
1411 return null;
1412 }
1413
Jake Hambye994d462014-02-03 13:10:13 -08001414 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 }
1416
Ihab Awadf9e92732013-12-05 18:02:52 -08001417 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1419 }
1420
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001421 private static void logv(String msg) {
1422 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1423 }
1424
Ihab Awadf9e92732013-12-05 18:02:52 -08001425 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1427 }
1428
1429 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001430 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001431 }
1432
Wink Savilleb564aae2014-10-23 10:18:09 -07001433 public int getActivePhoneTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001434 return getPhone(subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435 }
1436
1437 /**
1438 * Returns the CDMA ERI icon index to display
1439 */
1440 public int getCdmaEriIconIndex() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001441 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001442
1443 }
1444
Wink Savilleb564aae2014-10-23 10:18:09 -07001445 public int getCdmaEriIconIndexForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001446 return getPhone(subId).getCdmaEriIconIndex();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
1449 /**
1450 * Returns the CDMA ERI icon mode,
1451 * 0 - ON
1452 * 1 - FLASHING
1453 */
1454 public int getCdmaEriIconMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public int getCdmaEriIconModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001459 return getPhone(subId).getCdmaEriIconMode();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461
1462 /**
1463 * Returns the CDMA ERI text,
1464 */
1465 public String getCdmaEriText() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 return getCdmaEriTextForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001467 }
1468
Wink Savilleb564aae2014-10-23 10:18:09 -07001469 public String getCdmaEriTextForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001470 return getPhone(subId).getCdmaEriText();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 }
1472
1473 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001474 * Returns the CDMA MDN.
1475 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public String getCdmaMdn(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001477 enforceModifyPermissionOrCarrierPrivilege();
1478 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1479 return getPhone(subId).getLine1Number();
1480 } else {
1481 return null;
1482 }
1483 }
1484
1485 /**
1486 * Returns the CDMA MIN.
1487 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public String getCdmaMin(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001489 enforceModifyPermissionOrCarrierPrivilege();
1490 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1491 return getPhone(subId).getCdmaMin();
1492 } else {
1493 return null;
1494 }
1495 }
1496
1497 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 * Returns true if CDMA provisioning needs to run.
1499 */
1500 public boolean needsOtaServiceProvisioning() {
1501 return mPhone.needsOtaServiceProvisioning();
1502 }
1503
1504 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001505 * Sets the voice mail number of a given subId.
1506 */
1507 @Override
1508 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001509 enforceCarrierPrivilege();
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001510 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1511 new Pair<String, String>(alphaTag, number), new Integer(subId));
1512 return success;
1513 }
1514
1515 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 * Returns the unread count of voicemails
1517 */
1518 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001519 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001520 }
1521
1522 /**
1523 * Returns the unread count of voicemails for a subId
1524 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public int getVoiceMessageCountForSubscriber( int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001526 return getPhone(subId).getVoiceMessageCount();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528
1529 /**
1530 * Returns the data network type
1531 *
1532 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1533 */
1534 @Override
1535 public int getNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return getNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
1539 /**
1540 * Returns the network type for a subId
1541 */
1542 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int getNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001544 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
1546
1547 /**
1548 * Returns the data network type
1549 */
1550 @Override
1551 public int getDataNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001552 return getDataNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
1555 /**
1556 * Returns the data network type for a subId
1557 */
1558 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001559 public int getDataNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001560 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 }
1562
1563 /**
1564 * Returns the data network type
1565 */
1566 @Override
1567 public int getVoiceNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 return getVoiceNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
1571 /**
1572 * Returns the Voice network type for a subId
1573 */
1574 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001575 public int getVoiceNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001576 return getPhone(subId).getServiceState().getVoiceNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
1579 /**
1580 * @return true if a ICC card is present
1581 */
1582 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001583 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001584 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
1587 /**
1588 * @return true if a ICC card is present for a slotId
1589 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001590 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001591 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
1592 if (subId != null) {
1593 return getPhone(subId[0]).getIccCard().hasIccCard();
1594 } else {
1595 return false;
1596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598
1599 /**
1600 * Return if the current radio is LTE on CDMA. This
1601 * is a tri-state return value as for a period of time
1602 * the mode may be unknown.
1603 *
1604 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001605 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 */
1607 public int getLteOnCdmaMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001608 return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001609 }
1610
Wink Savilleb564aae2014-10-23 10:18:09 -07001611 public int getLteOnCdmaModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001612 return getPhone(subId).getLteOnCdmaMode();
1613 }
1614
1615 public void setPhone(Phone phone) {
1616 mPhone = phone;
1617 }
1618
1619 /**
1620 * {@hide}
1621 * Returns Default subId, 0 in the case of single standby.
1622 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001624 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Wink Savilleb564aae2014-10-23 10:18:09 -07001627 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001628 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001630
1631 /**
1632 * @see android.telephony.TelephonyManager.WifiCallingChoices
1633 */
1634 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001635 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1636 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001637 }
1638
1639 /**
1640 * @see android.telephony.TelephonyManager.WifiCallingChoices
1641 */
1642 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001643 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1644 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1645 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001646 }
1647
Sailesh Nepald1e68152013-12-12 19:08:02 -08001648 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001649 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001650 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001651 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001652
Shishir Agrawal566b7612013-10-28 14:41:00 -07001653 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001654 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
Junda Liua2e36012014-07-09 18:30:01 -07001655 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001656
1657 if (DBG) log("iccOpenLogicalChannel: " + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001658 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
1659 CMD_OPEN_CHANNEL, AID);
1660 if (DBG) log("iccOpenLogicalChannel: " + response);
1661 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001662 }
1663
1664 @Override
1665 public boolean iccCloseLogicalChannel(int channel) {
Junda Liua2e36012014-07-09 18:30:01 -07001666 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001667
1668 if (DBG) log("iccCloseLogicalChannel: " + channel);
1669 if (channel < 0) {
1670 return false;
1671 }
Jake Hambye994d462014-02-03 13:10:13 -08001672 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001673 if (DBG) log("iccCloseLogicalChannel: " + success);
1674 return success;
1675 }
1676
1677 @Override
1678 public String iccTransmitApduLogicalChannel(int channel, int cla,
1679 int command, int p1, int p2, int p3, String data) {
Junda Liua2e36012014-07-09 18:30:01 -07001680 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001681
1682 if (DBG) {
1683 log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla +
1684 " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
1685 " data=" + data);
1686 }
1687
1688 if (channel < 0) {
1689 return "";
1690 }
1691
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001692 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawal566b7612013-10-28 14:41:00 -07001693 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data));
1694 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
1695
Shishir Agrawal566b7612013-10-28 14:41:00 -07001696 // Append the returned status code to the end of the response payload.
1697 String s = Integer.toHexString(
1698 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001699 if (response.payload != null) {
1700 s = IccUtils.bytesToHexString(response.payload) + s;
1701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001702 return s;
1703 }
Jake Hambye994d462014-02-03 13:10:13 -08001704
Evan Charltonc66da362014-05-16 14:06:40 -07001705 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001706 public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2,
1707 int p3, String data) {
1708 enforceModifyPermissionOrCarrierPrivilege();
1709
1710 if (DBG) {
1711 log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1="
1712 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
1713 }
1714
1715 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
1716 new IccAPDUArgument(0, cla, command, p1, p2, p3, data));
1717 if (DBG) log("iccTransmitApduBasicChannel: " + response);
1718
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001719 // Append the returned status code to the end of the response payload.
1720 String s = Integer.toHexString(
1721 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001722 if (response.payload != null) {
1723 s = IccUtils.bytesToHexString(response.payload) + s;
1724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001725 return s;
1726 }
1727
1728 @Override
1729 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
1730 String filePath) {
1731 enforceModifyPermissionOrCarrierPrivilege();
1732
1733 if (DBG) {
1734 log("Exchange SIM_IO " + fileID + ":" + command + " " +
1735 p1 + " " + p2 + " " + p3 + ":" + filePath);
1736 }
1737
1738 IccIoResult response =
1739 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Yong Jiang3edf3782014-10-03 13:23:28 -05001740 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath));
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001741
1742 if (DBG) {
1743 log("Exchange SIM_IO [R]" + response);
1744 }
1745
1746 byte[] result = null;
1747 int length = 2;
1748 if (response.payload != null) {
1749 length = 2 + response.payload.length;
1750 result = new byte[length];
1751 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
1752 } else {
1753 result = new byte[length];
1754 }
1755
1756 result[length - 1] = (byte) response.sw2;
1757 result[length - 2] = (byte) response.sw1;
1758 return result;
1759 }
1760
1761 @Override
Evan Charltonc66da362014-05-16 14:06:40 -07001762 public String sendEnvelopeWithStatus(String content) {
Junda Liua2e36012014-07-09 18:30:01 -07001763 enforceModifyPermissionOrCarrierPrivilege();
Evan Charltonc66da362014-05-16 14:06:40 -07001764
1765 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content);
1766 if (response.payload == null) {
1767 return "";
1768 }
1769
1770 // Append the returned status code to the end of the response payload.
1771 String s = Integer.toHexString(
1772 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
1773 s = IccUtils.bytesToHexString(response.payload) + s;
1774 return s;
1775 }
1776
Jake Hambye994d462014-02-03 13:10:13 -08001777 /**
1778 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1779 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1780 *
1781 * @param itemID the ID of the item to read
1782 * @return the NV item as a String, or null on error.
1783 */
1784 @Override
1785 public String nvReadItem(int itemID) {
Junda Liua2e36012014-07-09 18:30:01 -07001786 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001787 if (DBG) log("nvReadItem: item " + itemID);
1788 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
1789 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
1790 return value;
1791 }
1792
1793 /**
1794 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1795 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1796 *
1797 * @param itemID the ID of the item to read
1798 * @param itemValue the value to write, as a String
1799 * @return true on success; false on any failure
1800 */
1801 @Override
1802 public boolean nvWriteItem(int itemID, String itemValue) {
Junda Liua2e36012014-07-09 18:30:01 -07001803 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001804 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
1805 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
1806 new Pair<Integer, String>(itemID, itemValue));
1807 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
1808 return success;
1809 }
1810
1811 /**
1812 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
1813 * Used for device configuration by some CDMA operators.
1814 *
1815 * @param preferredRoamingList byte array containing the new PRL
1816 * @return true on success; false on any failure
1817 */
1818 @Override
1819 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Junda Liua2e36012014-07-09 18:30:01 -07001820 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001821 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
1822 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
1823 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
1824 return success;
1825 }
1826
1827 /**
1828 * Perform the specified type of NV config reset.
1829 * Used for device configuration by some CDMA operators.
1830 *
1831 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
1832 * @return true on success; false on any failure
1833 */
1834 @Override
1835 public boolean nvResetConfig(int resetType) {
Junda Liua2e36012014-07-09 18:30:01 -07001836 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001837 if (DBG) log("nvResetConfig: type " + resetType);
1838 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
1839 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
1840 return success;
1841 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001842
1843 /**
Wink Saville36469e72014-06-11 15:17:00 -07001844 * {@hide}
1845 * Returns Default sim, 0 in the case of single standby.
1846 */
1847 public int getDefaultSim() {
1848 //TODO Need to get it from Telephony Devcontroller
1849 return 0;
1850 }
1851
ram87fca6f2014-07-18 18:58:44 +05301852 public String[] getPcscfAddress(String apnType) {
Wink Saville36469e72014-06-11 15:17:00 -07001853 enforceReadPermission();
ram87fca6f2014-07-18 18:58:44 +05301854 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07001855 }
1856
1857 public void setImsRegistrationState(boolean registered) {
1858 enforceModifyPermission();
1859 mPhone.setImsRegistrationState(registered);
1860 }
1861
1862 /**
Junda Liu84d15a22014-07-02 11:21:04 -07001863 * Get the calculated preferred network type.
1864 * Used for debugging incorrect network type.
1865 *
1866 * @return the preferred network type, defined in RILConstants.java.
1867 */
1868 @Override
1869 public int getCalculatedPreferredNetworkType() {
1870 enforceReadPermission();
Amit Mahajan43330e02014-11-18 11:54:45 -08001871 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07001872 }
1873
1874 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08001875 * Get the preferred network type.
1876 * Used for device configuration by some CDMA operators.
1877 *
1878 * @return the preferred network type, defined in RILConstants.java.
1879 */
1880 @Override
1881 public int getPreferredNetworkType() {
Junda Liua2e36012014-07-09 18:30:01 -07001882 enforceModifyPermissionOrCarrierPrivilege();
Jake Hamby7c27be32014-03-03 13:25:59 -08001883 if (DBG) log("getPreferredNetworkType");
1884 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null);
1885 int networkType = (result != null ? result[0] : -1);
1886 if (DBG) log("getPreferredNetworkType: " + networkType);
1887 return networkType;
1888 }
1889
1890 /**
1891 * Set the preferred network type.
1892 * Used for device configuration by some CDMA operators.
1893 *
1894 * @param networkType the preferred network type, defined in RILConstants.java.
1895 * @return true on success; false on any failure.
1896 */
1897 @Override
1898 public boolean setPreferredNetworkType(int networkType) {
Junda Liua2e36012014-07-09 18:30:01 -07001899 enforceModifyPermissionOrCarrierPrivilege();
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001900 final int phoneSubId = mPhone.getSubId();
Jake Hamby7c27be32014-03-03 13:25:59 -08001901 if (DBG) log("setPreferredNetworkType: type " + networkType);
1902 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
1903 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07001904 if (success) {
1905 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001906 Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07001907 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001908 return success;
1909 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001910
1911 /**
Junda Liu475951f2014-11-07 16:45:03 -08001912 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
1913 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
1914 * tethering.
1915 *
1916 * @return 0: Not required. 1: required. 2: Not set.
1917 * @hide
1918 */
1919 @Override
1920 public int getTetherApnRequired() {
1921 enforceModifyPermissionOrCarrierPrivilege();
1922 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
1923 Settings.Global.TETHER_DUN_REQUIRED, 2);
1924 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
1925 // config_tether_apndata.
1926 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
1927 dunRequired = 1;
1928 }
1929 return dunRequired;
1930 }
1931
1932 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07001933 * Set mobile data enabled
1934 * Used by the user through settings etc to turn on/off mobile data
1935 *
1936 * @param enable {@code true} turn turn data on, else {@code false}
1937 */
1938 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001939 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07001940 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08001941 int phoneId = mSubscriptionController.getPhoneId(subId);
1942 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1943 Phone phone = PhoneFactory.getPhone(phoneId);
1944 if (phone != null) {
1945 log("setDataEnabled: subId=" + subId + " enable=" + enable);
1946 phone.setDataEnabled(enable);
1947 } else {
1948 loge("setDataEnabled: no phone for subId=" + subId);
1949 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001950 }
1951
1952 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07001953 * Get whether mobile data is enabled.
1954 *
1955 * Note that this used to be available from ConnectivityService, gated by
1956 * ACCESS_NETWORK_STATE permission, so this will accept either that or
1957 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07001958 *
1959 * @return {@code true} if data is enabled else {@code false}
1960 */
1961 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001962 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07001963 try {
1964 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
1965 null);
1966 } catch (Exception e) {
1967 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
1968 null);
1969 }
Wink Savillee7353bb2014-12-05 14:21:41 -08001970 int phoneId = mSubscriptionController.getPhoneId(subId);
1971 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1972 Phone phone = PhoneFactory.getPhone(phoneId);
1973 if (phone != null) {
1974 boolean retVal = phone.getDataEnabled();
1975 log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
1976 return retVal;
1977 } else {
1978 loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
1979 return false;
1980 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001981 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001982
1983 @Override
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001984 public int getCarrierPrivilegeStatus() {
Shishir Agrawal21409252015-01-15 23:33:50 -08001985 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001986 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001987 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001988 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1989 }
1990 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001991 mPhone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001992 }
Junda Liu29340342014-07-10 15:23:27 -07001993
1994 @Override
Shishir Agrawal6d5a2852014-07-11 16:32:57 -07001995 public int checkCarrierPrivilegesForPackage(String pkgname) {
Shishir Agrawal21409252015-01-15 23:33:50 -08001996 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001997 if (card == null) {
1998 loge("checkCarrierPrivilegesForPackage: No UICC");
1999 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2000 }
2001 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname);
Junda Liu29340342014-07-10 15:23:27 -07002002 }
Derek Tan89e89d42014-07-08 17:00:10 -07002003
2004 @Override
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002005 public List<String> getCarrierPackageNamesForIntent(Intent intent) {
Shishir Agrawal21409252015-01-15 23:33:50 -08002006 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002007 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002008 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002009 return null ;
2010 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002011 return card.getCarrierPackageNamesForIntent(
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002012 mPhone.getContext().getPackageManager(), intent);
2013 }
2014
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 private String getIccId(int subId) {
Derek Tan97ebb422014-09-05 16:55:38 -07002016 UiccCard card = getPhone(subId).getUiccCard();
2017 if (card == null) {
2018 loge("getIccId: No UICC");
2019 return null;
2020 }
2021 String iccId = card.getIccId();
2022 if (TextUtils.isEmpty(iccId)) {
2023 loge("getIccId: ICC ID is null or empty.");
2024 return null;
2025 }
2026 return iccId;
2027 }
2028
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002029 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002030 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2031 String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002032 enforceCarrierPrivilege();
Derek Tan97ebb422014-09-05 16:55:38 -07002033
Jeff Sharkey85190e62014-12-05 09:40:12 -08002034 final String iccId = getIccId(subId);
2035 final String subscriberId = getPhone(subId).getSubscriberId();
2036
2037 if (DBG_MERGE) {
2038 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2039 + subscriberId + " to " + number);
2040 }
2041
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002042 if (TextUtils.isEmpty(iccId)) {
2043 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002044 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002045
Jeff Sharkey85190e62014-12-05 09:40:12 -08002046 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2047
2048 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002049 if (alphaTag == null) {
2050 editor.remove(alphaTagPrefKey);
2051 } else {
2052 editor.putString(alphaTagPrefKey, alphaTag);
2053 }
2054
Jeff Sharkey85190e62014-12-05 09:40:12 -08002055 // Record both the line number and IMSI for this ICCID, since we need to
2056 // track all merged IMSIs based on line number
2057 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2058 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002059 if (number == null) {
2060 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002061 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002062 } else {
2063 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002064 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002065 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002066
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002067 editor.commit();
2068 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002069 }
2070
2071 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002072 public String getLine1NumberForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002073 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002074
2075 String iccId = getIccId(subId);
2076 if (iccId != null) {
2077 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002078 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002079 }
Derek Tan97ebb422014-09-05 16:55:38 -07002080 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002081 }
2082
2083 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002084 public String getLine1AlphaTagForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002085 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002086
2087 String iccId = getIccId(subId);
2088 if (iccId != null) {
2089 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002090 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002091 }
Derek Tan97ebb422014-09-05 16:55:38 -07002092 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002093 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002094
2095 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002096 public String[] getMergedSubscriberIds() {
2097 final Context context = mPhone.getContext();
2098 final TelephonyManager tele = TelephonyManager.from(context);
2099 final SubscriptionManager sub = SubscriptionManager.from(context);
2100
2101 // Figure out what subscribers are currently active
2102 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
2103 final int[] subIds = sub.getActiveSubscriptionIdList();
2104 for (int subId : subIds) {
2105 activeSubscriberIds.add(tele.getSubscriberId(subId));
2106 }
2107
2108 // First pass, find a number override for an active subscriber
2109 String mergeNumber = null;
2110 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2111 for (String key : prefs.keySet()) {
2112 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2113 final String subscriberId = (String) prefs.get(key);
2114 if (activeSubscriberIds.contains(subscriberId)) {
2115 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2116 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2117 mergeNumber = (String) prefs.get(numberKey);
2118 if (DBG_MERGE) {
2119 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2120 + " for active subscriber " + subscriberId);
2121 }
2122 if (!TextUtils.isEmpty(mergeNumber)) {
2123 break;
2124 }
2125 }
2126 }
2127 }
2128
2129 // Shortcut when no active merged subscribers
2130 if (TextUtils.isEmpty(mergeNumber)) {
2131 return null;
2132 }
2133
2134 // Second pass, find all subscribers under that line override
2135 final ArraySet<String> result = new ArraySet<>();
2136 for (String key : prefs.keySet()) {
2137 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2138 final String number = (String) prefs.get(key);
2139 if (mergeNumber.equals(number)) {
2140 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2141 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2142 final String subscriberId = (String) prefs.get(subscriberKey);
2143 if (!TextUtils.isEmpty(subscriberId)) {
2144 result.add(subscriberId);
2145 }
2146 }
2147 }
2148 }
2149
2150 final String[] resultArray = result.toArray(new String[result.size()]);
2151 Arrays.sort(resultArray);
2152 if (DBG_MERGE) {
2153 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2154 }
2155 return resultArray;
2156 }
2157
2158 @Override
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002159 public boolean setOperatorBrandOverride(String brand) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002160 enforceCarrierPrivilege();
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002161 return mPhone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002162 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002163
2164 @Override
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002165 public boolean setRoamingOverride(List<String> gsmRoamingList,
2166 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2167 List<String> cdmaNonRoamingList) {
2168 enforceCarrierPrivilege();
2169 return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
2170 cdmaNonRoamingList);
2171 }
2172
2173 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002174 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2175 enforceModifyPermission();
2176
2177 int returnValue = 0;
2178 try {
2179 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2180 if(result.exception == null) {
2181 if (result.result != null) {
2182 byte[] responseData = (byte[])(result.result);
2183 if(responseData.length > oemResp.length) {
2184 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2185 responseData.length + "bytes. Buffer Size is " +
2186 oemResp.length + "bytes.");
2187 }
2188 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2189 returnValue = responseData.length;
2190 }
2191 } else {
2192 CommandException ex = (CommandException) result.exception;
2193 returnValue = ex.getCommandError().ordinal();
2194 if(returnValue > 0) returnValue *= -1;
2195 }
2196 } catch (RuntimeException e) {
2197 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2198 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2199 if(returnValue > 0) returnValue *= -1;
2200 }
2201
2202 return returnValue;
2203 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002204
2205 @Override
2206 public void setRadioCapability(RadioAccessFamily[] rafs) {
2207 try {
2208 ProxyController.getInstance().setRadioCapability(rafs);
2209 } catch (RuntimeException e) {
2210 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2211 }
2212 }
2213
2214 @Override
2215 public int getRadioAccessFamily(int phoneId) {
2216 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2217 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002218
2219 @Override
2220 public void enableVideoCalling(boolean enable) {
2221 enforceModifyPermission();
2222 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2223 editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable);
2224 editor.commit();
2225 }
2226
2227 @Override
2228 public boolean isVideoCallingEnabled() {
2229 enforceReadPermission();
Andrew Lee77527ac2014-10-21 16:57:39 -07002230 // Check the user preference and the system-level IMS setting. Even if the user has
2231 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2232 // In the long run, we may instead need to check if there exists a connection service
2233 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002234 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2235 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
2236 && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
Andrew Leedf14ead2014-10-17 14:22:52 -07002237 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002238
Andrew Leea1239f22015-03-02 17:44:07 -08002239 @Override
2240 public boolean canChangeDtmfToneLength() {
2241 return mPhone.getContext().getResources().getBoolean(R.bool.dtmf_type_enabled);
2242 }
2243
2244 @Override
2245 public boolean isWorldPhone() {
2246 return mPhone.getContext().getResources().getBoolean(R.bool.world_phone);
2247 }
2248
Andrew Lee9431b832015-03-09 18:46:45 -07002249 @Override
2250 public boolean isTtyModeSupported() {
2251 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2252 TelephonyManager telephonyManager =
2253 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
2254 return !telephonyManager.isMultiSimEnabled() && telecomManager.isTtySupported();
2255 }
2256
2257 @Override
2258 public boolean isHearingAidCompatibilitySupported() {
2259 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2260 }
2261
Sanket Padawe7310cc72015-01-14 09:53:20 -08002262 /**
2263 * Returns the unique device ID of phone, for example, the IMEI for
2264 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2265 *
2266 * <p>Requires Permission:
2267 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2268 */
2269 @Override
2270 public String getDeviceId() {
2271 enforceReadPermission();
2272 final Phone phone = PhoneFactory.getPhone(0);
2273 if (phone != null) {
2274 return phone.getDeviceId();
2275 } else {
2276 return null;
2277 }
2278 }
2279
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002280 /*
2281 * {@hide}
2282 * Returns the IMS Registration Status
2283 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08002284 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002285 public boolean isImsRegistered() {
2286 return mPhone.isImsRegistered();
2287 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08002288
2289 @Override
2290 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
2291 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293}