blob: 3a0ed231be56d14e419fcb145d55c5b2041e43bc [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();
1198 mPhone.getCellLocation().fillInNotifierBundle(data);
1199 return data;
1200 } else {
1201 if (DBG_LOC) log("getCellLocation: suppress non-active user");
1202 return null;
1203 }
1204 }
1205
1206 @Override
1207 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001208 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001209 }
1210
Wink Savilleb564aae2014-10-23 10:18:09 -07001211 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 mApp.enforceCallingOrSelfPermission(
1213 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001214 getPhone(subId).enableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 }
1216
1217 @Override
1218 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001219 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001220 }
1221
Wink Savilleb564aae2014-10-23 10:18:09 -07001222 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 mApp.enforceCallingOrSelfPermission(
1224 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Wink Saville36469e72014-06-11 15:17:00 -07001225 getPhone(subId).disableLocationUpdates();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 }
1227
1228 @Override
1229 @SuppressWarnings("unchecked")
1230 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1231 try {
1232 mApp.enforceCallingOrSelfPermission(
1233 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1234 } catch (SecurityException e) {
1235 // If we have ACCESS_FINE_LOCATION permission, skip the check
1236 // for ACCESS_COARSE_LOCATION
1237 // A failure should throw the SecurityException from
1238 // ACCESS_COARSE_LOCATION since this is the weaker precondition
1239 mApp.enforceCallingOrSelfPermission(
1240 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1241 }
1242
1243 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1244 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1245 return null;
1246 }
Jake Hambye994d462014-02-03 13:10:13 -08001247 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1249
1250 ArrayList<NeighboringCellInfo> cells = null;
1251
1252 try {
1253 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Wink Saville36469e72014-06-11 15:17:00 -07001254 CMD_HANDLE_NEIGHBORING_CELL, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001256 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258 return cells;
1259 } else {
1260 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1261 return null;
1262 }
1263 }
1264
1265
1266 @Override
1267 public List<CellInfo> getAllCellInfo() {
1268 try {
1269 mApp.enforceCallingOrSelfPermission(
1270 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1271 } catch (SecurityException e) {
1272 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1273 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1274 // is the weaker precondition
1275 mApp.enforceCallingOrSelfPermission(
1276 android.Manifest.permission.ACCESS_COARSE_LOCATION, null);
1277 }
1278
Jake Hambye994d462014-02-03 13:10:13 -08001279 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (DBG_LOC) log("getAllCellInfo: is active user");
1281 return mPhone.getAllCellInfo();
1282 } else {
1283 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1284 return null;
1285 }
1286 }
1287
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001288 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 public void setCellInfoListRate(int rateInMillis) {
1290 mPhone.setCellInfoListRate(rateInMillis);
1291 }
1292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 //
1294 // Internal helper methods.
1295 //
1296
Jake Hambye994d462014-02-03 13:10:13 -08001297 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 boolean ok;
1299
1300 boolean self = Binder.getCallingUid() == Process.myUid();
1301 if (!self) {
1302 // Get the caller's user id then clear the calling identity
1303 // which will be restored in the finally clause.
1304 int callingUser = UserHandle.getCallingUserId();
1305 long ident = Binder.clearCallingIdentity();
1306
1307 try {
1308 // With calling identity cleared the current user is the foreground user.
1309 int foregroundUser = ActivityManager.getCurrentUser();
1310 ok = (foregroundUser == callingUser);
1311 if (DBG_LOC) {
1312 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1313 + " callingUser=" + callingUser + " ok=" + ok);
1314 }
1315 } catch (Exception ex) {
1316 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1317 ok = false;
1318 } finally {
1319 Binder.restoreCallingIdentity(ident);
1320 }
1321 } else {
1322 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1323 ok = true;
1324 }
1325 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1326 return ok;
1327 }
1328
1329 /**
1330 * Make sure the caller has the READ_PHONE_STATE permission.
1331 *
1332 * @throws SecurityException if the caller does not have the required permission
1333 */
1334 private void enforceReadPermission() {
1335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
1336 }
1337
1338 /**
1339 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1340 *
1341 * @throws SecurityException if the caller does not have the required permission
1342 */
1343 private void enforceModifyPermission() {
1344 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1345 }
1346
1347 /**
Junda Liua2e36012014-07-09 18:30:01 -07001348 * Make sure either system app or the caller has carrier privilege.
1349 *
1350 * @throws SecurityException if the caller does not have the required permission/privilege
1351 */
1352 private void enforceModifyPermissionOrCarrierPrivilege() {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001353 int permission = mApp.checkCallingOrSelfPermission(
1354 android.Manifest.permission.MODIFY_PHONE_STATE);
1355 if (permission == PackageManager.PERMISSION_GRANTED) {
1356 return;
1357 }
1358
1359 log("No modify permission, check carrier privilege next.");
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001360 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001361 loge("No Carrier Privilege.");
1362 throw new SecurityException("No modify permission or carrier privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001363 }
1364 }
1365
1366 /**
1367 * Make sure the caller has carrier privilege.
1368 *
1369 * @throws SecurityException if the caller does not have the required permission
1370 */
1371 private void enforceCarrierPrivilege() {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001372 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001373 loge("No Carrier Privilege.");
1374 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001375 }
1376 }
1377
1378 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 * Make sure the caller has the CALL_PHONE permission.
1380 *
1381 * @throws SecurityException if the caller does not have the required permission
1382 */
1383 private void enforceCallPermission() {
1384 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1385 }
1386
Shishir Agrawal566b7612013-10-28 14:41:00 -07001387 /**
Gabriel Peal36ebb0d2014-03-20 09:20:43 -07001388 * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission.
1389 *
1390 * @throws SecurityException if the caller does not have the required permission
1391 */
1392 private void enforcePrivilegedPhoneStatePermission() {
1393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1394 null);
1395 }
1396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 private String createTelUrl(String number) {
1398 if (TextUtils.isEmpty(number)) {
1399 return null;
1400 }
1401
Jake Hambye994d462014-02-03 13:10:13 -08001402 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404
Ihab Awadf9e92732013-12-05 18:02:52 -08001405 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1407 }
1408
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001409 private static void logv(String msg) {
1410 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1411 }
1412
Ihab Awadf9e92732013-12-05 18:02:52 -08001413 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1415 }
1416
1417 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001418 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001419 }
1420
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 public int getActivePhoneTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001422 return getPhone(subId).getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423 }
1424
1425 /**
1426 * Returns the CDMA ERI icon index to display
1427 */
1428 public int getCdmaEriIconIndex() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001429 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001430
1431 }
1432
Wink Savilleb564aae2014-10-23 10:18:09 -07001433 public int getCdmaEriIconIndexForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001434 return getPhone(subId).getCdmaEriIconIndex();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435 }
1436
1437 /**
1438 * Returns the CDMA ERI icon mode,
1439 * 0 - ON
1440 * 1 - FLASHING
1441 */
1442 public int getCdmaEriIconMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001443 return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001444 }
1445
Wink Savilleb564aae2014-10-23 10:18:09 -07001446 public int getCdmaEriIconModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001447 return getPhone(subId).getCdmaEriIconMode();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
1450 /**
1451 * Returns the CDMA ERI text,
1452 */
1453 public String getCdmaEriText() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 return getCdmaEriTextForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public String getCdmaEriTextForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001458 return getPhone(subId).getCdmaEriText();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
1460
1461 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001462 * Returns the CDMA MDN.
1463 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001464 public String getCdmaMdn(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001465 enforceModifyPermissionOrCarrierPrivilege();
1466 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1467 return getPhone(subId).getLine1Number();
1468 } else {
1469 return null;
1470 }
1471 }
1472
1473 /**
1474 * Returns the CDMA MIN.
1475 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public String getCdmaMin(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001477 enforceModifyPermissionOrCarrierPrivilege();
1478 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1479 return getPhone(subId).getCdmaMin();
1480 } else {
1481 return null;
1482 }
1483 }
1484
1485 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 * Returns true if CDMA provisioning needs to run.
1487 */
1488 public boolean needsOtaServiceProvisioning() {
1489 return mPhone.needsOtaServiceProvisioning();
1490 }
1491
1492 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001493 * Sets the voice mail number of a given subId.
1494 */
1495 @Override
1496 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001497 enforceCarrierPrivilege();
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001498 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1499 new Pair<String, String>(alphaTag, number), new Integer(subId));
1500 return success;
1501 }
1502
1503 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 * Returns the unread count of voicemails
1505 */
1506 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001508 }
1509
1510 /**
1511 * Returns the unread count of voicemails for a subId
1512 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public int getVoiceMessageCountForSubscriber( int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001514 return getPhone(subId).getVoiceMessageCount();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
1516
1517 /**
1518 * Returns the data network type
1519 *
1520 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1521 */
1522 @Override
1523 public int getNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001524 return getNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001525 }
1526
1527 /**
1528 * Returns the network type for a subId
1529 */
1530 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001531 public int getNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001532 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
1535 /**
1536 * Returns the data network type
1537 */
1538 @Override
1539 public int getDataNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return getDataNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
1543 /**
1544 * Returns the data network type for a subId
1545 */
1546 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public int getDataNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001548 return getPhone(subId).getServiceState().getDataNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 }
1550
1551 /**
1552 * Returns the data network type
1553 */
1554 @Override
1555 public int getVoiceNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001556 return getVoiceNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001557 }
1558
1559 /**
1560 * Returns the Voice network type for a subId
1561 */
1562 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001563 public int getVoiceNetworkTypeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001564 return getPhone(subId).getServiceState().getVoiceNetworkType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
1567 /**
1568 * @return true if a ICC card is present
1569 */
1570 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001571 // FIXME Make changes to pass defaultSimId of type int
1572 return hasIccCardUsingSlotId(getDefaultSubscription());
1573 }
1574
1575 /**
1576 * @return true if a ICC card is present for a slotId
1577 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001578 public boolean hasIccCardUsingSlotId(int slotId) {
Wink Saville36469e72014-06-11 15:17:00 -07001579 return getPhone(slotId).getIccCard().hasIccCard();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
1582 /**
1583 * Return if the current radio is LTE on CDMA. This
1584 * is a tri-state return value as for a period of time
1585 * the mode may be unknown.
1586 *
1587 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001588 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 */
1590 public int getLteOnCdmaMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001591 return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public int getLteOnCdmaModeForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001595 return getPhone(subId).getLteOnCdmaMode();
1596 }
1597
1598 public void setPhone(Phone phone) {
1599 mPhone = phone;
1600 }
1601
1602 /**
1603 * {@hide}
1604 * Returns Default subId, 0 in the case of single standby.
1605 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001607 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
Wink Savilleb564aae2014-10-23 10:18:09 -07001610 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001611 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001613
1614 /**
1615 * @see android.telephony.TelephonyManager.WifiCallingChoices
1616 */
1617 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001618 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1619 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001620 }
1621
1622 /**
1623 * @see android.telephony.TelephonyManager.WifiCallingChoices
1624 */
1625 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001626 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1627 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1628 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001629 }
1630
Sailesh Nepald1e68152013-12-12 19:08:02 -08001631 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001632 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001633 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001634 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001635
Shishir Agrawal566b7612013-10-28 14:41:00 -07001636 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001637 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
Junda Liua2e36012014-07-09 18:30:01 -07001638 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001639
1640 if (DBG) log("iccOpenLogicalChannel: " + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001641 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
1642 CMD_OPEN_CHANNEL, AID);
1643 if (DBG) log("iccOpenLogicalChannel: " + response);
1644 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001645 }
1646
1647 @Override
1648 public boolean iccCloseLogicalChannel(int channel) {
Junda Liua2e36012014-07-09 18:30:01 -07001649 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001650
1651 if (DBG) log("iccCloseLogicalChannel: " + channel);
1652 if (channel < 0) {
1653 return false;
1654 }
Jake Hambye994d462014-02-03 13:10:13 -08001655 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001656 if (DBG) log("iccCloseLogicalChannel: " + success);
1657 return success;
1658 }
1659
1660 @Override
1661 public String iccTransmitApduLogicalChannel(int channel, int cla,
1662 int command, int p1, int p2, int p3, String data) {
Junda Liua2e36012014-07-09 18:30:01 -07001663 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001664
1665 if (DBG) {
1666 log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla +
1667 " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
1668 " data=" + data);
1669 }
1670
1671 if (channel < 0) {
1672 return "";
1673 }
1674
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001675 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawal566b7612013-10-28 14:41:00 -07001676 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data));
1677 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
1678
Shishir Agrawal566b7612013-10-28 14:41:00 -07001679 // Append the returned status code to the end of the response payload.
1680 String s = Integer.toHexString(
1681 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001682 if (response.payload != null) {
1683 s = IccUtils.bytesToHexString(response.payload) + s;
1684 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001685 return s;
1686 }
Jake Hambye994d462014-02-03 13:10:13 -08001687
Evan Charltonc66da362014-05-16 14:06:40 -07001688 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001689 public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2,
1690 int p3, String data) {
1691 enforceModifyPermissionOrCarrierPrivilege();
1692
1693 if (DBG) {
1694 log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1="
1695 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
1696 }
1697
1698 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
1699 new IccAPDUArgument(0, cla, command, p1, p2, p3, data));
1700 if (DBG) log("iccTransmitApduBasicChannel: " + response);
1701
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001702 // Append the returned status code to the end of the response payload.
1703 String s = Integer.toHexString(
1704 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001705 if (response.payload != null) {
1706 s = IccUtils.bytesToHexString(response.payload) + s;
1707 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001708 return s;
1709 }
1710
1711 @Override
1712 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
1713 String filePath) {
1714 enforceModifyPermissionOrCarrierPrivilege();
1715
1716 if (DBG) {
1717 log("Exchange SIM_IO " + fileID + ":" + command + " " +
1718 p1 + " " + p2 + " " + p3 + ":" + filePath);
1719 }
1720
1721 IccIoResult response =
1722 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Yong Jiang3edf3782014-10-03 13:23:28 -05001723 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath));
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001724
1725 if (DBG) {
1726 log("Exchange SIM_IO [R]" + response);
1727 }
1728
1729 byte[] result = null;
1730 int length = 2;
1731 if (response.payload != null) {
1732 length = 2 + response.payload.length;
1733 result = new byte[length];
1734 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
1735 } else {
1736 result = new byte[length];
1737 }
1738
1739 result[length - 1] = (byte) response.sw2;
1740 result[length - 2] = (byte) response.sw1;
1741 return result;
1742 }
1743
1744 @Override
Evan Charltonc66da362014-05-16 14:06:40 -07001745 public String sendEnvelopeWithStatus(String content) {
Junda Liua2e36012014-07-09 18:30:01 -07001746 enforceModifyPermissionOrCarrierPrivilege();
Evan Charltonc66da362014-05-16 14:06:40 -07001747
1748 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content);
1749 if (response.payload == null) {
1750 return "";
1751 }
1752
1753 // Append the returned status code to the end of the response payload.
1754 String s = Integer.toHexString(
1755 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
1756 s = IccUtils.bytesToHexString(response.payload) + s;
1757 return s;
1758 }
1759
Jake Hambye994d462014-02-03 13:10:13 -08001760 /**
1761 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1762 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1763 *
1764 * @param itemID the ID of the item to read
1765 * @return the NV item as a String, or null on error.
1766 */
1767 @Override
1768 public String nvReadItem(int itemID) {
Junda Liua2e36012014-07-09 18:30:01 -07001769 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001770 if (DBG) log("nvReadItem: item " + itemID);
1771 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
1772 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
1773 return value;
1774 }
1775
1776 /**
1777 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1778 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1779 *
1780 * @param itemID the ID of the item to read
1781 * @param itemValue the value to write, as a String
1782 * @return true on success; false on any failure
1783 */
1784 @Override
1785 public boolean nvWriteItem(int itemID, String itemValue) {
Junda Liua2e36012014-07-09 18:30:01 -07001786 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001787 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
1788 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
1789 new Pair<Integer, String>(itemID, itemValue));
1790 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
1791 return success;
1792 }
1793
1794 /**
1795 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
1796 * Used for device configuration by some CDMA operators.
1797 *
1798 * @param preferredRoamingList byte array containing the new PRL
1799 * @return true on success; false on any failure
1800 */
1801 @Override
1802 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Junda Liua2e36012014-07-09 18:30:01 -07001803 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001804 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
1805 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
1806 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
1807 return success;
1808 }
1809
1810 /**
1811 * Perform the specified type of NV config reset.
1812 * Used for device configuration by some CDMA operators.
1813 *
1814 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
1815 * @return true on success; false on any failure
1816 */
1817 @Override
1818 public boolean nvResetConfig(int resetType) {
Junda Liua2e36012014-07-09 18:30:01 -07001819 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001820 if (DBG) log("nvResetConfig: type " + resetType);
1821 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
1822 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
1823 return success;
1824 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001825
1826 /**
Wink Saville36469e72014-06-11 15:17:00 -07001827 * {@hide}
1828 * Returns Default sim, 0 in the case of single standby.
1829 */
1830 public int getDefaultSim() {
1831 //TODO Need to get it from Telephony Devcontroller
1832 return 0;
1833 }
1834
ram87fca6f2014-07-18 18:58:44 +05301835 public String[] getPcscfAddress(String apnType) {
Wink Saville36469e72014-06-11 15:17:00 -07001836 enforceReadPermission();
ram87fca6f2014-07-18 18:58:44 +05301837 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07001838 }
1839
1840 public void setImsRegistrationState(boolean registered) {
1841 enforceModifyPermission();
1842 mPhone.setImsRegistrationState(registered);
1843 }
1844
1845 /**
Junda Liu84d15a22014-07-02 11:21:04 -07001846 * Get the calculated preferred network type.
1847 * Used for debugging incorrect network type.
1848 *
1849 * @return the preferred network type, defined in RILConstants.java.
1850 */
1851 @Override
1852 public int getCalculatedPreferredNetworkType() {
1853 enforceReadPermission();
Amit Mahajan43330e02014-11-18 11:54:45 -08001854 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07001855 }
1856
1857 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08001858 * Get the preferred network type.
1859 * Used for device configuration by some CDMA operators.
1860 *
1861 * @return the preferred network type, defined in RILConstants.java.
1862 */
1863 @Override
1864 public int getPreferredNetworkType() {
Junda Liua2e36012014-07-09 18:30:01 -07001865 enforceModifyPermissionOrCarrierPrivilege();
Jake Hamby7c27be32014-03-03 13:25:59 -08001866 if (DBG) log("getPreferredNetworkType");
1867 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null);
1868 int networkType = (result != null ? result[0] : -1);
1869 if (DBG) log("getPreferredNetworkType: " + networkType);
1870 return networkType;
1871 }
1872
1873 /**
1874 * Set the preferred network type.
1875 * Used for device configuration by some CDMA operators.
1876 *
1877 * @param networkType the preferred network type, defined in RILConstants.java.
1878 * @return true on success; false on any failure.
1879 */
1880 @Override
1881 public boolean setPreferredNetworkType(int networkType) {
Junda Liua2e36012014-07-09 18:30:01 -07001882 enforceModifyPermissionOrCarrierPrivilege();
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001883 final int phoneSubId = mPhone.getSubId();
Jake Hamby7c27be32014-03-03 13:25:59 -08001884 if (DBG) log("setPreferredNetworkType: type " + networkType);
1885 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType);
1886 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07001887 if (success) {
1888 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
PauloftheWest3c6ce5e2014-11-03 07:09:47 -08001889 Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07001890 }
Jake Hamby7c27be32014-03-03 13:25:59 -08001891 return success;
1892 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001893
1894 /**
Junda Liu475951f2014-11-07 16:45:03 -08001895 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
1896 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
1897 * tethering.
1898 *
1899 * @return 0: Not required. 1: required. 2: Not set.
1900 * @hide
1901 */
1902 @Override
1903 public int getTetherApnRequired() {
1904 enforceModifyPermissionOrCarrierPrivilege();
1905 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
1906 Settings.Global.TETHER_DUN_REQUIRED, 2);
1907 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
1908 // config_tether_apndata.
1909 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
1910 dunRequired = 1;
1911 }
1912 return dunRequired;
1913 }
1914
1915 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07001916 * Set mobile data enabled
1917 * Used by the user through settings etc to turn on/off mobile data
1918 *
1919 * @param enable {@code true} turn turn data on, else {@code false}
1920 */
1921 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001922 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07001923 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08001924 int phoneId = mSubscriptionController.getPhoneId(subId);
1925 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1926 Phone phone = PhoneFactory.getPhone(phoneId);
1927 if (phone != null) {
1928 log("setDataEnabled: subId=" + subId + " enable=" + enable);
1929 phone.setDataEnabled(enable);
1930 } else {
1931 loge("setDataEnabled: no phone for subId=" + subId);
1932 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001933 }
1934
1935 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07001936 * Get whether mobile data is enabled.
1937 *
1938 * Note that this used to be available from ConnectivityService, gated by
1939 * ACCESS_NETWORK_STATE permission, so this will accept either that or
1940 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07001941 *
1942 * @return {@code true} if data is enabled else {@code false}
1943 */
1944 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08001945 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07001946 try {
1947 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
1948 null);
1949 } catch (Exception e) {
1950 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
1951 null);
1952 }
Wink Savillee7353bb2014-12-05 14:21:41 -08001953 int phoneId = mSubscriptionController.getPhoneId(subId);
1954 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
1955 Phone phone = PhoneFactory.getPhone(phoneId);
1956 if (phone != null) {
1957 boolean retVal = phone.getDataEnabled();
1958 log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
1959 return retVal;
1960 } else {
1961 loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
1962 return false;
1963 }
Robert Greenwalted86e582014-05-21 20:03:20 -07001964 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001965
1966 @Override
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001967 public int getCarrierPrivilegeStatus() {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001968 UiccCard card = UiccController.getInstance().getUiccCard();
1969 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001970 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1972 }
1973 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001974 mPhone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07001975 }
Junda Liu29340342014-07-10 15:23:27 -07001976
1977 @Override
Shishir Agrawal6d5a2852014-07-11 16:32:57 -07001978 public int checkCarrierPrivilegesForPackage(String pkgname) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001979 UiccCard card = UiccController.getInstance().getUiccCard();
1980 if (card == null) {
1981 loge("checkCarrierPrivilegesForPackage: No UICC");
1982 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
1983 }
1984 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgname);
Junda Liu29340342014-07-10 15:23:27 -07001985 }
Derek Tan89e89d42014-07-08 17:00:10 -07001986
1987 @Override
Diego Pontorieroaf74c862014-08-28 11:51:16 -07001988 public List<String> getCarrierPackageNamesForIntent(Intent intent) {
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07001989 UiccCard card = UiccController.getInstance().getUiccCard();
1990 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07001991 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07001992 return null ;
1993 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07001994 return card.getCarrierPackageNamesForIntent(
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07001995 mPhone.getContext().getPackageManager(), intent);
1996 }
1997
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 private String getIccId(int subId) {
Derek Tan97ebb422014-09-05 16:55:38 -07001999 UiccCard card = getPhone(subId).getUiccCard();
2000 if (card == null) {
2001 loge("getIccId: No UICC");
2002 return null;
2003 }
2004 String iccId = card.getIccId();
2005 if (TextUtils.isEmpty(iccId)) {
2006 loge("getIccId: ICC ID is null or empty.");
2007 return null;
2008 }
2009 return iccId;
2010 }
2011
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002012 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002013 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2014 String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002015 enforceCarrierPrivilege();
Derek Tan97ebb422014-09-05 16:55:38 -07002016
Jeff Sharkey85190e62014-12-05 09:40:12 -08002017 final String iccId = getIccId(subId);
2018 final String subscriberId = getPhone(subId).getSubscriberId();
2019
2020 if (DBG_MERGE) {
2021 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2022 + subscriberId + " to " + number);
2023 }
2024
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002025 if (TextUtils.isEmpty(iccId)) {
2026 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002027 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002028
Jeff Sharkey85190e62014-12-05 09:40:12 -08002029 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2030
2031 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002032 if (alphaTag == null) {
2033 editor.remove(alphaTagPrefKey);
2034 } else {
2035 editor.putString(alphaTagPrefKey, alphaTag);
2036 }
2037
Jeff Sharkey85190e62014-12-05 09:40:12 -08002038 // Record both the line number and IMSI for this ICCID, since we need to
2039 // track all merged IMSIs based on line number
2040 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2041 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002042 if (number == null) {
2043 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002044 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002045 } else {
2046 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002047 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002048 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002049
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002050 editor.commit();
2051 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002052 }
2053
2054 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002055 public String getLine1NumberForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002056 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002057
2058 String iccId = getIccId(subId);
2059 if (iccId != null) {
2060 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002061 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002062 }
Derek Tan97ebb422014-09-05 16:55:38 -07002063 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002064 }
2065
2066 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002067 public String getLine1AlphaTagForDisplay(int subId) {
Derek Tan7226c842014-07-02 17:42:23 -07002068 enforceReadPermission();
Derek Tan97ebb422014-09-05 16:55:38 -07002069
2070 String iccId = getIccId(subId);
2071 if (iccId != null) {
2072 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002073 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002074 }
Derek Tan97ebb422014-09-05 16:55:38 -07002075 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002076 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002077
2078 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002079 public String[] getMergedSubscriberIds() {
2080 final Context context = mPhone.getContext();
2081 final TelephonyManager tele = TelephonyManager.from(context);
2082 final SubscriptionManager sub = SubscriptionManager.from(context);
2083
2084 // Figure out what subscribers are currently active
2085 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
2086 final int[] subIds = sub.getActiveSubscriptionIdList();
2087 for (int subId : subIds) {
2088 activeSubscriberIds.add(tele.getSubscriberId(subId));
2089 }
2090
2091 // First pass, find a number override for an active subscriber
2092 String mergeNumber = null;
2093 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2094 for (String key : prefs.keySet()) {
2095 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2096 final String subscriberId = (String) prefs.get(key);
2097 if (activeSubscriberIds.contains(subscriberId)) {
2098 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2099 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2100 mergeNumber = (String) prefs.get(numberKey);
2101 if (DBG_MERGE) {
2102 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2103 + " for active subscriber " + subscriberId);
2104 }
2105 if (!TextUtils.isEmpty(mergeNumber)) {
2106 break;
2107 }
2108 }
2109 }
2110 }
2111
2112 // Shortcut when no active merged subscribers
2113 if (TextUtils.isEmpty(mergeNumber)) {
2114 return null;
2115 }
2116
2117 // Second pass, find all subscribers under that line override
2118 final ArraySet<String> result = new ArraySet<>();
2119 for (String key : prefs.keySet()) {
2120 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2121 final String number = (String) prefs.get(key);
2122 if (mergeNumber.equals(number)) {
2123 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2124 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2125 final String subscriberId = (String) prefs.get(subscriberKey);
2126 if (!TextUtils.isEmpty(subscriberId)) {
2127 result.add(subscriberId);
2128 }
2129 }
2130 }
2131 }
2132
2133 final String[] resultArray = result.toArray(new String[result.size()]);
2134 Arrays.sort(resultArray);
2135 if (DBG_MERGE) {
2136 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2137 }
2138 return resultArray;
2139 }
2140
2141 @Override
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002142 public boolean setOperatorBrandOverride(String brand) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002143 enforceCarrierPrivilege();
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002144 return mPhone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002145 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002146
2147 @Override
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002148 public boolean setRoamingOverride(List<String> gsmRoamingList,
2149 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2150 List<String> cdmaNonRoamingList) {
2151 enforceCarrierPrivilege();
2152 return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
2153 cdmaNonRoamingList);
2154 }
2155
2156 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002157 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2158 enforceModifyPermission();
2159
2160 int returnValue = 0;
2161 try {
2162 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2163 if(result.exception == null) {
2164 if (result.result != null) {
2165 byte[] responseData = (byte[])(result.result);
2166 if(responseData.length > oemResp.length) {
2167 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2168 responseData.length + "bytes. Buffer Size is " +
2169 oemResp.length + "bytes.");
2170 }
2171 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2172 returnValue = responseData.length;
2173 }
2174 } else {
2175 CommandException ex = (CommandException) result.exception;
2176 returnValue = ex.getCommandError().ordinal();
2177 if(returnValue > 0) returnValue *= -1;
2178 }
2179 } catch (RuntimeException e) {
2180 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2181 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2182 if(returnValue > 0) returnValue *= -1;
2183 }
2184
2185 return returnValue;
2186 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002187
2188 @Override
2189 public void setRadioCapability(RadioAccessFamily[] rafs) {
2190 try {
2191 ProxyController.getInstance().setRadioCapability(rafs);
2192 } catch (RuntimeException e) {
2193 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2194 }
2195 }
2196
2197 @Override
2198 public int getRadioAccessFamily(int phoneId) {
2199 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002201
2202 @Override
2203 public void enableVideoCalling(boolean enable) {
2204 enforceModifyPermission();
2205 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2206 editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable);
2207 editor.commit();
2208 }
2209
2210 @Override
2211 public boolean isVideoCallingEnabled() {
2212 enforceReadPermission();
Andrew Lee77527ac2014-10-21 16:57:39 -07002213 // Check the user preference and the system-level IMS setting. Even if the user has
2214 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2215 // In the long run, we may instead need to check if there exists a connection service
2216 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002217 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2218 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
2219 && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
Andrew Leedf14ead2014-10-17 14:22:52 -07002220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221}