blob: 5e1ad89cb9cd7d8c451541b6bc379c94fffa86aa [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
19import android.app.ActivityManager;
20import android.app.AppOpsManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070021import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.Context;
23import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070024import android.content.SharedPreferences;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070025import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.net.Uri;
27import android.os.AsyncResult;
28import android.os.Binder;
29import android.os.Bundle;
30import android.os.Handler;
31import android.os.Looper;
32import android.os.Message;
33import android.os.Process;
34import android.os.ServiceManager;
35import android.os.UserHandle;
Derek Tan97ebb422014-09-05 16:55:38 -070036import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080037import android.provider.Settings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.telephony.CellInfo;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070039import android.telephony.IccOpenLogicalChannelResponse;
Jake Hambye994d462014-02-03 13:10:13 -080040import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070041import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080043import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080044import android.telephony.SubscriptionManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080045import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080047import android.util.ArrayMap;
48import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080050import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080051import android.util.Slog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052
Andrew Lee312e8172014-10-23 17:01:36 -070053import com.android.ims.ImsManager;
Shishir Agrawal566b7612013-10-28 14:41:00 -070054import com.android.internal.telephony.CallManager;
55import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080058import com.android.internal.telephony.IccCard;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import com.android.internal.telephony.Phone;
Wink Saville36469e72014-06-11 15:17:00 -070060import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import com.android.internal.telephony.ProxyController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import com.android.internal.telephony.PhoneConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080063import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070064import com.android.internal.telephony.uicc.IccIoResult;
65import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070066import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070067import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080068import com.android.internal.util.HexDump;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069
Wink Saville36469e72014-06-11 15:17:00 -070070import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
71
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import java.util.Arrays;
Shishir Agrawal621a47c2014-12-01 10:25:09 -080074import java.util.HashMap;
75import java.util.Iterator;
Jake Hambye994d462014-02-03 13:10:13 -080076import java.util.List;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import java.util.Map;
78import java.util.Objects;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079
80/**
81 * Implementation of the ITelephony interface.
82 */
Santos Cordon117fee72014-05-16 17:56:12 -070083public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084 private static final String LOG_TAG = "PhoneInterfaceManager";
85 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
86 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088
89 // Message codes used with mMainThreadHandler
90 private static final int CMD_HANDLE_PIN_MMI = 1;
91 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
92 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
93 private static final int CMD_ANSWER_RINGING_CALL = 4;
94 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070095 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
96 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -070097 private static final int CMD_OPEN_CHANNEL = 9;
98 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
99 private static final int CMD_CLOSE_CHANNEL = 11;
100 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800101 private static final int CMD_NV_READ_ITEM = 13;
102 private static final int EVENT_NV_READ_ITEM_DONE = 14;
103 private static final int CMD_NV_WRITE_ITEM = 15;
104 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
105 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
106 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
107 private static final int CMD_NV_RESET_CONFIG = 19;
108 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800109 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
110 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
111 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
112 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800113 private static final int CMD_SEND_ENVELOPE = 25;
114 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700115 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
116 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
117 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
118 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
119 private static final int CMD_EXCHANGE_SIM_IO = 31;
120 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800121 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
122 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123
124 /** The singleton instance. */
125 private static PhoneInterfaceManager sInstance;
126
Wink Saville3ab207e2014-11-20 13:07:20 -0800127 private PhoneGlobals mApp;
128 private Phone mPhone;
129 private CallManager mCM;
130 private AppOpsManager mAppOps;
131 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800132 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800133 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
Derek Tan97ebb422014-09-05 16:55:38 -0700135 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
136 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Andrew Leedf14ead2014-10-17 14:22:52 -0700138 private static final String PREF_ENABLE_VIDEO_CALLING = "enable_video_calling";
Derek Tan89e89d42014-07-08 17:00:10 -0700139
140 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141 * A request object to use for transmitting data to an ICC.
142 */
143 private static final class IccAPDUArgument {
144 public int channel, cla, command, p1, p2, p3;
145 public String data;
146
147 public IccAPDUArgument(int channel, int cla, int command,
148 int p1, int p2, int p3, String data) {
149 this.channel = channel;
150 this.cla = cla;
151 this.command = command;
152 this.p1 = p1;
153 this.p2 = p2;
154 this.p3 = p3;
155 this.data = data;
156 }
157 }
158
159 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
161 * request after sending. The main thread will notify the request when it is complete.
162 */
163 private static final class MainThreadRequest {
164 /** The argument to use for the request */
165 public Object argument;
166 /** The result of the request that is run on the main thread */
167 public Object result;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800168 /** The subscriber id that this request applies to. Null if default. */
169 public Integer subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170
171 public MainThreadRequest(Object argument) {
172 this.argument = argument;
173 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800174
175 public MainThreadRequest(Object argument, Integer subId) {
176 this.argument = argument;
177 this.subId = subId;
178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179 }
180
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800181 private static final class IncomingThirdPartyCallArgs {
182 public final ComponentName component;
183 public final String callId;
184 public final String callerDisplayName;
185
186 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
187 String callerDisplayName) {
188 this.component = component;
189 this.callId = callId;
190 this.callerDisplayName = callerDisplayName;
191 }
192 }
193
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 /**
195 * A handler that processes messages on the main thread in the phone process. Since many
196 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
197 * inbound binder threads to the main thread in the phone process. The Binder thread
198 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
199 * on, which will be notified when the operation completes and will contain the result of the
200 * request.
201 *
202 * <p>If a MainThreadRequest object is provided in the msg.obj field,
203 * note that request.result must be set to something non-null for the calling thread to
204 * unblock.
205 */
206 private final class MainThreadHandler extends Handler {
207 @Override
208 public void handleMessage(Message msg) {
209 MainThreadRequest request;
210 Message onCompleted;
211 AsyncResult ar;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700212 UiccCard uiccCard = UiccController.getInstance().getUiccCard();
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700213 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214
215 switch (msg.what) {
216 case CMD_HANDLE_PIN_MMI:
217 request = (MainThreadRequest) msg.obj;
Jake Hambye994d462014-02-03 13:10:13 -0800218 request.result = mPhone.handlePinMmi((String) request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219 // Wake up the requesting thread
220 synchronized (request) {
221 request.notifyAll();
222 }
223 break;
224
225 case CMD_HANDLE_NEIGHBORING_CELL:
226 request = (MainThreadRequest) msg.obj;
227 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
228 request);
229 mPhone.getNeighboringCids(onCompleted);
230 break;
231
232 case EVENT_NEIGHBORING_CELL_DONE:
233 ar = (AsyncResult) msg.obj;
234 request = (MainThreadRequest) ar.userObj;
235 if (ar.exception == null && ar.result != null) {
236 request.result = ar.result;
237 } else {
238 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800239 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 }
241 // Wake up the requesting thread
242 synchronized (request) {
243 request.notifyAll();
244 }
245 break;
246
247 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700248 request = (MainThreadRequest) msg.obj;
Wink Savilleb564aae2014-10-23 10:18:09 -0700249 int answer_subId = ((Integer)request.argument).intValue();
Wink Saville08874612014-08-31 19:19:58 -0700250 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 break;
252
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 case CMD_END_CALL:
254 request = (MainThreadRequest) msg.obj;
Wink Savilleb564aae2014-10-23 10:18:09 -0700255 int end_subId = ((Integer)request.argument).intValue();
Wink Saville08874612014-08-31 19:19:58 -0700256 final boolean hungUp;
257 int phoneType = getPhone(end_subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
259 // CDMA: If the user presses the Power button we treat it as
260 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700261 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
263 // GSM: End the call as per the Phone state
264 hungUp = PhoneUtils.hangup(mCM);
265 } else {
266 throw new IllegalStateException("Unexpected phone type: " + phoneType);
267 }
268 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
269 request.result = hungUp;
270 // Wake up the requesting thread
271 synchronized (request) {
272 request.notifyAll();
273 }
274 break;
275
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700276 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700277 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700278 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700279 if (uiccCard == null) {
280 loge("iccTransmitApduLogicalChannel: No UICC");
281 request.result = new IccIoResult(0x6F, 0, (byte[])null);
282 synchronized (request) {
283 request.notifyAll();
284 }
285 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700286 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
287 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700288 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700289 iccArgument.channel, iccArgument.cla, iccArgument.command,
290 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700291 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700292 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700293 break;
294
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700295 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700296 ar = (AsyncResult) msg.obj;
297 request = (MainThreadRequest) ar.userObj;
298 if (ar.exception == null && ar.result != null) {
299 request.result = ar.result;
300 } else {
301 request.result = new IccIoResult(0x6F, 0, (byte[])null);
302 if (ar.result == null) {
303 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800304 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800306 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700307 } else {
308 loge("iccTransmitApduLogicalChannel: Unknown exception");
309 }
310 }
311 synchronized (request) {
312 request.notifyAll();
313 }
314 break;
315
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700316 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
317 request = (MainThreadRequest) msg.obj;
318 iccArgument = (IccAPDUArgument) request.argument;
319 if (uiccCard == null) {
320 loge("iccTransmitApduBasicChannel: No UICC");
321 request.result = new IccIoResult(0x6F, 0, (byte[])null);
322 synchronized (request) {
323 request.notifyAll();
324 }
325 } else {
326 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
327 request);
328 uiccCard.iccTransmitApduBasicChannel(
329 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
330 iccArgument.p3, iccArgument.data, onCompleted);
331 }
332 break;
333
334 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
335 ar = (AsyncResult) msg.obj;
336 request = (MainThreadRequest) ar.userObj;
337 if (ar.exception == null && ar.result != null) {
338 request.result = ar.result;
339 } else {
340 request.result = new IccIoResult(0x6F, 0, (byte[])null);
341 if (ar.result == null) {
342 loge("iccTransmitApduBasicChannel: Empty response");
343 } else if (ar.exception instanceof CommandException) {
344 loge("iccTransmitApduBasicChannel: CommandException: " +
345 ar.exception);
346 } else {
347 loge("iccTransmitApduBasicChannel: Unknown exception");
348 }
349 }
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
354
355 case CMD_EXCHANGE_SIM_IO:
356 request = (MainThreadRequest) msg.obj;
357 iccArgument = (IccAPDUArgument) request.argument;
358 if (uiccCard == null) {
359 loge("iccExchangeSimIO: No UICC");
360 request.result = new IccIoResult(0x6F, 0, (byte[])null);
361 synchronized (request) {
362 request.notifyAll();
363 }
364 } else {
365 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
366 request);
367 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
368 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
369 iccArgument.data, onCompleted);
370 }
371 break;
372
373 case EVENT_EXCHANGE_SIM_IO_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 request.result = new IccIoResult(0x6f, 0, (byte[])null);
380 }
381 synchronized (request) {
382 request.notifyAll();
383 }
384 break;
385
Derek Tan4d5e5c12014-02-04 11:54:58 -0800386 case CMD_SEND_ENVELOPE:
387 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700388 if (uiccCard == null) {
389 loge("sendEnvelopeWithStatus: No UICC");
390 request.result = new IccIoResult(0x6F, 0, (byte[])null);
391 synchronized (request) {
392 request.notifyAll();
393 }
394 } else {
395 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
396 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
397 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800398 break;
399
400 case EVENT_SEND_ENVELOPE_DONE:
401 ar = (AsyncResult) msg.obj;
402 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700403 if (ar.exception == null && ar.result != null) {
404 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800405 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
407 if (ar.result == null) {
408 loge("sendEnvelopeWithStatus: Empty response");
409 } else if (ar.exception instanceof CommandException) {
410 loge("sendEnvelopeWithStatus: CommandException: " +
411 ar.exception);
412 } else {
413 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
414 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800415 }
416 synchronized (request) {
417 request.notifyAll();
418 }
419 break;
420
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 case CMD_OPEN_CHANNEL:
422 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 if (uiccCard == null) {
424 loge("iccOpenLogicalChannel: No UICC");
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
426 synchronized (request) {
427 request.notifyAll();
428 }
429 } else {
430 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
431 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 break;
434
435 case EVENT_OPEN_CHANNEL_DONE:
436 ar = (AsyncResult) msg.obj;
437 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 int[] result = (int[]) ar.result;
441 int channelId = result[0];
442 byte[] selectResponse = null;
443 if (result.length > 1) {
444 selectResponse = new byte[result.length - 1];
445 for (int i = 1; i < result.length; ++i) {
446 selectResponse[i - 1] = (byte) result[i];
447 }
448 }
449 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700450 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 if (ar.result == null) {
453 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 if (ar.exception != null) {
456 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
457 }
458
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700459 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if ((ar.exception != null) && (ar.exception instanceof CommandException)) {
461 if (ar.exception.getMessage().compareTo("MISSING_RESOURCE") == 0) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700462 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 } else if (ar.exception.getMessage().compareTo("NO_SUCH_ELEMENT") == 0) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700464 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 }
466 }
467 openChannelResp = new IccOpenLogicalChannelResponse(
468 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700470 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 synchronized (request) {
472 request.notifyAll();
473 }
474 break;
475
476 case CMD_CLOSE_CHANNEL:
477 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700478 if (uiccCard == null) {
479 loge("iccCloseLogicalChannel: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
481 synchronized (request) {
482 request.notifyAll();
483 }
484 } else {
485 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
486 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 break;
489
490 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800491 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
492 break;
493
494 case CMD_NV_READ_ITEM:
495 request = (MainThreadRequest) msg.obj;
496 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
497 mPhone.nvReadItem((Integer) request.argument, onCompleted);
498 break;
499
500 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800506 request.result = "";
507 if (ar.result == null) {
508 loge("nvReadItem: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("nvReadItem: CommandException: " +
511 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800513 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 }
515 }
516 synchronized (request) {
517 request.notifyAll();
518 }
519 break;
520
Jake Hambye994d462014-02-03 13:10:13 -0800521 case CMD_NV_WRITE_ITEM:
522 request = (MainThreadRequest) msg.obj;
523 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
524 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
525 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
526 break;
527
528 case EVENT_NV_WRITE_ITEM_DONE:
529 handleNullReturnEvent(msg, "nvWriteItem");
530 break;
531
532 case CMD_NV_WRITE_CDMA_PRL:
533 request = (MainThreadRequest) msg.obj;
534 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
535 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
536 break;
537
538 case EVENT_NV_WRITE_CDMA_PRL_DONE:
539 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
540 break;
541
542 case CMD_NV_RESET_CONFIG:
543 request = (MainThreadRequest) msg.obj;
544 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
545 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
546 break;
547
548 case EVENT_NV_RESET_CONFIG_DONE:
549 handleNullReturnEvent(msg, "nvResetConfig");
550 break;
551
Jake Hamby7c27be32014-03-03 13:25:59 -0800552 case CMD_GET_PREFERRED_NETWORK_TYPE:
553 request = (MainThreadRequest) msg.obj;
554 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
555 mPhone.getPreferredNetworkType(onCompleted);
556 break;
557
558 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
561 if (ar.exception == null && ar.result != null) {
562 request.result = ar.result; // Integer
563 } else {
564 request.result = -1;
565 if (ar.result == null) {
566 loge("getPreferredNetworkType: Empty response");
567 } else if (ar.exception instanceof CommandException) {
568 loge("getPreferredNetworkType: CommandException: " +
569 ar.exception);
570 } else {
571 loge("getPreferredNetworkType: Unknown exception");
572 }
573 }
574 synchronized (request) {
575 request.notifyAll();
576 }
577 break;
578
579 case CMD_SET_PREFERRED_NETWORK_TYPE:
580 request = (MainThreadRequest) msg.obj;
581 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
582 int networkType = (Integer) request.argument;
583 mPhone.setPreferredNetworkType(networkType, onCompleted);
584 break;
585
586 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
587 handleNullReturnEvent(msg, "setPreferredNetworkType");
588 break;
589
Steven Liu4bf01bc2014-07-17 11:05:29 -0500590 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
591 request = (MainThreadRequest)msg.obj;
592 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
593 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
594 break;
595
596 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
597 ar = (AsyncResult)msg.obj;
598 request = (MainThreadRequest)ar.userObj;
599 request.result = ar;
600 synchronized (request) {
601 request.notifyAll();
602 }
603 break;
604
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800605 case CMD_SET_VOICEMAIL_NUMBER:
606 request = (MainThreadRequest) msg.obj;
607 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
608 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
609 Phone phone = (request.subId == null) ? mPhone : getPhone(request.subId);
610 phone.setVoiceMailNumber(tagNum.first, tagNum.second, onCompleted);
611 break;
612
613 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
614 handleNullReturnEvent(msg, "setVoicemailNumber");
615 break;
616
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 default:
618 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
619 break;
620 }
621 }
Jake Hambye994d462014-02-03 13:10:13 -0800622
623 private void handleNullReturnEvent(Message msg, String command) {
624 AsyncResult ar = (AsyncResult) msg.obj;
625 MainThreadRequest request = (MainThreadRequest) ar.userObj;
626 if (ar.exception == null) {
627 request.result = true;
628 } else {
629 request.result = false;
630 if (ar.exception instanceof CommandException) {
631 loge(command + ": CommandException: " + ar.exception);
632 } else {
633 loge(command + ": Unknown exception");
634 }
635 }
636 synchronized (request) {
637 request.notifyAll();
638 }
639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700640 }
641
642 /**
643 * Posts the specified command to be executed on the main thread,
644 * waits for the request to complete, and returns the result.
645 * @see #sendRequestAsync
646 */
647 private Object sendRequest(int command, Object argument) {
Santos Cordon500b0e02014-06-17 10:33:33 -0700648 return sendRequest(command, argument, null);
Wink Saville36469e72014-06-11 15:17:00 -0700649 }
650
651 /**
652 * Posts the specified command to be executed on the main thread,
653 * waits for the request to complete, and returns the result.
654 * @see #sendRequestAsync
655 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800656 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700657 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
658 throw new RuntimeException("This method will deadlock if called from the main thread.");
659 }
660
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800661 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700662 Message msg = mMainThreadHandler.obtainMessage(command, request);
663 msg.sendToTarget();
664
665 // Wait for the request to complete
666 synchronized (request) {
667 while (request.result == null) {
668 try {
669 request.wait();
670 } catch (InterruptedException e) {
671 // Do nothing, go back and wait until the request is complete
672 }
673 }
674 }
675 return request.result;
676 }
677
678 /**
679 * Asynchronous ("fire and forget") version of sendRequest():
680 * Posts the specified command to be executed on the main thread, and
681 * returns immediately.
682 * @see #sendRequest
683 */
684 private void sendRequestAsync(int command) {
685 mMainThreadHandler.sendEmptyMessage(command);
686 }
687
688 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700689 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
690 * @see {@link #sendRequest(int,Object)}
691 */
692 private void sendRequestAsync(int command, Object argument) {
693 MainThreadRequest request = new MainThreadRequest(argument);
694 Message msg = mMainThreadHandler.obtainMessage(command, request);
695 msg.sendToTarget();
696 }
697
698 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700699 * Initialize the singleton PhoneInterfaceManager instance.
700 * This is only done once, at startup, from PhoneApp.onCreate().
701 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700702 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700703 synchronized (PhoneInterfaceManager.class) {
704 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700705 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700706 } else {
707 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
708 }
709 return sInstance;
710 }
711 }
712
713 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700714 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700715 mApp = app;
716 mPhone = phone;
717 mCM = PhoneGlobals.getInstance().mCM;
718 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
719 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700720 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700721 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800722 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800723
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700724 publish();
725 }
726
727 private void publish() {
728 if (DBG) log("publish: " + this);
729
730 ServiceManager.addService("phone", this);
731 }
732
Wink Saville36469e72014-06-11 15:17:00 -0700733 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700734 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800735 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700737 //
738 // Implementation of the ITelephony interface.
739 //
740
741 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700742 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700743 }
744
Wink Savilleb564aae2014-10-23 10:18:09 -0700745 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700746 if (DBG) log("dial: " + number);
747 // No permission check needed here: This is just a wrapper around the
748 // ACTION_DIAL intent, which is available to any app since it puts up
749 // the UI before it does anything.
750
751 String url = createTelUrl(number);
752 if (url == null) {
753 return;
754 }
755
756 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -0700757 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
759 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
760 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
761 mApp.startActivity(intent);
762 }
763 }
764
765 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700766 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -0700767 }
768
Wink Savilleb564aae2014-10-23 10:18:09 -0700769 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700770 if (DBG) log("call: " + number);
771
772 // This is just a wrapper around the ACTION_CALL intent, but we still
773 // need to do a permission check since we're calling startActivity()
774 // from the context of the phone app.
775 enforceCallPermission();
776
777 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
778 != AppOpsManager.MODE_ALLOWED) {
779 return;
780 }
781
782 String url = createTelUrl(number);
783 if (url == null) {
784 return;
785 }
786
Wink Saville08874612014-08-31 19:19:58 -0700787 boolean isValid = false;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800788 List<SubscriptionInfo> slist = mSubscriptionController.getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -0800789 if (slist != null) {
790 for (SubscriptionInfo subInfoRecord : slist) {
791 if (subInfoRecord.getSubscriptionId() == subId) {
792 isValid = true;
793 break;
794 }
Wink Saville08874612014-08-31 19:19:58 -0700795 }
796 }
797 if (isValid == false) {
798 return;
799 }
800
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700801 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -0700802 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
804 mApp.startActivity(intent);
805 }
806
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700807 /**
808 * End a call based on call state
809 * @return true is a call was ended
810 */
811 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700812 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700813 }
814
815 /**
816 * End a call based on the call state of the subId
817 * @return true is a call was ended
818 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700819 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700820 enforceCallPermission();
Wink Saville9f73bda2014-11-05 08:13:36 -0800821 return (Boolean) sendRequest(CMD_END_CALL, new Integer(subId), null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700822 }
823
824 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700825 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700826 }
827
Wink Savilleb564aae2014-10-23 10:18:09 -0700828 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700829 if (DBG) log("answerRingingCall...");
830 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
831 // but that can probably wait till the big TelephonyManager API overhaul.
832 // For now, protect this call with the MODIFY_PHONE_STATE permission.
833 enforceModifyPermission();
Wink Saville9f73bda2014-11-05 08:13:36 -0800834 sendRequest(CMD_ANSWER_RINGING_CALL, new Integer(subId), null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700835 }
836
837 /**
838 * Make the actual telephony calls to implement answerRingingCall().
839 * This should only be called from the main thread of the Phone app.
840 * @see #answerRingingCall
841 *
842 * TODO: it would be nice to return true if we answered the call, or
843 * false if there wasn't actually a ringing incoming call, or some
844 * other error occurred. (In other words, pass back the return value
845 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
846 * But that would require calling this method via sendRequest() rather
847 * than sendRequestAsync(), and right now we don't actually *need* that
848 * return value, so let's just return void for now.
849 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700850 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -0700851 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700852 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -0700853 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
854 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700855 if (hasActiveCall && hasHoldingCall) {
856 // Both lines are in use!
857 // TODO: provide a flag to let the caller specify what
858 // policy to use if both lines are in use. (The current
859 // behavior is hardwired to "answer incoming, end ongoing",
860 // which is how the CALL button is specced to behave.)
861 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
862 return;
863 } else {
864 // answerCall() will automatically hold the current active
865 // call, if there is one.
866 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
867 return;
868 }
869 } else {
870 // No call was ringing.
871 return;
872 }
873 }
874
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700875 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -0700876 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700877 */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700878 public void silenceRinger() {
879 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700880 }
881
882 public boolean isOffhook() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700883 return isOffhookForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700884 }
885
Wink Savilleb564aae2014-10-23 10:18:09 -0700886 public boolean isOffhookForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700887 return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700888 }
889
890 public boolean isRinging() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700891 return (isRingingForSubscriber(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -0700892 }
893
Wink Savilleb564aae2014-10-23 10:18:09 -0700894 public boolean isRingingForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700895 return (getPhone(subId).getState() == PhoneConstants.State.RINGING);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 }
897
898 public boolean isIdle() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700899 return isIdleForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700900 }
901
Wink Savilleb564aae2014-10-23 10:18:09 -0700902 public boolean isIdleForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -0700903 return (getPhone(subId).getState() == PhoneConstants.State.IDLE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700904 }
905
906 public boolean isSimPinEnabled() {
907 enforceReadPermission();
908 return (PhoneGlobals.getInstance().isSimPinEnabled());
909 }
910
911 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700912 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700913 }
914
Wink Savilleb564aae2014-10-23 10:18:09 -0700915 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700916 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700917 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
918 }
919
920 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700921 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700922 }
923
Wink Savilleb564aae2014-10-23 10:18:09 -0700924 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700925 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -0700926 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
927 }
928
929 /** {@hide} */
930 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700931 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700932 }
933
Wink Savilleb564aae2014-10-23 10:18:09 -0700934 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700935 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700936 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700937 checkSimPin.start();
938 return checkSimPin.unlockSim(null, pin);
939 }
940
Wink Saville9de0f752013-10-22 19:04:03 -0700941 /** {@hide} */
942 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700943 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -0700944 }
945
Wink Savilleb564aae2014-10-23 10:18:09 -0700946 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -0700948 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949 checkSimPuk.start();
950 return checkSimPuk.unlockSim(puk, pin);
951 }
952
953 /**
Wink Saville9de0f752013-10-22 19:04:03 -0700954 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700955 * a synchronous one.
956 */
957 private static class UnlockSim extends Thread {
958
959 private final IccCard mSimCard;
960
961 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -0700962 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
963 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700964
965 // For replies from SimCard interface
966 private Handler mHandler;
967
968 // For async handler to identify request type
969 private static final int SUPPLY_PIN_COMPLETE = 100;
970
971 public UnlockSim(IccCard simCard) {
972 mSimCard = simCard;
973 }
974
975 @Override
976 public void run() {
977 Looper.prepare();
978 synchronized (UnlockSim.this) {
979 mHandler = new Handler() {
980 @Override
981 public void handleMessage(Message msg) {
982 AsyncResult ar = (AsyncResult) msg.obj;
983 switch (msg.what) {
984 case SUPPLY_PIN_COMPLETE:
985 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
986 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -0700987 mRetryCount = msg.arg1;
988 if (ar.exception != null) {
989 if (ar.exception instanceof CommandException &&
990 ((CommandException)(ar.exception)).getCommandError()
991 == CommandException.Error.PASSWORD_INCORRECT) {
992 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
993 } else {
994 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
995 }
996 } else {
997 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700999 mDone = true;
1000 UnlockSim.this.notifyAll();
1001 }
1002 break;
1003 }
1004 }
1005 };
1006 UnlockSim.this.notifyAll();
1007 }
1008 Looper.loop();
1009 }
1010
1011 /*
1012 * Use PIN or PUK to unlock SIM card
1013 *
1014 * If PUK is null, unlock SIM card with PIN
1015 *
1016 * If PUK is not null, unlock SIM card with PUK and set PIN code
1017 */
Wink Saville9de0f752013-10-22 19:04:03 -07001018 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001019
1020 while (mHandler == null) {
1021 try {
1022 wait();
1023 } catch (InterruptedException e) {
1024 Thread.currentThread().interrupt();
1025 }
1026 }
1027 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1028
1029 if (puk == null) {
1030 mSimCard.supplyPin(pin, callback);
1031 } else {
1032 mSimCard.supplyPuk(puk, pin, callback);
1033 }
1034
1035 while (!mDone) {
1036 try {
1037 Log.d(LOG_TAG, "wait for done");
1038 wait();
1039 } catch (InterruptedException e) {
1040 // Restore the interrupted status
1041 Thread.currentThread().interrupt();
1042 }
1043 }
1044 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001045 int[] resultArray = new int[2];
1046 resultArray[0] = mResult;
1047 resultArray[1] = mRetryCount;
1048 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001049 }
1050 }
1051
1052 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001053 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001054
1055 }
1056
Wink Savilleb564aae2014-10-23 10:18:09 -07001057 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 // No permission check needed here: this call is harmless, and it's
1059 // needed for the ServiceState.requestStateUpdate() call (which is
1060 // already intentionally exposed to 3rd parties.)
Wink Saville36469e72014-06-11 15:17:00 -07001061 getPhone(subId).updateServiceLocation();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 }
1063
1064 public boolean isRadioOn() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001065 return isRadioOnForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001066 }
1067
Wink Savilleb564aae2014-10-23 10:18:09 -07001068 public boolean isRadioOnForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001069 return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 }
1071
1072 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001073 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001074
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001075 }
Wink Saville36469e72014-06-11 15:17:00 -07001076
Wink Savilleb564aae2014-10-23 10:18:09 -07001077 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 enforceModifyPermission();
Wink Savilleadd7cc52014-09-08 14:23:09 -07001079 getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001080 }
1081
1082 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001083 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001084 }
1085
Wink Savilleb564aae2014-10-23 10:18:09 -07001086 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001087 enforceModifyPermission();
1088 if ((getPhone(subId).getServiceState().getState() !=
1089 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001090 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 }
1092 return true;
1093 }
Wink Saville36469e72014-06-11 15:17:00 -07001094
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001095 public boolean needMobileRadioShutdown() {
1096 /*
1097 * If any of the Radios are available, it will need to be
1098 * shutdown. So return true if any Radio is available.
1099 */
1100 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1101 Phone phone = PhoneFactory.getPhone(i);
1102 if (phone != null && phone.isRadioAvailable()) return true;
1103 }
1104 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1105 return false;
1106 }
1107
1108 public void shutdownMobileRadios() {
1109 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1110 logv("Shutting down Phone " + i);
1111 shutdownRadioUsingPhoneId(i);
1112 }
1113 }
1114
1115 private void shutdownRadioUsingPhoneId(int phoneId) {
1116 enforceModifyPermission();
1117 Phone phone = PhoneFactory.getPhone(phoneId);
1118 if (phone != null && phone.isRadioAvailable()) {
1119 phone.shutdownRadio();
1120 }
1121 }
1122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 public boolean setRadioPower(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001124 return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001125 }
1126
Wink Savilleb564aae2014-10-23 10:18:09 -07001127 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001129 getPhone(subId).setRadioPower(turnOn);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 return true;
1131 }
1132
Wink Saville36469e72014-06-11 15:17:00 -07001133 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 public boolean enableDataConnectivity() {
1135 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001136 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001137 getPhone(subId).setDataEnabled(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 return true;
1139 }
1140
Wink Saville36469e72014-06-11 15:17:00 -07001141 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 public boolean disableDataConnectivity() {
1143 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001144 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001145 getPhone(subId).setDataEnabled(false);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001146 return true;
1147 }
1148
Wink Saville36469e72014-06-11 15:17:00 -07001149 // FIXME: subId version needed
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001151 int subId = mSubscriptionController.getDefaultDataSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001152 return getPhone(subId).isDataConnectivityPossible();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 }
1154
1155 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001156 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001157 }
1158
Wink Savilleb564aae2014-10-23 10:18:09 -07001159 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001161 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 }
1163
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 public int getCallState() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001165 return getCallStateForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001166 }
1167
Wink Savilleb564aae2014-10-23 10:18:09 -07001168 public int getCallStateForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001169 return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 }
1171
1172 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001173 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001174 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 }
1176
1177 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001178 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Wink Saville36469e72014-06-11 15:17:00 -07001179 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 }
1181
1182 @Override
1183 public Bundle getCellLocation() {
1184 try {
1185 mApp.enforceCallingOrSelfPermission(
1186 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1187 } catch (SecurityException e) {
1188 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1189 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1190 // is the weaker precondition
1191 mApp.enforceCallingOrSelfPermission(
1192 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1193 }
1194
Jake Hambye994d462014-02-03 13:10:13 -08001195 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 if (DBG_LOC) log("getCellLocation: is active user");
1197 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001198 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1199 phone.getCellLocation().fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 return data;
1201 } else {
1202 if (DBG_LOC) log("getCellLocation: suppress non-active user");
1203 return null;
1204 }
1205 }
1206
1207 @Override
1208 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001209 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001210 }
1211
Wink Savilleb564aae2014-10-23 10:18:09 -07001212 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 mApp.enforceCallingOrSelfPermission(
1214 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001215 getPhone(subId).enableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217
1218 @Override
1219 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001220 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001221 }
1222
Wink Savilleb564aae2014-10-23 10:18:09 -07001223 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 mApp.enforceCallingOrSelfPermission(
1225 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001226 getPhone(subId).disableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 }
1228
1229 @Override
1230 @SuppressWarnings("unchecked")
1231 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1232 try {
1233 mApp.enforceCallingOrSelfPermission(
1234 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1235 } catch (SecurityException e) {
1236 // If we have ACCESS_FINE_LOCATION permission, skip the check
1237 // for ACCESS_COARSE_LOCATION
1238 // A failure should throw the SecurityException from
1239 // ACCESS_COARSE_LOCATION since this is the weaker precondition
1240 mApp.enforceCallingOrSelfPermission(
1241 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1242 }
1243
1244 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1245 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1246 return null;
1247 }
Jake Hambye994d462014-02-03 13:10:13 -08001248 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1250
1251 ArrayList<NeighboringCellInfo> cells = null;
1252
1253 try {
1254 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Wink Saville36469e72014-06-11 15:17:00 -07001255 CMD_HANDLE_NEIGHBORING_CELL, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001257 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259 return cells;
1260 } else {
1261 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1262 return null;
1263 }
1264 }
1265
1266
1267 @Override
1268 public List<CellInfo> getAllCellInfo() {
1269 try {
1270 mApp.enforceCallingOrSelfPermission(
1271 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1272 } catch (SecurityException e) {
1273 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1274 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1275 // is the weaker precondition
1276 mApp.enforceCallingOrSelfPermission(
1277 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1278 }
1279
Jake Hambye994d462014-02-03 13:10:13 -08001280 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 if (DBG_LOC) log("getAllCellInfo: is active user");
Legler Wu2c01cdf2014-12-08 19:00:59 +08001282 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1283 for (Phone phone : PhoneFactory.getPhones()) {
1284 cellInfos.addAll(phone.getAllCellInfo());
1285 }
1286 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 } else {
1288 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1289 return null;
1290 }
1291 }
1292
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001293 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 public void setCellInfoListRate(int rateInMillis) {
1295 mPhone.setCellInfoListRate(rateInMillis);
1296 }
1297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 //
1299 // Internal helper methods.
1300 //
1301
Jake Hambye994d462014-02-03 13:10:13 -08001302 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 boolean ok;
1304
1305 boolean self = Binder.getCallingUid() == Process.myUid();
1306 if (!self) {
1307 // Get the caller's user id then clear the calling identity
1308 // which will be restored in the finally clause.
1309 int callingUser = UserHandle.getCallingUserId();
1310 long ident = Binder.clearCallingIdentity();
1311
1312 try {
1313 // With calling identity cleared the current user is the foreground user.
1314 int foregroundUser = ActivityManager.getCurrentUser();
1315 ok = (foregroundUser == callingUser);
1316 if (DBG_LOC) {
1317 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1318 + " callingUser=" + callingUser + " ok=" + ok);
1319 }
1320 } catch (Exception ex) {
1321 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1322 ok = false;
1323 } finally {
1324 Binder.restoreCallingIdentity(ident);
1325 }
1326 } else {
1327 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1328 ok = true;
1329 }
1330 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1331 return ok;
1332 }
1333
1334 /**
1335 * Make sure the caller has the READ_PHONE_STATE permission.
1336 *
1337 * @throws SecurityException if the caller does not have the required permission
1338 */
1339 private void enforceReadPermission() {
1340 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
1341 }
1342
1343 /**
1344 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1345 *
1346 * @throws SecurityException if the caller does not have the required permission
1347 */
1348 private void enforceModifyPermission() {
1349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1350 }
1351
1352 /**
Junda Liua2e36012014-07-09 18:30:01 -07001353 * Make sure either system app or the caller has carrier privilege.
1354 *
1355 * @throws SecurityException if the caller does not have the required permission/privilege
1356 */
1357 private void enforceModifyPermissionOrCarrierPrivilege() {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001358 int permission = mApp.checkCallingOrSelfPermission(
1359 android.Manifest.permission.MODIFY_PHONE_STATE);
1360 if (permission == PackageManager.PERMISSION_GRANTED) {
1361 return;
1362 }
1363
1364 log("No modify permission, check carrier privilege next.");
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001365 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001366 loge("No Carrier Privilege.");
1367 throw new SecurityException("No modify permission or carrier privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001368 }
1369 }
1370
1371 /**
1372 * Make sure the caller has carrier privilege.
1373 *
1374 * @throws SecurityException if the caller does not have the required permission
1375 */
1376 private void enforceCarrierPrivilege() {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001377 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001378 loge("No Carrier Privilege.");
1379 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001380 }
1381 }
1382
1383 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 * Make sure the caller has the CALL_PHONE permission.
1385 *
1386 * @throws SecurityException if the caller does not have the required permission
1387 */
1388 private void enforceCallPermission() {
1389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1390 }
1391
Shishir Agrawal566b7612013-10-28 14:41:00 -07001392 /**
Gabriel Peal36ebb0d2014-03-20 09:20:43 -07001393 * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission.
1394 *
1395 * @throws SecurityException if the caller does not have the required permission
1396 */
1397 private void enforcePrivilegedPhoneStatePermission() {
1398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1399 null);
1400 }
1401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 private String createTelUrl(String number) {
1403 if (TextUtils.isEmpty(number)) {
1404 return null;
1405 }
1406
Jake Hambye994d462014-02-03 13:10:13 -08001407 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 }
1409
Ihab Awadf9e92732013-12-05 18:02:52 -08001410 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1412 }
1413
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001414 private static void logv(String msg) {
1415 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1416 }
1417
Ihab Awadf9e92732013-12-05 18:02:52 -08001418 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1420 }
1421
1422 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public int getActivePhoneTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001427 return getPhone(subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 }
1429
1430 /**
1431 * Returns the CDMA ERI icon index to display
1432 */
1433 public int getCdmaEriIconIndex() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001434 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001435
1436 }
1437
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 public int getCdmaEriIconIndexForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001439 return getPhone(subId).getCdmaEriIconIndex();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
1442 /**
1443 * Returns the CDMA ERI icon mode,
1444 * 0 - ON
1445 * 1 - FLASHING
1446 */
1447 public int getCdmaEriIconMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001448 return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public int getCdmaEriIconModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001452 return getPhone(subId).getCdmaEriIconMode();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 }
1454
1455 /**
1456 * Returns the CDMA ERI text,
1457 */
1458 public String getCdmaEriText() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return getCdmaEriTextForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public String getCdmaEriTextForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001463 return getPhone(subId).getCdmaEriText();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 }
1465
1466 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001467 * Returns the CDMA MDN.
1468 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001469 public String getCdmaMdn(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001470 enforceModifyPermissionOrCarrierPrivilege();
1471 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1472 return getPhone(subId).getLine1Number();
1473 } else {
1474 return null;
1475 }
1476 }
1477
1478 /**
1479 * Returns the CDMA MIN.
1480 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001481 public String getCdmaMin(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001482 enforceModifyPermissionOrCarrierPrivilege();
1483 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1484 return getPhone(subId).getCdmaMin();
1485 } else {
1486 return null;
1487 }
1488 }
1489
1490 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 * Returns true if CDMA provisioning needs to run.
1492 */
1493 public boolean needsOtaServiceProvisioning() {
1494 return mPhone.needsOtaServiceProvisioning();
1495 }
1496
1497 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001498 * Sets the voice mail number of a given subId.
1499 */
1500 @Override
1501 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001502 enforceCarrierPrivilege();
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001503 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1504 new Pair<String, String>(alphaTag, number), new Integer(subId));
1505 return success;
1506 }
1507
1508 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 * Returns the unread count of voicemails
1510 */
1511 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
1515 /**
1516 * Returns the unread count of voicemails for a subId
1517 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001518 public int getVoiceMessageCountForSubscriber( int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001519 return getPhone(subId).getVoiceMessageCount();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521
1522 /**
1523 * Returns the data network type
1524 *
1525 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1526 */
1527 @Override
1528 public int getNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001529 return getNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
1532 /**
1533 * Returns the network type for a subId
1534 */
1535 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public int getNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001537 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 }
1539
1540 /**
1541 * Returns the data network type
1542 */
1543 @Override
1544 public int getDataNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 return getDataNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
1548 /**
1549 * Returns the data network type for a subId
1550 */
1551 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public int getDataNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001553 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 /**
1557 * Returns the data network type
1558 */
1559 @Override
1560 public int getVoiceNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001561 return getVoiceNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001562 }
1563
1564 /**
1565 * Returns the Voice network type for a subId
1566 */
1567 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001568 public int getVoiceNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001569 return getPhone(subId).getServiceState().getVoiceNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 /**
1573 * @return true if a ICC card is present
1574 */
1575 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001576 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001577 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
1580 /**
1581 * @return true if a ICC card is present for a slotId
1582 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001583 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001584 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
1585 if (subId != null) {
1586 return getPhone(subId[0]).getIccCard().hasIccCard();
1587 } else {
1588 return false;
1589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
1592 /**
1593 * Return if the current radio is LTE on CDMA. This
1594 * is a tri-state return value as for a period of time
1595 * the mode may be unknown.
1596 *
1597 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001598 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 */
1600 public int getLteOnCdmaMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001601 return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001602 }
1603
Wink Savilleb564aae2014-10-23 10:18:09 -07001604 public int getLteOnCdmaModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001605 return getPhone(subId).getLteOnCdmaMode();
1606 }
1607
1608 public void setPhone(Phone phone) {
1609 mPhone = phone;
1610 }
1611
1612 /**
1613 * {@hide}
1614 * Returns Default subId, 0 in the case of single standby.
1615 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001616 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001617 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001618 }
1619
Wink Savilleb564aae2014-10-23 10:18:09 -07001620 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001621 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001623
1624 /**
1625 * @see android.telephony.TelephonyManager.WifiCallingChoices
1626 */
1627 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001628 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1629 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001630 }
1631
1632 /**
1633 * @see android.telephony.TelephonyManager.WifiCallingChoices
1634 */
1635 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001636 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1637 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1638 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001639 }
1640
Sailesh Nepald1e68152013-12-12 19:08:02 -08001641 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001642 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001643 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001644 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001645
Shishir Agrawal566b7612013-10-28 14:41:00 -07001646 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001647 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
Junda Liua2e36012014-07-09 18:30:01 -07001648 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001649
1650 if (DBG) log("iccOpenLogicalChannel: " + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001651 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
1652 CMD_OPEN_CHANNEL, AID);
1653 if (DBG) log("iccOpenLogicalChannel: " + response);
1654 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001655 }
1656
1657 @Override
1658 public boolean iccCloseLogicalChannel(int channel) {
Junda Liua2e36012014-07-09 18:30:01 -07001659 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001660
1661 if (DBG) log("iccCloseLogicalChannel: " + channel);
1662 if (channel < 0) {
1663 return false;
1664 }
Jake Hambye994d462014-02-03 13:10:13 -08001665 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001666 if (DBG) log("iccCloseLogicalChannel: " + success);
1667 return success;
1668 }
1669
1670 @Override
1671 public String iccTransmitApduLogicalChannel(int channel, int cla,
1672 int command, int p1, int p2, int p3, String data) {
Junda Liua2e36012014-07-09 18:30:01 -07001673 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001674
1675 if (DBG) {
1676 log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla +
1677 " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
1678 " data=" + data);
1679 }
1680
1681 if (channel < 0) {
1682 return "";
1683 }
1684
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001685 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawal566b7612013-10-28 14:41:00 -07001686 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data));
1687 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
1688
Shishir Agrawal566b7612013-10-28 14:41:00 -07001689 // Append the returned status code to the end of the response payload.
1690 String s = Integer.toHexString(
1691 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001692 if (response.payload != null) {
1693 s = IccUtils.bytesToHexString(response.payload) + s;
1694 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001695 return s;
1696 }
Jake Hambye994d462014-02-03 13:10:13 -08001697
Evan Charltonc66da362014-05-16 14:06:40 -07001698 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001699 public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2,
1700 int p3, String data) {
1701 enforceModifyPermissionOrCarrierPrivilege();
1702
1703 if (DBG) {
1704 log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1="
1705 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
1706 }
1707
1708 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
1709 new IccAPDUArgument(0, cla, command, p1, p2, p3, data));
1710 if (DBG) log("iccTransmitApduBasicChannel: " + response);
1711
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001712 // Append the returned status code to the end of the response payload.
1713 String s = Integer.toHexString(
1714 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001715 if (response.payload != null) {
1716 s = IccUtils.bytesToHexString(response.payload) + s;
1717 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001718 return s;
1719 }
1720
1721 @Override
1722 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
1723 String filePath) {
1724 enforceModifyPermissionOrCarrierPrivilege();
1725
1726 if (DBG) {
1727 log("Exchange SIM_IO " + fileID + ":" + command + " " +
1728 p1 + " " + p2 + " " + p3 + ":" + filePath);
1729 }
1730
1731 IccIoResult response =
1732 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Yong Jiang3edf3782014-10-03 13:23:28 -05001733 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath));
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001734
1735 if (DBG) {
1736 log("Exchange SIM_IO [R]" + response);
1737 }
1738
1739 byte[] result = null;
1740 int length = 2;
1741 if (response.payload != null) {
1742 length = 2 + response.payload.length;
1743 result = new byte[length];
1744 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
1745 } else {
1746 result = new byte[length];
1747 }
1748
1749 result[length - 1] = (byte) response.sw2;
1750 result[length - 2] = (byte) response.sw1;
1751 return result;
1752 }
1753
1754 @Override
Evan Charltonc66da362014-05-16 14:06:40 -07001755 public String sendEnvelopeWithStatus(String content) {
Junda Liua2e36012014-07-09 18:30:01 -07001756 enforceModifyPermissionOrCarrierPrivilege();
Evan Charltonc66da362014-05-16 14:06:40 -07001757
1758 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content);
1759 if (response.payload == null) {
1760 return "";
1761 }
1762
1763 // Append the returned status code to the end of the response payload.
1764 String s = Integer.toHexString(
1765 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
1766 s = IccUtils.bytesToHexString(response.payload) + s;
1767 return s;
1768 }
1769
Jake Hambye994d462014-02-03 13:10:13 -08001770 /**
1771 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1772 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1773 *
1774 * @param itemID the ID of the item to read
1775 * @return the NV item as a String, or null on error.
1776 */
1777 @Override
1778 public String nvReadItem(int itemID) {
Junda Liua2e36012014-07-09 18:30:01 -07001779 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001780 if (DBG) log("nvReadItem: item " + itemID);
1781 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
1782 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
1783 return value;
1784 }
1785
1786 /**
1787 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1788 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1789 *
1790 * @param itemID the ID of the item to read
1791 * @param itemValue the value to write, as a String
1792 * @return true on success; false on any failure
1793 */
1794 @Override
1795 public boolean nvWriteItem(int itemID, String itemValue) {
Junda Liua2e36012014-07-09 18:30:01 -07001796 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001797 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
1798 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
1799 new Pair<Integer, String>(itemID, itemValue));
1800 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
1801 return success;
1802 }
1803
1804 /**
1805 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
1806 * Used for device configuration by some CDMA operators.
1807 *
1808 * @param preferredRoamingList byte array containing the new PRL
1809 * @return true on success; false on any failure
1810 */
1811 @Override
1812 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Junda Liua2e36012014-07-09 18:30:01 -07001813 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001814 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
1815 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
1816 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
1817 return success;
1818 }
1819
1820 /**
1821 * Perform the specified type of NV config reset.
1822 * Used for device configuration by some CDMA operators.
1823 *
1824 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
1825 * @return true on success; false on any failure
1826 */
1827 @Override
1828 public boolean nvResetConfig(int resetType) {
Junda Liua2e36012014-07-09 18:30:01 -07001829 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001830 if (DBG) log("nvResetConfig: type " + resetType);
1831 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
1832 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
1833 return success;
1834 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001835
1836 /**
Wink Saville36469e72014-06-11 15:17:00 -07001837 * {@hide}
1838 * Returns Default sim, 0 in the case of single standby.
1839 */
1840 public int getDefaultSim() {
1841 //TODO Need to get it from Telephony Devcontroller
1842 return 0;
1843 }
1844
ram87fca6f2014-07-18 18:58:44 +05301845 public String[] getPcscfAddress(String apnType) {
Wink Saville36469e72014-06-11 15:17:00 -07001846 enforceReadPermission();
ram87fca6f2014-07-18 18:58:44 +05301847 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
1850 public void setImsRegistrationState(boolean registered) {
1851 enforceModifyPermission();
1852 mPhone.setImsRegistrationState(registered);
1853 }
1854
1855 /**
Junda Liu84d15a22014-07-02 11:21:04 -07001856 * Get the calculated preferred network type.
1857 * Used for debugging incorrect network type.
1858 *
1859 * @return the preferred network type, defined in RILConstants.java.
1860 */
1861 @Override
1862 public int getCalculatedPreferredNetworkType() {
1863 enforceReadPermission();
Amit Mahajan43330e02014-11-18 11:54:45 -08001864 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07001865 }
1866
1867 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08001868 * Get the preferred network type.
1869 * Used for device configuration by some CDMA operators.
1870 *
1871 * @return the preferred network type, defined in RILConstants.java.
1872 */
1873 @Override
1874 public int getPreferredNetworkType() {
Junda Liua2e36012014-07-09 18:30:01 -07001875 enforceModifyPermissionOrCarrierPrivilege();
Jake Hamby7c27be32014-03-03 13:25:59 -08001876 if (DBG) log("getPreferredNetworkType");
1877 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null);
1878 int networkType = (result != null ? result[0] : -1);
1879 if (DBG) log("getPreferredNetworkType: " + networkType);
1880 return networkType;
1881 }
1882
1883 /**
1884 * Set the preferred network type.
1885 * Used for device configuration by some CDMA operators.
1886 *
1887 * @param networkType the preferred network type, defined in RILConstants.java.
1888 * @return true on success; false on any failure.
1889 */
1890 @Override
1891 public boolean setPreferredNetworkType(int networkType) {
Junda Liua2e36012014-07-09 18:30:01 -07001892 enforceModifyPermissionOrCarrierPrivilege();
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001893 final int phoneSubId = mPhone.getSubId();
Jake Hamby7c27be32014-03-03 13:25:59 -08001894 if (DBG) log("setPreferredNetworkType: type " + networkType);
1895 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
1896 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07001897 if (success) {
1898 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001899 Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07001900 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001901 return success;
1902 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001903
1904 /**
Junda Liu475951f2014-11-07 16:45:03 -08001905 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
1906 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
1907 * tethering.
1908 *
1909 * @return 0: Not required. 1: required. 2: Not set.
1910 * @hide
1911 */
1912 @Override
1913 public int getTetherApnRequired() {
1914 enforceModifyPermissionOrCarrierPrivilege();
1915 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
1916 Settings.Global.TETHER_DUN_REQUIRED, 2);
1917 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
1918 // config_tether_apndata.
1919 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
1920 dunRequired = 1;
1921 }
1922 return dunRequired;
1923 }
1924
1925 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07001926 * Set mobile data enabled
1927 * Used by the user through settings etc to turn on/off mobile data
1928 *
1929 * @param enable {@code true} turn turn data on, else {@code false}
1930 */
1931 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001932 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07001933 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08001934 int phoneId = mSubscriptionController.getPhoneId(subId);
1935 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1936 Phone phone = PhoneFactory.getPhone(phoneId);
1937 if (phone != null) {
1938 log("setDataEnabled: subId=" + subId + " enable=" + enable);
1939 phone.setDataEnabled(enable);
1940 } else {
1941 loge("setDataEnabled: no phone for subId=" + subId);
1942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001943 }
1944
1945 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07001946 * Get whether mobile data is enabled.
1947 *
1948 * Note that this used to be available from ConnectivityService, gated by
1949 * ACCESS_NETWORK_STATE permission, so this will accept either that or
1950 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07001951 *
1952 * @return {@code true} if data is enabled else {@code false}
1953 */
1954 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001955 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07001956 try {
1957 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
1958 null);
1959 } catch (Exception e) {
1960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
1961 null);
1962 }
Wink Savillee7353bb2014-12-05 14:21:41 -08001963 int phoneId = mSubscriptionController.getPhoneId(subId);
1964 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1965 Phone phone = PhoneFactory.getPhone(phoneId);
1966 if (phone != null) {
1967 boolean retVal = phone.getDataEnabled();
1968 log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
1969 return retVal;
1970 } else {
1971 loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
1972 return false;
1973 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001974 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001975
1976 @Override
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001977 public int getCarrierPrivilegeStatus() {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001978 UiccCard card = UiccController.getInstance().getUiccCard();
1979 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001980 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001981 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1982 }
1983 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001984 mPhone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001985 }
Junda Liu29340342014-07-10 15:23:27 -07001986
1987 @Override
Shishir Agrawal6d5a2852014-07-11 16:32:57 -07001988 public int checkCarrierPrivilegesForPackage(String pkgname) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001989 UiccCard card = UiccController.getInstance().getUiccCard();
1990 if (card == null) {
1991 loge("checkCarrierPrivilegesForPackage: No UICC");
1992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1993 }
1994 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname);
Junda Liu29340342014-07-10 15:23:27 -07001995 }
Derek Tan89e89d42014-07-08 17:00:10 -07001996
1997 @Override
Diego Pontorieroaf74c862014-08-28 11:51:16 -07001998 public List<String> getCarrierPackageNamesForIntent(Intent intent) {
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07001999 UiccCard card = UiccController.getInstance().getUiccCard();
2000 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002001 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002002 return null ;
2003 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002004 return card.getCarrierPackageNamesForIntent(
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002005 mPhone.getContext().getPackageManager(), intent);
2006 }
2007
Wink Savilleb564aae2014-10-23 10:18:09 -07002008 private String getIccId(int subId) {
Derek Tan97ebb422014-09-05 16:55:38 -07002009 UiccCard card = getPhone(subId).getUiccCard();
2010 if (card == null) {
2011 loge("getIccId: No UICC");
2012 return null;
2013 }
2014 String iccId = card.getIccId();
2015 if (TextUtils.isEmpty(iccId)) {
2016 loge("getIccId: ICC ID is null or empty.");
2017 return null;
2018 }
2019 return iccId;
2020 }
2021
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002022 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002023 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2024 String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002025 enforceCarrierPrivilege();
Derek Tan97ebb422014-09-05 16:55:38 -07002026
Jeff Sharkey85190e62014-12-05 09:40:12 -08002027 final String iccId = getIccId(subId);
2028 final String subscriberId = getPhone(subId).getSubscriberId();
2029
2030 if (DBG_MERGE) {
2031 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2032 + subscriberId + " to " + number);
2033 }
2034
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002035 if (TextUtils.isEmpty(iccId)) {
2036 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002037 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002038
Jeff Sharkey85190e62014-12-05 09:40:12 -08002039 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2040
2041 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002042 if (alphaTag == null) {
2043 editor.remove(alphaTagPrefKey);
2044 } else {
2045 editor.putString(alphaTagPrefKey, alphaTag);
2046 }
2047
Jeff Sharkey85190e62014-12-05 09:40:12 -08002048 // Record both the line number and IMSI for this ICCID, since we need to
2049 // track all merged IMSIs based on line number
2050 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2051 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002052 if (number == null) {
2053 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002054 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002055 } else {
2056 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002057 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002058 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002059
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002060 editor.commit();
2061 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002062 }
2063
2064 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public String getLine1NumberForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002066 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002067
2068 String iccId = getIccId(subId);
2069 if (iccId != null) {
2070 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002071 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002072 }
Derek Tan97ebb422014-09-05 16:55:38 -07002073 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002074 }
2075
2076 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002077 public String getLine1AlphaTagForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002078 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002079
2080 String iccId = getIccId(subId);
2081 if (iccId != null) {
2082 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002083 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002084 }
Derek Tan97ebb422014-09-05 16:55:38 -07002085 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002086 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002087
2088 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002089 public String[] getMergedSubscriberIds() {
2090 final Context context = mPhone.getContext();
2091 final TelephonyManager tele = TelephonyManager.from(context);
2092 final SubscriptionManager sub = SubscriptionManager.from(context);
2093
2094 // Figure out what subscribers are currently active
2095 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
2096 final int[] subIds = sub.getActiveSubscriptionIdList();
2097 for (int subId : subIds) {
2098 activeSubscriberIds.add(tele.getSubscriberId(subId));
2099 }
2100
2101 // First pass, find a number override for an active subscriber
2102 String mergeNumber = null;
2103 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2104 for (String key : prefs.keySet()) {
2105 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2106 final String subscriberId = (String) prefs.get(key);
2107 if (activeSubscriberIds.contains(subscriberId)) {
2108 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2109 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2110 mergeNumber = (String) prefs.get(numberKey);
2111 if (DBG_MERGE) {
2112 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2113 + " for active subscriber " + subscriberId);
2114 }
2115 if (!TextUtils.isEmpty(mergeNumber)) {
2116 break;
2117 }
2118 }
2119 }
2120 }
2121
2122 // Shortcut when no active merged subscribers
2123 if (TextUtils.isEmpty(mergeNumber)) {
2124 return null;
2125 }
2126
2127 // Second pass, find all subscribers under that line override
2128 final ArraySet<String> result = new ArraySet<>();
2129 for (String key : prefs.keySet()) {
2130 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2131 final String number = (String) prefs.get(key);
2132 if (mergeNumber.equals(number)) {
2133 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2134 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2135 final String subscriberId = (String) prefs.get(subscriberKey);
2136 if (!TextUtils.isEmpty(subscriberId)) {
2137 result.add(subscriberId);
2138 }
2139 }
2140 }
2141 }
2142
2143 final String[] resultArray = result.toArray(new String[result.size()]);
2144 Arrays.sort(resultArray);
2145 if (DBG_MERGE) {
2146 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2147 }
2148 return resultArray;
2149 }
2150
2151 @Override
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002152 public boolean setOperatorBrandOverride(String brand) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002153 enforceCarrierPrivilege();
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002154 return mPhone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002155 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002156
2157 @Override
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002158 public boolean setRoamingOverride(List<String> gsmRoamingList,
2159 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2160 List<String> cdmaNonRoamingList) {
2161 enforceCarrierPrivilege();
2162 return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
2163 cdmaNonRoamingList);
2164 }
2165
2166 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002167 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2168 enforceModifyPermission();
2169
2170 int returnValue = 0;
2171 try {
2172 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2173 if(result.exception == null) {
2174 if (result.result != null) {
2175 byte[] responseData = (byte[])(result.result);
2176 if(responseData.length > oemResp.length) {
2177 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2178 responseData.length + "bytes. Buffer Size is " +
2179 oemResp.length + "bytes.");
2180 }
2181 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2182 returnValue = responseData.length;
2183 }
2184 } else {
2185 CommandException ex = (CommandException) result.exception;
2186 returnValue = ex.getCommandError().ordinal();
2187 if(returnValue > 0) returnValue *= -1;
2188 }
2189 } catch (RuntimeException e) {
2190 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2191 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2192 if(returnValue > 0) returnValue *= -1;
2193 }
2194
2195 return returnValue;
2196 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002197
2198 @Override
2199 public void setRadioCapability(RadioAccessFamily[] rafs) {
2200 try {
2201 ProxyController.getInstance().setRadioCapability(rafs);
2202 } catch (RuntimeException e) {
2203 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2204 }
2205 }
2206
2207 @Override
2208 public int getRadioAccessFamily(int phoneId) {
2209 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2210 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002211
2212 @Override
2213 public void enableVideoCalling(boolean enable) {
2214 enforceModifyPermission();
2215 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2216 editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable);
2217 editor.commit();
2218 }
2219
2220 @Override
2221 public boolean isVideoCallingEnabled() {
2222 enforceReadPermission();
Andrew Lee77527ac2014-10-21 16:57:39 -07002223 // Check the user preference and the system-level IMS setting. Even if the user has
2224 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2225 // In the long run, we may instead need to check if there exists a connection service
2226 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002227 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2228 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
2229 && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
Andrew Leedf14ead2014-10-17 14:22:52 -07002230 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002231
Sanket Padawe7310cc72015-01-14 09:53:20 -08002232 /**
2233 * Returns the unique device ID of phone, for example, the IMEI for
2234 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2235 *
2236 * <p>Requires Permission:
2237 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2238 */
2239 @Override
2240 public String getDeviceId() {
2241 enforceReadPermission();
2242 final Phone phone = PhoneFactory.getPhone(0);
2243 if (phone != null) {
2244 return phone.getDeviceId();
2245 } else {
2246 return null;
2247 }
2248 }
2249
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002250 /*
2251 * {@hide}
2252 * Returns the IMS Registration Status
2253 */
2254 public boolean isImsRegistered() {
2255 return mPhone.isImsRegistered();
2256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257}