blob: 9320bc114d33d61e1c3b619f62aebe1939c64401 [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
Tyler Gunnba569462018-02-14 14:19:42 -080019import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070020import android.app.ActivityManager;
21import android.app.AppOpsManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070022import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.content.Context;
24import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070025import android.content.SharedPreferences;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070026import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.net.Uri;
28import android.os.AsyncResult;
29import android.os.Binder;
30import android.os.Bundle;
31import android.os.Handler;
32import android.os.Looper;
33import android.os.Message;
34import android.os.Process;
35import android.os.ServiceManager;
36import android.os.UserHandle;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080038import android.provider.Settings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.telephony.CellInfo;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070040import android.telephony.IccOpenLogicalChannelResponse;
Jake Hambye994d462014-02-03 13:10:13 -080041import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070042import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080044import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080045import android.telephony.SubscriptionManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080046import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080048import android.util.ArrayMap;
49import android.util.ArraySet;
Tyler Gunnba569462018-02-14 14:19:42 -080050import android.util.EventLog;
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) {
Tyler Gunnba569462018-02-14 14:19:42 -0800827 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
828 != PackageManager.PERMISSION_GRANTED) {
829 Log.i(LOG_TAG, "endCall: called without modify phone state.");
830 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
831 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
832 }
Stuart Scott584921c2015-01-15 17:10:34 -0800833 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700834 }
835
836 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700837 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700838 }
839
Wink Savilleb564aae2014-10-23 10:18:09 -0700840 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700841 if (DBG) log("answerRingingCall...");
842 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
843 // but that can probably wait till the big TelephonyManager API overhaul.
844 // For now, protect this call with the MODIFY_PHONE_STATE permission.
845 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800846 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700847 }
848
849 /**
850 * Make the actual telephony calls to implement answerRingingCall().
851 * This should only be called from the main thread of the Phone app.
852 * @see #answerRingingCall
853 *
854 * TODO: it would be nice to return true if we answered the call, or
855 * false if there wasn't actually a ringing incoming call, or some
856 * other error occurred. (In other words, pass back the return value
857 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
858 * But that would require calling this method via sendRequest() rather
859 * than sendRequestAsync(), and right now we don't actually *need* that
860 * return value, so let's just return void for now.
861 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700862 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -0700863 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700864 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -0700865 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
866 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700867 if (hasActiveCall && hasHoldingCall) {
868 // Both lines are in use!
869 // TODO: provide a flag to let the caller specify what
870 // policy to use if both lines are in use. (The current
871 // behavior is hardwired to "answer incoming, end ongoing",
872 // which is how the CALL button is specced to behave.)
873 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
874 return;
875 } else {
876 // answerCall() will automatically hold the current active
877 // call, if there is one.
878 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
879 return;
880 }
881 } else {
882 // No call was ringing.
883 return;
884 }
885 }
886
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700887 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -0700888 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700889 */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700890 public void silenceRinger() {
891 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700892 }
893
894 public boolean isOffhook() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700895 return isOffhookForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700896 }
897
Wink Savilleb564aae2014-10-23 10:18:09 -0700898 public boolean isOffhookForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700899 return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700900 }
901
902 public boolean isRinging() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700903 return (isRingingForSubscriber(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -0700904 }
905
Wink Savilleb564aae2014-10-23 10:18:09 -0700906 public boolean isRingingForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700907 return (getPhone(subId).getState() == PhoneConstants.State.RINGING);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700908 }
909
910 public boolean isIdle() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700911 return isIdleForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700912 }
913
Wink Savilleb564aae2014-10-23 10:18:09 -0700914 public boolean isIdleForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700915 return (getPhone(subId).getState() == PhoneConstants.State.IDLE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 }
917
918 public boolean isSimPinEnabled() {
919 enforceReadPermission();
920 return (PhoneGlobals.getInstance().isSimPinEnabled());
921 }
922
923 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700924 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700925 }
926
Wink Savilleb564aae2014-10-23 10:18:09 -0700927 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700928 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700929 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
930 }
931
932 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700933 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700934 }
935
Wink Savilleb564aae2014-10-23 10:18:09 -0700936 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700937 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700938 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
939 }
940
941 /** {@hide} */
942 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700943 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700944 }
945
Wink Savilleb564aae2014-10-23 10:18:09 -0700946 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700948 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949 checkSimPin.start();
950 return checkSimPin.unlockSim(null, pin);
951 }
952
Wink Saville9de0f752013-10-22 19:04:03 -0700953 /** {@hide} */
954 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700955 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700956 }
957
Wink Savilleb564aae2014-10-23 10:18:09 -0700958 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700960 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 checkSimPuk.start();
962 return checkSimPuk.unlockSim(puk, pin);
963 }
964
965 /**
Wink Saville9de0f752013-10-22 19:04:03 -0700966 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700967 * a synchronous one.
968 */
969 private static class UnlockSim extends Thread {
970
971 private final IccCard mSimCard;
972
973 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -0700974 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
975 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976
977 // For replies from SimCard interface
978 private Handler mHandler;
979
980 // For async handler to identify request type
981 private static final int SUPPLY_PIN_COMPLETE = 100;
982
983 public UnlockSim(IccCard simCard) {
984 mSimCard = simCard;
985 }
986
987 @Override
988 public void run() {
989 Looper.prepare();
990 synchronized (UnlockSim.this) {
991 mHandler = new Handler() {
992 @Override
993 public void handleMessage(Message msg) {
994 AsyncResult ar = (AsyncResult) msg.obj;
995 switch (msg.what) {
996 case SUPPLY_PIN_COMPLETE:
997 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
998 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -0700999 mRetryCount = msg.arg1;
1000 if (ar.exception != null) {
1001 if (ar.exception instanceof CommandException &&
1002 ((CommandException)(ar.exception)).getCommandError()
1003 == CommandException.Error.PASSWORD_INCORRECT) {
1004 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1005 } else {
1006 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1007 }
1008 } else {
1009 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001011 mDone = true;
1012 UnlockSim.this.notifyAll();
1013 }
1014 break;
1015 }
1016 }
1017 };
1018 UnlockSim.this.notifyAll();
1019 }
1020 Looper.loop();
1021 }
1022
1023 /*
1024 * Use PIN or PUK to unlock SIM card
1025 *
1026 * If PUK is null, unlock SIM card with PIN
1027 *
1028 * If PUK is not null, unlock SIM card with PUK and set PIN code
1029 */
Wink Saville9de0f752013-10-22 19:04:03 -07001030 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031
1032 while (mHandler == null) {
1033 try {
1034 wait();
1035 } catch (InterruptedException e) {
1036 Thread.currentThread().interrupt();
1037 }
1038 }
1039 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1040
1041 if (puk == null) {
1042 mSimCard.supplyPin(pin, callback);
1043 } else {
1044 mSimCard.supplyPuk(puk, pin, callback);
1045 }
1046
1047 while (!mDone) {
1048 try {
1049 Log.d(LOG_TAG, "wait for done");
1050 wait();
1051 } catch (InterruptedException e) {
1052 // Restore the interrupted status
1053 Thread.currentThread().interrupt();
1054 }
1055 }
1056 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001057 int[] resultArray = new int[2];
1058 resultArray[0] = mResult;
1059 resultArray[1] = mRetryCount;
1060 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 }
1062 }
1063
1064 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001065 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001066
1067 }
1068
Wink Savilleb564aae2014-10-23 10:18:09 -07001069 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 // No permission check needed here: this call is harmless, and it's
1071 // needed for the ServiceState.requestStateUpdate() call (which is
1072 // already intentionally exposed to 3rd parties.)
Wink Saville36469e72014-06-11 15:17:00 -07001073 getPhone(subId).updateServiceLocation();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 }
1075
1076 public boolean isRadioOn() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001077 return isRadioOnForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001078 }
1079
Wink Savilleb564aae2014-10-23 10:18:09 -07001080 public boolean isRadioOnForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001081 return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 }
1083
1084 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001085 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 }
Wink Saville36469e72014-06-11 15:17:00 -07001088
Wink Savilleb564aae2014-10-23 10:18:09 -07001089 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 enforceModifyPermission();
Wink Savilleadd7cc52014-09-08 14:23:09 -07001091 getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001092 }
1093
1094 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001095 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001096 }
1097
Wink Savilleb564aae2014-10-23 10:18:09 -07001098 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001099 enforceModifyPermission();
1100 if ((getPhone(subId).getServiceState().getState() !=
1101 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001102 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 }
1104 return true;
1105 }
Wink Saville36469e72014-06-11 15:17:00 -07001106
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001107 public boolean needMobileRadioShutdown() {
1108 /*
1109 * If any of the Radios are available, it will need to be
1110 * shutdown. So return true if any Radio is available.
1111 */
1112 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1113 Phone phone = PhoneFactory.getPhone(i);
1114 if (phone != null && phone.isRadioAvailable()) return true;
1115 }
1116 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1117 return false;
1118 }
1119
1120 public void shutdownMobileRadios() {
1121 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1122 logv("Shutting down Phone " + i);
1123 shutdownRadioUsingPhoneId(i);
1124 }
1125 }
1126
1127 private void shutdownRadioUsingPhoneId(int phoneId) {
1128 enforceModifyPermission();
1129 Phone phone = PhoneFactory.getPhone(phoneId);
1130 if (phone != null && phone.isRadioAvailable()) {
1131 phone.shutdownRadio();
1132 }
1133 }
1134
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 public boolean setRadioPower(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001136 return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Wink Savilleb564aae2014-10-23 10:18:09 -07001139 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001141 getPhone(subId).setRadioPower(turnOn);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 return true;
1143 }
1144
Wink Saville36469e72014-06-11 15:17:00 -07001145 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001146 public boolean enableDataConnectivity() {
1147 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001148 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001149 getPhone(subId).setDataEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 return true;
1151 }
1152
Wink Saville36469e72014-06-11 15:17:00 -07001153 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 public boolean disableDataConnectivity() {
1155 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001156 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001157 getPhone(subId).setDataEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158 return true;
1159 }
1160
Wink Saville36469e72014-06-11 15:17:00 -07001161 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001163 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001164 return getPhone(subId).isDataConnectivityPossible();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 }
1166
1167 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001168 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
Wink Savilleb564aae2014-10-23 10:18:09 -07001171 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001173 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 }
1175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 public int getCallState() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001177 return getCallStateForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001178 }
1179
Wink Savilleb564aae2014-10-23 10:18:09 -07001180 public int getCallStateForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001181 return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 }
1183
1184 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001185 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001186 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 }
1188
1189 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001190 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001191 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 @Override
1195 public Bundle getCellLocation() {
1196 try {
1197 mApp.enforceCallingOrSelfPermission(
1198 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1199 } catch (SecurityException e) {
1200 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1201 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1202 // is the weaker precondition
1203 mApp.enforceCallingOrSelfPermission(
1204 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1205 }
1206
Jake Hambye994d462014-02-03 13:10:13 -08001207 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 if (DBG_LOC) log("getCellLocation: is active user");
1209 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001210 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1211 phone.getCellLocation().fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 return data;
1213 } else {
1214 if (DBG_LOC) log("getCellLocation: suppress non-active user");
1215 return null;
1216 }
1217 }
1218
1219 @Override
1220 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001221 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001222 }
1223
Wink Savilleb564aae2014-10-23 10:18:09 -07001224 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 mApp.enforceCallingOrSelfPermission(
1226 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001227 getPhone(subId).enableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 }
1229
1230 @Override
1231 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001232 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001233 }
1234
Wink Savilleb564aae2014-10-23 10:18:09 -07001235 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 mApp.enforceCallingOrSelfPermission(
1237 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001238 getPhone(subId).disableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 }
1240
1241 @Override
1242 @SuppressWarnings("unchecked")
1243 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1244 try {
1245 mApp.enforceCallingOrSelfPermission(
1246 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1247 } catch (SecurityException e) {
1248 // If we have ACCESS_FINE_LOCATION permission, skip the check
1249 // for ACCESS_COARSE_LOCATION
1250 // A failure should throw the SecurityException from
1251 // ACCESS_COARSE_LOCATION since this is the weaker precondition
1252 mApp.enforceCallingOrSelfPermission(
1253 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1254 }
1255
1256 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1257 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1258 return null;
1259 }
Jake Hambye994d462014-02-03 13:10:13 -08001260 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1262
1263 ArrayList<NeighboringCellInfo> cells = null;
1264
1265 try {
1266 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Wink Saville36469e72014-06-11 15:17:00 -07001267 CMD_HANDLE_NEIGHBORING_CELL, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001269 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 }
1271 return cells;
1272 } else {
1273 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1274 return null;
1275 }
1276 }
1277
1278
1279 @Override
1280 public List<CellInfo> getAllCellInfo() {
1281 try {
1282 mApp.enforceCallingOrSelfPermission(
1283 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1284 } catch (SecurityException e) {
1285 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1286 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1287 // is the weaker precondition
1288 mApp.enforceCallingOrSelfPermission(
1289 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1290 }
1291
Jake Hambye994d462014-02-03 13:10:13 -08001292 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 if (DBG_LOC) log("getAllCellInfo: is active user");
Legler Wu2c01cdf2014-12-08 19:00:59 +08001294 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1295 for (Phone phone : PhoneFactory.getPhones()) {
1296 cellInfos.addAll(phone.getAllCellInfo());
1297 }
1298 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 } else {
1300 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1301 return null;
1302 }
1303 }
1304
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001305 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 public void setCellInfoListRate(int rateInMillis) {
Jack Yu3128d9e2017-01-16 10:15:34 -08001307 enforceModifyPermission();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 mPhone.setCellInfoListRate(rateInMillis);
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 //
1312 // Internal helper methods.
1313 //
1314
Jake Hambye994d462014-02-03 13:10:13 -08001315 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 boolean ok;
1317
1318 boolean self = Binder.getCallingUid() == Process.myUid();
1319 if (!self) {
1320 // Get the caller's user id then clear the calling identity
1321 // which will be restored in the finally clause.
1322 int callingUser = UserHandle.getCallingUserId();
1323 long ident = Binder.clearCallingIdentity();
1324
1325 try {
1326 // With calling identity cleared the current user is the foreground user.
1327 int foregroundUser = ActivityManager.getCurrentUser();
1328 ok = (foregroundUser == callingUser);
1329 if (DBG_LOC) {
1330 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1331 + " callingUser=" + callingUser + " ok=" + ok);
1332 }
1333 } catch (Exception ex) {
1334 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1335 ok = false;
1336 } finally {
1337 Binder.restoreCallingIdentity(ident);
1338 }
1339 } else {
1340 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1341 ok = true;
1342 }
1343 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1344 return ok;
1345 }
1346
1347 /**
1348 * Make sure the caller has the READ_PHONE_STATE permission.
1349 *
1350 * @throws SecurityException if the caller does not have the required permission
1351 */
1352 private void enforceReadPermission() {
1353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
1354 }
1355
1356 /**
1357 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1358 *
1359 * @throws SecurityException if the caller does not have the required permission
1360 */
1361 private void enforceModifyPermission() {
1362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1363 }
1364
1365 /**
Junda Liua2e36012014-07-09 18:30:01 -07001366 * Make sure either system app or the caller has carrier privilege.
1367 *
1368 * @throws SecurityException if the caller does not have the required permission/privilege
1369 */
1370 private void enforceModifyPermissionOrCarrierPrivilege() {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001371 int permission = mApp.checkCallingOrSelfPermission(
1372 android.Manifest.permission.MODIFY_PHONE_STATE);
1373 if (permission == PackageManager.PERMISSION_GRANTED) {
1374 return;
1375 }
1376
1377 log("No modify permission, check carrier privilege next.");
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001378 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001379 loge("No Carrier Privilege.");
1380 throw new SecurityException("No modify permission or carrier privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001381 }
1382 }
1383
1384 /**
1385 * Make sure the caller has carrier privilege.
1386 *
1387 * @throws SecurityException if the caller does not have the required permission
1388 */
1389 private void enforceCarrierPrivilege() {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001390 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001391 loge("No Carrier Privilege.");
1392 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001393 }
1394 }
1395
1396 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 * Make sure the caller has the CALL_PHONE permission.
1398 *
1399 * @throws SecurityException if the caller does not have the required permission
1400 */
1401 private void enforceCallPermission() {
1402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1403 }
1404
Shishir Agrawal566b7612013-10-28 14:41:00 -07001405 /**
Gabriel Peal36ebb0d2014-03-20 09:20:43 -07001406 * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission.
1407 *
1408 * @throws SecurityException if the caller does not have the required permission
1409 */
1410 private void enforcePrivilegedPhoneStatePermission() {
1411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1412 null);
1413 }
1414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 private String createTelUrl(String number) {
1416 if (TextUtils.isEmpty(number)) {
1417 return null;
1418 }
1419
Jake Hambye994d462014-02-03 13:10:13 -08001420 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 }
1422
Ihab Awadf9e92732013-12-05 18:02:52 -08001423 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1425 }
1426
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001427 private static void logv(String msg) {
1428 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1429 }
1430
Ihab Awadf9e92732013-12-05 18:02:52 -08001431 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1433 }
1434
1435 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001436 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
1438
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 public int getActivePhoneTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001440 return getPhone(subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 }
1442
1443 /**
1444 * Returns the CDMA ERI icon index to display
1445 */
1446 public int getCdmaEriIconIndex() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001448
1449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public int getCdmaEriIconIndexForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001452 return getPhone(subId).getCdmaEriIconIndex();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 }
1454
1455 /**
1456 * Returns the CDMA ERI icon mode,
1457 * 0 - ON
1458 * 1 - FLASHING
1459 */
1460 public int getCdmaEriIconMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001462 }
1463
Wink Savilleb564aae2014-10-23 10:18:09 -07001464 public int getCdmaEriIconModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001465 return getPhone(subId).getCdmaEriIconMode();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
1468 /**
1469 * Returns the CDMA ERI text,
1470 */
1471 public String getCdmaEriText() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001472 return getCdmaEriTextForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001473 }
1474
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public String getCdmaEriTextForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001476 return getPhone(subId).getCdmaEriText();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 }
1478
1479 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001480 * Returns the CDMA MDN.
1481 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001482 public String getCdmaMdn(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001483 enforceModifyPermissionOrCarrierPrivilege();
1484 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1485 return getPhone(subId).getLine1Number();
1486 } else {
1487 return null;
1488 }
1489 }
1490
1491 /**
1492 * Returns the CDMA MIN.
1493 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001494 public String getCdmaMin(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001495 enforceModifyPermissionOrCarrierPrivilege();
1496 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1497 return getPhone(subId).getCdmaMin();
1498 } else {
1499 return null;
1500 }
1501 }
1502
1503 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 * Returns true if CDMA provisioning needs to run.
1505 */
1506 public boolean needsOtaServiceProvisioning() {
1507 return mPhone.needsOtaServiceProvisioning();
1508 }
1509
1510 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001511 * Sets the voice mail number of a given subId.
1512 */
1513 @Override
1514 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001515 enforceCarrierPrivilege();
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001516 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1517 new Pair<String, String>(alphaTag, number), new Integer(subId));
1518 return success;
1519 }
1520
1521 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 * Returns the unread count of voicemails
1523 */
1524 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001525 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001526 }
1527
1528 /**
1529 * Returns the unread count of voicemails for a subId
1530 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001531 public int getVoiceMessageCountForSubscriber( int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001532 return getPhone(subId).getVoiceMessageCount();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
1535 /**
1536 * Returns the data network type
1537 *
1538 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1539 */
1540 @Override
1541 public int getNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 return getNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001543 }
1544
1545 /**
1546 * Returns the network type for a subId
1547 */
1548 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001549 public int getNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001550 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 }
1552
1553 /**
1554 * Returns the data network type
1555 */
1556 @Override
1557 public int getDataNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001558 return getDataNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001559 }
1560
1561 /**
1562 * Returns the data network type for a subId
1563 */
1564 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public int getDataNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001566 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
1569 /**
1570 * Returns the data network type
1571 */
1572 @Override
1573 public int getVoiceNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001574 return getVoiceNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001575 }
1576
1577 /**
1578 * Returns the Voice network type for a subId
1579 */
1580 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public int getVoiceNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001582 return getPhone(subId).getServiceState().getVoiceNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
1586 * @return true if a ICC card is present
1587 */
1588 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001589 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001590 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
1593 /**
1594 * @return true if a ICC card is present for a slotId
1595 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001596 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001597 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
1598 if (subId != null) {
1599 return getPhone(subId[0]).getIccCard().hasIccCard();
1600 } else {
1601 return false;
1602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604
1605 /**
1606 * Return if the current radio is LTE on CDMA. This
1607 * is a tri-state return value as for a period of time
1608 * the mode may be unknown.
1609 *
1610 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001611 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 */
1613 public int getLteOnCdmaMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001615 }
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public int getLteOnCdmaModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001618 return getPhone(subId).getLteOnCdmaMode();
1619 }
1620
1621 public void setPhone(Phone phone) {
1622 mPhone = phone;
1623 }
1624
1625 /**
1626 * {@hide}
1627 * Returns Default subId, 0 in the case of single standby.
1628 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001629 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001630 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001631 }
1632
Wink Savilleb564aae2014-10-23 10:18:09 -07001633 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001634 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001636
1637 /**
1638 * @see android.telephony.TelephonyManager.WifiCallingChoices
1639 */
1640 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001641 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1642 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001643 }
1644
1645 /**
1646 * @see android.telephony.TelephonyManager.WifiCallingChoices
1647 */
1648 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001649 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1650 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1651 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001652 }
1653
Sailesh Nepald1e68152013-12-12 19:08:02 -08001654 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001655 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001656 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001657 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001658
Shishir Agrawal566b7612013-10-28 14:41:00 -07001659 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001660 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
Junda Liua2e36012014-07-09 18:30:01 -07001661 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001662
1663 if (DBG) log("iccOpenLogicalChannel: " + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001664 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
1665 CMD_OPEN_CHANNEL, AID);
1666 if (DBG) log("iccOpenLogicalChannel: " + response);
1667 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001668 }
1669
1670 @Override
1671 public boolean iccCloseLogicalChannel(int channel) {
Junda Liua2e36012014-07-09 18:30:01 -07001672 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001673
1674 if (DBG) log("iccCloseLogicalChannel: " + channel);
1675 if (channel < 0) {
1676 return false;
1677 }
Jake Hambye994d462014-02-03 13:10:13 -08001678 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001679 if (DBG) log("iccCloseLogicalChannel: " + success);
1680 return success;
1681 }
1682
1683 @Override
1684 public String iccTransmitApduLogicalChannel(int channel, int cla,
1685 int command, int p1, int p2, int p3, String data) {
Junda Liua2e36012014-07-09 18:30:01 -07001686 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001687
1688 if (DBG) {
1689 log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla +
1690 " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
1691 " data=" + data);
1692 }
1693
1694 if (channel < 0) {
1695 return "";
1696 }
1697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001698 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawal566b7612013-10-28 14:41:00 -07001699 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data));
1700 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
1701
Shishir Agrawal566b7612013-10-28 14:41:00 -07001702 // Append the returned status code to the end of the response payload.
1703 String s = Integer.toHexString(
1704 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001705 if (response.payload != null) {
1706 s = IccUtils.bytesToHexString(response.payload) + s;
1707 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001708 return s;
1709 }
Jake Hambye994d462014-02-03 13:10:13 -08001710
Evan Charltonc66da362014-05-16 14:06:40 -07001711 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001712 public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2,
1713 int p3, String data) {
1714 enforceModifyPermissionOrCarrierPrivilege();
1715
1716 if (DBG) {
1717 log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1="
1718 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
1719 }
1720
1721 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
1722 new IccAPDUArgument(0, cla, command, p1, p2, p3, data));
1723 if (DBG) log("iccTransmitApduBasicChannel: " + response);
1724
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001725 // Append the returned status code to the end of the response payload.
1726 String s = Integer.toHexString(
1727 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001728 if (response.payload != null) {
1729 s = IccUtils.bytesToHexString(response.payload) + s;
1730 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001731 return s;
1732 }
1733
1734 @Override
1735 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
1736 String filePath) {
1737 enforceModifyPermissionOrCarrierPrivilege();
1738
1739 if (DBG) {
1740 log("Exchange SIM_IO " + fileID + ":" + command + " " +
1741 p1 + " " + p2 + " " + p3 + ":" + filePath);
1742 }
1743
1744 IccIoResult response =
1745 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Yong Jiang3edf3782014-10-03 13:23:28 -05001746 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath));
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001747
1748 if (DBG) {
1749 log("Exchange SIM_IO [R]" + response);
1750 }
1751
1752 byte[] result = null;
1753 int length = 2;
1754 if (response.payload != null) {
1755 length = 2 + response.payload.length;
1756 result = new byte[length];
1757 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
1758 } else {
1759 result = new byte[length];
1760 }
1761
1762 result[length - 1] = (byte) response.sw2;
1763 result[length - 2] = (byte) response.sw1;
1764 return result;
1765 }
1766
1767 @Override
Evan Charltonc66da362014-05-16 14:06:40 -07001768 public String sendEnvelopeWithStatus(String content) {
Junda Liua2e36012014-07-09 18:30:01 -07001769 enforceModifyPermissionOrCarrierPrivilege();
Evan Charltonc66da362014-05-16 14:06:40 -07001770
1771 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content);
1772 if (response.payload == null) {
1773 return "";
1774 }
1775
1776 // Append the returned status code to the end of the response payload.
1777 String s = Integer.toHexString(
1778 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
1779 s = IccUtils.bytesToHexString(response.payload) + s;
1780 return s;
1781 }
1782
Jake Hambye994d462014-02-03 13:10:13 -08001783 /**
1784 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1785 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1786 *
1787 * @param itemID the ID of the item to read
1788 * @return the NV item as a String, or null on error.
1789 */
1790 @Override
1791 public String nvReadItem(int itemID) {
Junda Liua2e36012014-07-09 18:30:01 -07001792 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001793 if (DBG) log("nvReadItem: item " + itemID);
1794 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
1795 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
1796 return value;
1797 }
1798
1799 /**
1800 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1801 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1802 *
1803 * @param itemID the ID of the item to read
1804 * @param itemValue the value to write, as a String
1805 * @return true on success; false on any failure
1806 */
1807 @Override
1808 public boolean nvWriteItem(int itemID, String itemValue) {
Junda Liua2e36012014-07-09 18:30:01 -07001809 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001810 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
1811 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
1812 new Pair<Integer, String>(itemID, itemValue));
1813 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
1814 return success;
1815 }
1816
1817 /**
1818 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
1819 * Used for device configuration by some CDMA operators.
1820 *
1821 * @param preferredRoamingList byte array containing the new PRL
1822 * @return true on success; false on any failure
1823 */
1824 @Override
1825 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Junda Liua2e36012014-07-09 18:30:01 -07001826 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001827 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
1828 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
1829 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
1830 return success;
1831 }
1832
1833 /**
1834 * Perform the specified type of NV config reset.
1835 * Used for device configuration by some CDMA operators.
1836 *
1837 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
1838 * @return true on success; false on any failure
1839 */
1840 @Override
1841 public boolean nvResetConfig(int resetType) {
Junda Liua2e36012014-07-09 18:30:01 -07001842 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001843 if (DBG) log("nvResetConfig: type " + resetType);
1844 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
1845 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
1846 return success;
1847 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001848
1849 /**
Wink Saville36469e72014-06-11 15:17:00 -07001850 * {@hide}
1851 * Returns Default sim, 0 in the case of single standby.
1852 */
1853 public int getDefaultSim() {
1854 //TODO Need to get it from Telephony Devcontroller
1855 return 0;
1856 }
1857
ram87fca6f2014-07-18 18:58:44 +05301858 public String[] getPcscfAddress(String apnType) {
Wink Saville36469e72014-06-11 15:17:00 -07001859 enforceReadPermission();
ram87fca6f2014-07-18 18:58:44 +05301860 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
1863 public void setImsRegistrationState(boolean registered) {
1864 enforceModifyPermission();
1865 mPhone.setImsRegistrationState(registered);
1866 }
1867
1868 /**
Junda Liu84d15a22014-07-02 11:21:04 -07001869 * Get the calculated preferred network type.
1870 * Used for debugging incorrect network type.
1871 *
1872 * @return the preferred network type, defined in RILConstants.java.
1873 */
1874 @Override
1875 public int getCalculatedPreferredNetworkType() {
1876 enforceReadPermission();
Amit Mahajan43330e02014-11-18 11:54:45 -08001877 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07001878 }
1879
1880 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08001881 * Get the preferred network type.
1882 * Used for device configuration by some CDMA operators.
1883 *
1884 * @return the preferred network type, defined in RILConstants.java.
1885 */
1886 @Override
1887 public int getPreferredNetworkType() {
Junda Liua2e36012014-07-09 18:30:01 -07001888 enforceModifyPermissionOrCarrierPrivilege();
Jake Hamby7c27be32014-03-03 13:25:59 -08001889 if (DBG) log("getPreferredNetworkType");
1890 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null);
1891 int networkType = (result != null ? result[0] : -1);
1892 if (DBG) log("getPreferredNetworkType: " + networkType);
1893 return networkType;
1894 }
1895
1896 /**
1897 * Set the preferred network type.
1898 * Used for device configuration by some CDMA operators.
1899 *
1900 * @param networkType the preferred network type, defined in RILConstants.java.
1901 * @return true on success; false on any failure.
1902 */
1903 @Override
1904 public boolean setPreferredNetworkType(int networkType) {
Junda Liua2e36012014-07-09 18:30:01 -07001905 enforceModifyPermissionOrCarrierPrivilege();
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001906 final int phoneSubId = mPhone.getSubId();
Jake Hamby7c27be32014-03-03 13:25:59 -08001907 if (DBG) log("setPreferredNetworkType: type " + networkType);
1908 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
1909 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07001910 if (success) {
1911 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001912 Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07001913 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001914 return success;
1915 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001916
1917 /**
Junda Liu475951f2014-11-07 16:45:03 -08001918 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
1919 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
1920 * tethering.
1921 *
1922 * @return 0: Not required. 1: required. 2: Not set.
1923 * @hide
1924 */
1925 @Override
1926 public int getTetherApnRequired() {
1927 enforceModifyPermissionOrCarrierPrivilege();
1928 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
1929 Settings.Global.TETHER_DUN_REQUIRED, 2);
1930 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
1931 // config_tether_apndata.
1932 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
1933 dunRequired = 1;
1934 }
1935 return dunRequired;
1936 }
1937
1938 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07001939 * Set mobile data enabled
1940 * Used by the user through settings etc to turn on/off mobile data
1941 *
1942 * @param enable {@code true} turn turn data on, else {@code false}
1943 */
1944 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001945 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07001946 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08001947 int phoneId = mSubscriptionController.getPhoneId(subId);
1948 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1949 Phone phone = PhoneFactory.getPhone(phoneId);
1950 if (phone != null) {
1951 log("setDataEnabled: subId=" + subId + " enable=" + enable);
1952 phone.setDataEnabled(enable);
1953 } else {
1954 loge("setDataEnabled: no phone for subId=" + subId);
1955 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001956 }
1957
1958 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07001959 * Get whether mobile data is enabled.
1960 *
1961 * Note that this used to be available from ConnectivityService, gated by
1962 * ACCESS_NETWORK_STATE permission, so this will accept either that or
1963 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07001964 *
1965 * @return {@code true} if data is enabled else {@code false}
1966 */
1967 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001968 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07001969 try {
1970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
1971 null);
1972 } catch (Exception e) {
1973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
1974 null);
1975 }
Wink Savillee7353bb2014-12-05 14:21:41 -08001976 int phoneId = mSubscriptionController.getPhoneId(subId);
1977 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1978 Phone phone = PhoneFactory.getPhone(phoneId);
1979 if (phone != null) {
1980 boolean retVal = phone.getDataEnabled();
1981 log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
1982 return retVal;
1983 } else {
1984 loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
1985 return false;
1986 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001987 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001988
1989 @Override
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001990 public int getCarrierPrivilegeStatus() {
Shishir Agrawal21409252015-01-15 23:33:50 -08001991 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001992 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001993 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001994 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1995 }
1996 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001997 mPhone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001998 }
Junda Liu29340342014-07-10 15:23:27 -07001999
2000 @Override
Shishir Agrawal6d5a2852014-07-11 16:32:57 -07002001 public int checkCarrierPrivilegesForPackage(String pkgname) {
Shishir Agrawal21409252015-01-15 23:33:50 -08002002 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002003 if (card == null) {
2004 loge("checkCarrierPrivilegesForPackage: No UICC");
2005 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2006 }
2007 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname);
Junda Liu29340342014-07-10 15:23:27 -07002008 }
Derek Tan89e89d42014-07-08 17:00:10 -07002009
2010 @Override
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002011 public List<String> getCarrierPackageNamesForIntent(Intent intent) {
Shishir Agrawal21409252015-01-15 23:33:50 -08002012 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002013 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002014 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002015 return null ;
2016 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002017 return card.getCarrierPackageNamesForIntent(
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002018 mPhone.getContext().getPackageManager(), intent);
2019 }
2020
Wink Savilleb564aae2014-10-23 10:18:09 -07002021 private String getIccId(int subId) {
Derek Tan97ebb422014-09-05 16:55:38 -07002022 UiccCard card = getPhone(subId).getUiccCard();
2023 if (card == null) {
2024 loge("getIccId: No UICC");
2025 return null;
2026 }
2027 String iccId = card.getIccId();
2028 if (TextUtils.isEmpty(iccId)) {
2029 loge("getIccId: ICC ID is null or empty.");
2030 return null;
2031 }
2032 return iccId;
2033 }
2034
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002035 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002036 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2037 String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002038 enforceCarrierPrivilege();
Derek Tan97ebb422014-09-05 16:55:38 -07002039
Jeff Sharkey85190e62014-12-05 09:40:12 -08002040 final String iccId = getIccId(subId);
2041 final String subscriberId = getPhone(subId).getSubscriberId();
2042
2043 if (DBG_MERGE) {
2044 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2045 + subscriberId + " to " + number);
2046 }
2047
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002048 if (TextUtils.isEmpty(iccId)) {
2049 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002050 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002051
Jeff Sharkey85190e62014-12-05 09:40:12 -08002052 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2053
2054 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002055 if (alphaTag == null) {
2056 editor.remove(alphaTagPrefKey);
2057 } else {
2058 editor.putString(alphaTagPrefKey, alphaTag);
2059 }
2060
Jeff Sharkey85190e62014-12-05 09:40:12 -08002061 // Record both the line number and IMSI for this ICCID, since we need to
2062 // track all merged IMSIs based on line number
2063 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2064 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002065 if (number == null) {
2066 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002067 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002068 } else {
2069 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002070 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002072
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002073 editor.commit();
2074 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002075 }
2076
2077 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002078 public String getLine1NumberForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002079 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002080
2081 String iccId = getIccId(subId);
2082 if (iccId != null) {
2083 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002084 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002085 }
Derek Tan97ebb422014-09-05 16:55:38 -07002086 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002087 }
2088
2089 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002090 public String getLine1AlphaTagForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002091 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002092
2093 String iccId = getIccId(subId);
2094 if (iccId != null) {
2095 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002096 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002097 }
Derek Tan97ebb422014-09-05 16:55:38 -07002098 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002099 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002100
2101 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002102 public String[] getMergedSubscriberIds() {
2103 final Context context = mPhone.getContext();
2104 final TelephonyManager tele = TelephonyManager.from(context);
2105 final SubscriptionManager sub = SubscriptionManager.from(context);
2106
2107 // Figure out what subscribers are currently active
2108 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
2109 final int[] subIds = sub.getActiveSubscriptionIdList();
2110 for (int subId : subIds) {
2111 activeSubscriberIds.add(tele.getSubscriberId(subId));
2112 }
2113
2114 // First pass, find a number override for an active subscriber
2115 String mergeNumber = null;
2116 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2117 for (String key : prefs.keySet()) {
2118 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2119 final String subscriberId = (String) prefs.get(key);
2120 if (activeSubscriberIds.contains(subscriberId)) {
2121 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2122 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2123 mergeNumber = (String) prefs.get(numberKey);
2124 if (DBG_MERGE) {
2125 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2126 + " for active subscriber " + subscriberId);
2127 }
2128 if (!TextUtils.isEmpty(mergeNumber)) {
2129 break;
2130 }
2131 }
2132 }
2133 }
2134
2135 // Shortcut when no active merged subscribers
2136 if (TextUtils.isEmpty(mergeNumber)) {
2137 return null;
2138 }
2139
2140 // Second pass, find all subscribers under that line override
2141 final ArraySet<String> result = new ArraySet<>();
2142 for (String key : prefs.keySet()) {
2143 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2144 final String number = (String) prefs.get(key);
2145 if (mergeNumber.equals(number)) {
2146 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2147 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2148 final String subscriberId = (String) prefs.get(subscriberKey);
2149 if (!TextUtils.isEmpty(subscriberId)) {
2150 result.add(subscriberId);
2151 }
2152 }
2153 }
2154 }
2155
2156 final String[] resultArray = result.toArray(new String[result.size()]);
2157 Arrays.sort(resultArray);
2158 if (DBG_MERGE) {
2159 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2160 }
2161 return resultArray;
2162 }
2163
2164 @Override
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002165 public boolean setOperatorBrandOverride(String brand) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002166 enforceCarrierPrivilege();
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002167 return mPhone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002168 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002169
2170 @Override
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002171 public boolean setRoamingOverride(List<String> gsmRoamingList,
2172 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2173 List<String> cdmaNonRoamingList) {
2174 enforceCarrierPrivilege();
2175 return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
2176 cdmaNonRoamingList);
2177 }
2178
2179 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002180 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2181 enforceModifyPermission();
2182
2183 int returnValue = 0;
2184 try {
2185 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2186 if(result.exception == null) {
2187 if (result.result != null) {
2188 byte[] responseData = (byte[])(result.result);
2189 if(responseData.length > oemResp.length) {
2190 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2191 responseData.length + "bytes. Buffer Size is " +
2192 oemResp.length + "bytes.");
2193 }
2194 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2195 returnValue = responseData.length;
2196 }
2197 } else {
2198 CommandException ex = (CommandException) result.exception;
2199 returnValue = ex.getCommandError().ordinal();
2200 if(returnValue > 0) returnValue *= -1;
2201 }
2202 } catch (RuntimeException e) {
2203 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2204 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2205 if(returnValue > 0) returnValue *= -1;
2206 }
2207
2208 return returnValue;
2209 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002210
2211 @Override
2212 public void setRadioCapability(RadioAccessFamily[] rafs) {
2213 try {
2214 ProxyController.getInstance().setRadioCapability(rafs);
2215 } catch (RuntimeException e) {
2216 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2217 }
2218 }
2219
2220 @Override
2221 public int getRadioAccessFamily(int phoneId) {
2222 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2223 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002224
2225 @Override
2226 public void enableVideoCalling(boolean enable) {
2227 enforceModifyPermission();
2228 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2229 editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable);
2230 editor.commit();
2231 }
2232
2233 @Override
2234 public boolean isVideoCallingEnabled() {
2235 enforceReadPermission();
Andrew Lee77527ac2014-10-21 16:57:39 -07002236 // Check the user preference and the system-level IMS setting. Even if the user has
2237 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2238 // In the long run, we may instead need to check if there exists a connection service
2239 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002240 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2241 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
2242 && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
Andrew Leedf14ead2014-10-17 14:22:52 -07002243 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002244
Sanket Padawe7310cc72015-01-14 09:53:20 -08002245 /**
2246 * Returns the unique device ID of phone, for example, the IMEI for
2247 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2248 *
2249 * <p>Requires Permission:
2250 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2251 */
2252 @Override
2253 public String getDeviceId() {
2254 enforceReadPermission();
2255 final Phone phone = PhoneFactory.getPhone(0);
2256 if (phone != null) {
2257 return phone.getDeviceId();
2258 } else {
2259 return null;
2260 }
2261 }
2262
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002263 /*
2264 * {@hide}
2265 * Returns the IMS Registration Status
2266 */
2267 public boolean isImsRegistered() {
2268 return mPhone.isImsRegistered();
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270}