blob: aabd4dfa0787aa38303cd3c3e6145147282d3f4e [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;
Stuart Scott981d8582015-04-21 14:09:50 -070036import android.os.UserManager;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080038import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080039import android.telecom.PhoneAccount;
Andrew Lee9431b832015-03-09 18:46:45 -070040import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070041import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.telephony.CellInfo;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070043import android.telephony.IccOpenLogicalChannelResponse;
Jake Hambye994d462014-02-03 13:10:13 -080044import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070045import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080047import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080048import android.telephony.SubscriptionManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.telephony.TelephonyManager;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -070050import android.telephony.ModemActivityInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080052import android.util.ArrayMap;
53import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080055import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080056import android.util.Slog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057
Andrew Lee312e8172014-10-23 17:01:36 -070058import com.android.ims.ImsManager;
Shishir Agrawal566b7612013-10-28 14:41:00 -070059import com.android.internal.telephony.CallManager;
60import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080063import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010064import com.android.internal.telephony.MccTable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.Phone;
Wink Saville36469e72014-06-11 15:17:00 -070066import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import com.android.internal.telephony.ProxyController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import com.android.internal.telephony.PhoneConstants;
Svet Ganovb320e182015-04-16 12:30:10 -070069import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080070import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070071import com.android.internal.telephony.uicc.IccIoResult;
72import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070073import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070074import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080075import com.android.internal.util.HexDump;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076
Wink Saville36469e72014-06-11 15:17:00 -070077import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
78
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import java.util.Arrays;
Shishir Agrawal621a47c2014-12-01 10:25:09 -080081import java.util.HashMap;
82import java.util.Iterator;
Jake Hambye994d462014-02-03 13:10:13 -080083import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +010084import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import java.util.Map;
86import java.util.Objects;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087
88/**
89 * Implementation of the ITelephony interface.
90 */
Santos Cordon117fee72014-05-16 17:56:12 -070091public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092 private static final String LOG_TAG = "PhoneInterfaceManager";
93 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
94 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -080095 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096
97 // Message codes used with mMainThreadHandler
98 private static final int CMD_HANDLE_PIN_MMI = 1;
99 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
100 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
101 private static final int CMD_ANSWER_RINGING_CALL = 4;
102 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700103 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
104 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105 private static final int CMD_OPEN_CHANNEL = 9;
106 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
107 private static final int CMD_CLOSE_CHANNEL = 11;
108 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800109 private static final int CMD_NV_READ_ITEM = 13;
110 private static final int EVENT_NV_READ_ITEM_DONE = 14;
111 private static final int CMD_NV_WRITE_ITEM = 15;
112 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
113 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
114 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
115 private static final int CMD_NV_RESET_CONFIG = 19;
116 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800117 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
118 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
119 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
120 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800121 private static final int CMD_SEND_ENVELOPE = 25;
122 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700123 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
124 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
125 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
126 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
127 private static final int CMD_EXCHANGE_SIM_IO = 31;
128 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800129 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
130 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700131 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
132 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700133 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
134 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
135
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137 /** The singleton instance. */
138 private static PhoneInterfaceManager sInstance;
139
Wink Saville3ab207e2014-11-20 13:07:20 -0800140 private PhoneGlobals mApp;
141 private Phone mPhone;
142 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700143 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800144 private AppOpsManager mAppOps;
145 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800147 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
Derek Tan97ebb422014-09-05 16:55:38 -0700149 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
150 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800151 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Andrew Leedf14ead2014-10-17 14:22:52 -0700152 private static final String PREF_ENABLE_VIDEO_CALLING = "enable_video_calling";
Derek Tan89e89d42014-07-08 17:00:10 -0700153
154 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155 * A request object to use for transmitting data to an ICC.
156 */
157 private static final class IccAPDUArgument {
158 public int channel, cla, command, p1, p2, p3;
159 public String data;
160
161 public IccAPDUArgument(int channel, int cla, int command,
162 int p1, int p2, int p3, String data) {
163 this.channel = channel;
164 this.cla = cla;
165 this.command = command;
166 this.p1 = p1;
167 this.p2 = p2;
168 this.p3 = p3;
169 this.data = data;
170 }
171 }
172
173 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
175 * request after sending. The main thread will notify the request when it is complete.
176 */
177 private static final class MainThreadRequest {
178 /** The argument to use for the request */
179 public Object argument;
180 /** The result of the request that is run on the main thread */
181 public Object result;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800182 /** The subscriber id that this request applies to. Null if default. */
183 public Integer subId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185 public MainThreadRequest(Object argument) {
186 this.argument = argument;
187 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800188
189 public MainThreadRequest(Object argument, Integer subId) {
190 this.argument = argument;
191 this.subId = subId;
192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 }
194
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800195 private static final class IncomingThirdPartyCallArgs {
196 public final ComponentName component;
197 public final String callId;
198 public final String callerDisplayName;
199
200 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
201 String callerDisplayName) {
202 this.component = component;
203 this.callId = callId;
204 this.callerDisplayName = callerDisplayName;
205 }
206 }
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /**
209 * A handler that processes messages on the main thread in the phone process. Since many
210 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
211 * inbound binder threads to the main thread in the phone process. The Binder thread
212 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
213 * on, which will be notified when the operation completes and will contain the result of the
214 * request.
215 *
216 * <p>If a MainThreadRequest object is provided in the msg.obj field,
217 * note that request.result must be set to something non-null for the calling thread to
218 * unblock.
219 */
220 private final class MainThreadHandler extends Handler {
221 @Override
222 public void handleMessage(Message msg) {
223 MainThreadRequest request;
224 Message onCompleted;
225 AsyncResult ar;
Shishir Agrawal21409252015-01-15 23:33:50 -0800226 UiccCard uiccCard = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700227 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229 switch (msg.what) {
Yorke Lee716f67e2015-06-17 15:39:16 -0700230 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700232 final Phone phone = getPhoneFromRequest(request);
233 request.result = phone != null ?
234 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
235 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 // Wake up the requesting thread
237 synchronized (request) {
238 request.notifyAll();
239 }
240 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243 case CMD_HANDLE_NEIGHBORING_CELL:
244 request = (MainThreadRequest) msg.obj;
245 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
246 request);
247 mPhone.getNeighboringCids(onCompleted);
248 break;
249
250 case EVENT_NEIGHBORING_CELL_DONE:
251 ar = (AsyncResult) msg.obj;
252 request = (MainThreadRequest) ar.userObj;
253 if (ar.exception == null && ar.result != null) {
254 request.result = ar.result;
255 } else {
256 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800257 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259 // Wake up the requesting thread
260 synchronized (request) {
261 request.notifyAll();
262 }
263 break;
264
265 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700266 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800267 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700268 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 break;
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 case CMD_END_CALL:
272 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800273 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700274 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700275 Phone phone = getPhone(end_subId);
276 if (phone == null) {
277 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
278 break;
279 }
280 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
282 // CDMA: If the user presses the Power button we treat it as
283 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700284 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
286 // GSM: End the call as per the Phone state
287 hungUp = PhoneUtils.hangup(mCM);
288 } else {
289 throw new IllegalStateException("Unexpected phone type: " + phoneType);
290 }
291 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
292 request.result = hungUp;
293 // Wake up the requesting thread
294 synchronized (request) {
295 request.notifyAll();
296 }
297 break;
298
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700299 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700300 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700301 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700302 if (uiccCard == null) {
303 loge("iccTransmitApduLogicalChannel: No UICC");
304 request.result = new IccIoResult(0x6F, 0, (byte[])null);
305 synchronized (request) {
306 request.notifyAll();
307 }
308 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700309 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
310 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700311 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700312 iccArgument.channel, iccArgument.cla, iccArgument.command,
313 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700314 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700316 break;
317
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700318 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700319 ar = (AsyncResult) msg.obj;
320 request = (MainThreadRequest) ar.userObj;
321 if (ar.exception == null && ar.result != null) {
322 request.result = ar.result;
323 } else {
324 request.result = new IccIoResult(0x6F, 0, (byte[])null);
325 if (ar.result == null) {
326 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800327 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700328 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800329 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700330 } else {
331 loge("iccTransmitApduLogicalChannel: Unknown exception");
332 }
333 }
334 synchronized (request) {
335 request.notifyAll();
336 }
337 break;
338
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700339 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
340 request = (MainThreadRequest) msg.obj;
341 iccArgument = (IccAPDUArgument) request.argument;
342 if (uiccCard == null) {
343 loge("iccTransmitApduBasicChannel: No UICC");
344 request.result = new IccIoResult(0x6F, 0, (byte[])null);
345 synchronized (request) {
346 request.notifyAll();
347 }
348 } else {
349 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
350 request);
351 uiccCard.iccTransmitApduBasicChannel(
352 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
353 iccArgument.p3, iccArgument.data, onCompleted);
354 }
355 break;
356
357 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
358 ar = (AsyncResult) msg.obj;
359 request = (MainThreadRequest) ar.userObj;
360 if (ar.exception == null && ar.result != null) {
361 request.result = ar.result;
362 } else {
363 request.result = new IccIoResult(0x6F, 0, (byte[])null);
364 if (ar.result == null) {
365 loge("iccTransmitApduBasicChannel: Empty response");
366 } else if (ar.exception instanceof CommandException) {
367 loge("iccTransmitApduBasicChannel: CommandException: " +
368 ar.exception);
369 } else {
370 loge("iccTransmitApduBasicChannel: Unknown exception");
371 }
372 }
373 synchronized (request) {
374 request.notifyAll();
375 }
376 break;
377
378 case CMD_EXCHANGE_SIM_IO:
379 request = (MainThreadRequest) msg.obj;
380 iccArgument = (IccAPDUArgument) request.argument;
381 if (uiccCard == null) {
382 loge("iccExchangeSimIO: No UICC");
383 request.result = new IccIoResult(0x6F, 0, (byte[])null);
384 synchronized (request) {
385 request.notifyAll();
386 }
387 } else {
388 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
389 request);
390 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
391 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
392 iccArgument.data, onCompleted);
393 }
394 break;
395
396 case EVENT_EXCHANGE_SIM_IO_DONE:
397 ar = (AsyncResult) msg.obj;
398 request = (MainThreadRequest) ar.userObj;
399 if (ar.exception == null && ar.result != null) {
400 request.result = ar.result;
401 } else {
402 request.result = new IccIoResult(0x6f, 0, (byte[])null);
403 }
404 synchronized (request) {
405 request.notifyAll();
406 }
407 break;
408
Derek Tan4d5e5c12014-02-04 11:54:58 -0800409 case CMD_SEND_ENVELOPE:
410 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700411 if (uiccCard == null) {
412 loge("sendEnvelopeWithStatus: No UICC");
413 request.result = new IccIoResult(0x6F, 0, (byte[])null);
414 synchronized (request) {
415 request.notifyAll();
416 }
417 } else {
418 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
419 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
420 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800421 break;
422
423 case EVENT_SEND_ENVELOPE_DONE:
424 ar = (AsyncResult) msg.obj;
425 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700426 if (ar.exception == null && ar.result != null) {
427 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800428 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
430 if (ar.result == null) {
431 loge("sendEnvelopeWithStatus: Empty response");
432 } else if (ar.exception instanceof CommandException) {
433 loge("sendEnvelopeWithStatus: CommandException: " +
434 ar.exception);
435 } else {
436 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
437 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800438 }
439 synchronized (request) {
440 request.notifyAll();
441 }
442 break;
443
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 case CMD_OPEN_CHANNEL:
445 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 if (uiccCard == null) {
447 loge("iccOpenLogicalChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 synchronized (request) {
450 request.notifyAll();
451 }
452 } else {
453 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
454 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
455 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 break;
457
458 case EVENT_OPEN_CHANNEL_DONE:
459 ar = (AsyncResult) msg.obj;
460 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 int[] result = (int[]) ar.result;
464 int channelId = result[0];
465 byte[] selectResponse = null;
466 if (result.length > 1) {
467 selectResponse = new byte[result.length - 1];
468 for (int i = 1; i < result.length; ++i) {
469 selectResponse[i - 1] = (byte) result[i];
470 }
471 }
472 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700473 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 if (ar.result == null) {
476 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (ar.exception != null) {
479 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
480 }
481
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700482 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700483 if (ar.exception instanceof CommandException) {
484 CommandException.Error error =
485 ((CommandException) (ar.exception)).getCommandError();
486 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700487 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700488 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700489 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 }
491 }
492 openChannelResp = new IccOpenLogicalChannelResponse(
493 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700495 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 synchronized (request) {
497 request.notifyAll();
498 }
499 break;
500
501 case CMD_CLOSE_CHANNEL:
502 request = (MainThreadRequest) msg.obj;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700503 if (uiccCard == null) {
504 loge("iccCloseLogicalChannel: No UICC");
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 synchronized (request) {
507 request.notifyAll();
508 }
509 } else {
510 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
511 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
512 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 break;
514
515 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800516 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
517 break;
518
519 case CMD_NV_READ_ITEM:
520 request = (MainThreadRequest) msg.obj;
521 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
522 mPhone.nvReadItem((Integer) request.argument, onCompleted);
523 break;
524
525 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800531 request.result = "";
532 if (ar.result == null) {
533 loge("nvReadItem: Empty response");
534 } else if (ar.exception instanceof CommandException) {
535 loge("nvReadItem: CommandException: " +
536 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800538 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 }
540 }
541 synchronized (request) {
542 request.notifyAll();
543 }
544 break;
545
Jake Hambye994d462014-02-03 13:10:13 -0800546 case CMD_NV_WRITE_ITEM:
547 request = (MainThreadRequest) msg.obj;
548 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
549 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
550 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
551 break;
552
553 case EVENT_NV_WRITE_ITEM_DONE:
554 handleNullReturnEvent(msg, "nvWriteItem");
555 break;
556
557 case CMD_NV_WRITE_CDMA_PRL:
558 request = (MainThreadRequest) msg.obj;
559 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
560 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
561 break;
562
563 case EVENT_NV_WRITE_CDMA_PRL_DONE:
564 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
565 break;
566
567 case CMD_NV_RESET_CONFIG:
568 request = (MainThreadRequest) msg.obj;
569 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
570 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
571 break;
572
573 case EVENT_NV_RESET_CONFIG_DONE:
574 handleNullReturnEvent(msg, "nvResetConfig");
575 break;
576
Jake Hamby7c27be32014-03-03 13:25:59 -0800577 case CMD_GET_PREFERRED_NETWORK_TYPE:
578 request = (MainThreadRequest) msg.obj;
579 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700580 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800581 break;
582
583 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
586 if (ar.exception == null && ar.result != null) {
587 request.result = ar.result; // Integer
588 } else {
589 request.result = -1;
590 if (ar.result == null) {
591 loge("getPreferredNetworkType: Empty response");
592 } else if (ar.exception instanceof CommandException) {
593 loge("getPreferredNetworkType: CommandException: " +
594 ar.exception);
595 } else {
596 loge("getPreferredNetworkType: Unknown exception");
597 }
598 }
599 synchronized (request) {
600 request.notifyAll();
601 }
602 break;
603
604 case CMD_SET_PREFERRED_NETWORK_TYPE:
605 request = (MainThreadRequest) msg.obj;
606 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
607 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700608 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800609 break;
610
611 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
612 handleNullReturnEvent(msg, "setPreferredNetworkType");
613 break;
614
Steven Liu4bf01bc2014-07-17 11:05:29 -0500615 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
616 request = (MainThreadRequest)msg.obj;
617 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
618 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
619 break;
620
621 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
622 ar = (AsyncResult)msg.obj;
623 request = (MainThreadRequest)ar.userObj;
624 request.result = ar;
625 synchronized (request) {
626 request.notifyAll();
627 }
628 break;
629
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800630 case CMD_SET_VOICEMAIL_NUMBER:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
633 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800634 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
635 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800636 break;
637
638 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
639 handleNullReturnEvent(msg, "setVoicemailNumber");
640 break;
641
Stuart Scott54788802015-03-30 13:18:01 -0700642 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
645 request);
646 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
647 break;
648
649 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
650 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
651 break;
652
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700653 case CMD_GET_MODEM_ACTIVITY_INFO:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700656 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700657 break;
658
659 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result;
664 } else {
665 if (ar.result == null) {
666 loge("queryModemActivityInfo: Empty response");
667 } else if (ar.exception instanceof CommandException) {
668 loge("queryModemActivityInfo: CommandException: " +
669 ar.exception);
670 } else {
671 loge("queryModemActivityInfo: Unknown exception");
672 }
673 }
674 synchronized (request) {
675 request.notifyAll();
676 }
677 break;
678
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700679 default:
680 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
681 break;
682 }
683 }
Jake Hambye994d462014-02-03 13:10:13 -0800684
685 private void handleNullReturnEvent(Message msg, String command) {
686 AsyncResult ar = (AsyncResult) msg.obj;
687 MainThreadRequest request = (MainThreadRequest) ar.userObj;
688 if (ar.exception == null) {
689 request.result = true;
690 } else {
691 request.result = false;
692 if (ar.exception instanceof CommandException) {
693 loge(command + ": CommandException: " + ar.exception);
694 } else {
695 loge(command + ": Unknown exception");
696 }
697 }
698 synchronized (request) {
699 request.notifyAll();
700 }
701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700702 }
703
704 /**
705 * Posts the specified command to be executed on the main thread,
706 * waits for the request to complete, and returns the result.
707 * @see #sendRequestAsync
708 */
709 private Object sendRequest(int command, Object argument) {
Santos Cordon500b0e02014-06-17 10:33:33 -0700710 return sendRequest(command, argument, null);
Wink Saville36469e72014-06-11 15:17:00 -0700711 }
712
713 /**
714 * Posts the specified command to be executed on the main thread,
715 * waits for the request to complete, and returns the result.
716 * @see #sendRequestAsync
717 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800718 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700719 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
720 throw new RuntimeException("This method will deadlock if called from the main thread.");
721 }
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700724 Message msg = mMainThreadHandler.obtainMessage(command, request);
725 msg.sendToTarget();
726
727 // Wait for the request to complete
728 synchronized (request) {
729 while (request.result == null) {
730 try {
731 request.wait();
732 } catch (InterruptedException e) {
733 // Do nothing, go back and wait until the request is complete
734 }
735 }
736 }
737 return request.result;
738 }
739
740 /**
741 * Asynchronous ("fire and forget") version of sendRequest():
742 * Posts the specified command to be executed on the main thread, and
743 * returns immediately.
744 * @see #sendRequest
745 */
746 private void sendRequestAsync(int command) {
747 mMainThreadHandler.sendEmptyMessage(command);
748 }
749
750 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700751 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
752 * @see {@link #sendRequest(int,Object)}
753 */
754 private void sendRequestAsync(int command, Object argument) {
755 MainThreadRequest request = new MainThreadRequest(argument);
756 Message msg = mMainThreadHandler.obtainMessage(command, request);
757 msg.sendToTarget();
758 }
759
760 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700761 * Initialize the singleton PhoneInterfaceManager instance.
762 * This is only done once, at startup, from PhoneApp.onCreate().
763 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700764 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700765 synchronized (PhoneInterfaceManager.class) {
766 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700767 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700768 } else {
769 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
770 }
771 return sInstance;
772 }
773 }
774
775 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700776 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700777 mApp = app;
778 mPhone = phone;
779 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700780 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
782 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700783 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700784 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800785 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800786
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700787 publish();
788 }
789
790 private void publish() {
791 if (DBG) log("publish: " + this);
792
793 ServiceManager.addService("phone", this);
794 }
795
Stuart Scott584921c2015-01-15 17:10:34 -0800796 private Phone getPhoneFromRequest(MainThreadRequest request) {
797 return (request.subId == null) ? mPhone : getPhone(request.subId);
798 }
799
Wink Saville36469e72014-06-11 15:17:00 -0700800 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700801 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800802 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700804 //
805 // Implementation of the ITelephony interface.
806 //
807
808 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700809 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700810 }
811
Wink Savilleb564aae2014-10-23 10:18:09 -0700812 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700813 if (DBG) log("dial: " + number);
814 // No permission check needed here: This is just a wrapper around the
815 // ACTION_DIAL intent, which is available to any app since it puts up
816 // the UI before it does anything.
817
818 String url = createTelUrl(number);
819 if (url == null) {
820 return;
821 }
822
823 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -0700824 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700825 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
826 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
827 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
828 mApp.startActivity(intent);
829 }
830 }
831
832 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700833 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -0700834 }
835
Wink Savilleb564aae2014-10-23 10:18:09 -0700836 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700837 if (DBG) log("call: " + number);
838
839 // This is just a wrapper around the ACTION_CALL intent, but we still
840 // need to do a permission check since we're calling startActivity()
841 // from the context of the phone app.
842 enforceCallPermission();
843
844 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
845 != AppOpsManager.MODE_ALLOWED) {
846 return;
847 }
848
849 String url = createTelUrl(number);
850 if (url == null) {
851 return;
852 }
853
Wink Saville08874612014-08-31 19:19:58 -0700854 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100855 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -0800856 if (slist != null) {
857 for (SubscriptionInfo subInfoRecord : slist) {
858 if (subInfoRecord.getSubscriptionId() == subId) {
859 isValid = true;
860 break;
861 }
Wink Saville08874612014-08-31 19:19:58 -0700862 }
863 }
864 if (isValid == false) {
865 return;
866 }
867
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700868 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -0700869 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700870 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
871 mApp.startActivity(intent);
872 }
873
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700874 /**
875 * End a call based on call state
876 * @return true is a call was ended
877 */
878 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700879 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700880 }
881
882 /**
883 * End a call based on the call state of the subId
884 * @return true is a call was ended
885 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700886 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700887 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800888 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700889 }
890
891 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700892 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700893 }
894
Wink Savilleb564aae2014-10-23 10:18:09 -0700895 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700896 if (DBG) log("answerRingingCall...");
897 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
898 // but that can probably wait till the big TelephonyManager API overhaul.
899 // For now, protect this call with the MODIFY_PHONE_STATE permission.
900 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800901 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700902 }
903
904 /**
905 * Make the actual telephony calls to implement answerRingingCall().
906 * This should only be called from the main thread of the Phone app.
907 * @see #answerRingingCall
908 *
909 * TODO: it would be nice to return true if we answered the call, or
910 * false if there wasn't actually a ringing incoming call, or some
911 * other error occurred. (In other words, pass back the return value
912 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
913 * But that would require calling this method via sendRequest() rather
914 * than sendRequestAsync(), and right now we don't actually *need* that
915 * return value, so let's just return void for now.
916 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700917 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -0700918 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700919 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -0700920 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
921 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700922 if (hasActiveCall && hasHoldingCall) {
923 // Both lines are in use!
924 // TODO: provide a flag to let the caller specify what
925 // policy to use if both lines are in use. (The current
926 // behavior is hardwired to "answer incoming, end ongoing",
927 // which is how the CALL button is specced to behave.)
928 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
929 return;
930 } else {
931 // answerCall() will automatically hold the current active
932 // call, if there is one.
933 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
934 return;
935 }
936 } else {
937 // No call was ringing.
938 return;
939 }
940 }
941
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -0700943 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700944 */
Santos Cordon5422a8d2014-09-12 04:20:56 -0700945 public void silenceRinger() {
946 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 }
948
949 public boolean isOffhook() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700950 return isOffhookForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700951 }
952
Wink Savilleb564aae2014-10-23 10:18:09 -0700953 public boolean isOffhookForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -0700954 final Phone phone = getPhone(subId);
955 if (phone != null) {
956 return (phone.getState() == PhoneConstants.State.OFFHOOK);
957 } else {
958 return false;
959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700960 }
961
962 public boolean isRinging() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700963 return (isRingingForSubscriber(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -0700964 }
965
Wink Savilleb564aae2014-10-23 10:18:09 -0700966 public boolean isRingingForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -0700967 final Phone phone = getPhone(subId);
968 if (phone != null) {
969 return (phone.getState() == PhoneConstants.State.RINGING);
970 } else {
971 return false;
972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700973 }
974
975 public boolean isIdle() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700976 return isIdleForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700977 }
978
Wink Savilleb564aae2014-10-23 10:18:09 -0700979 public boolean isIdleForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -0700980 final Phone phone = getPhone(subId);
981 if (phone != null) {
982 return (phone.getState() == PhoneConstants.State.IDLE);
983 } else {
984 return false;
985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700986 }
987
Svet Ganovb320e182015-04-16 12:30:10 -0700988 public boolean isSimPinEnabled(String callingPackage) {
989 if (!canReadPhoneState(callingPackage, "isSimPinEnabled")) {
990 return false;
991 }
992
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 return (PhoneGlobals.getInstance().isSimPinEnabled());
994 }
995
996 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700997 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -0700998 }
999
Wink Savilleb564aae2014-10-23 10:18:09 -07001000 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001001 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001002 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1003 }
1004
1005 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001006 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001007 }
1008
Wink Savilleb564aae2014-10-23 10:18:09 -07001009 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001010 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001011 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1012 }
1013
1014 /** {@hide} */
1015 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001016 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001017 }
1018
Wink Savilleb564aae2014-10-23 10:18:09 -07001019 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001020 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001021 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001022 checkSimPin.start();
1023 return checkSimPin.unlockSim(null, pin);
1024 }
1025
Wink Saville9de0f752013-10-22 19:04:03 -07001026 /** {@hide} */
1027 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001028 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001029 }
1030
Wink Savilleb564aae2014-10-23 10:18:09 -07001031 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001033 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001034 checkSimPuk.start();
1035 return checkSimPuk.unlockSim(puk, pin);
1036 }
1037
1038 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001039 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 * a synchronous one.
1041 */
1042 private static class UnlockSim extends Thread {
1043
1044 private final IccCard mSimCard;
1045
1046 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001047 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1048 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001049
1050 // For replies from SimCard interface
1051 private Handler mHandler;
1052
1053 // For async handler to identify request type
1054 private static final int SUPPLY_PIN_COMPLETE = 100;
1055
1056 public UnlockSim(IccCard simCard) {
1057 mSimCard = simCard;
1058 }
1059
1060 @Override
1061 public void run() {
1062 Looper.prepare();
1063 synchronized (UnlockSim.this) {
1064 mHandler = new Handler() {
1065 @Override
1066 public void handleMessage(Message msg) {
1067 AsyncResult ar = (AsyncResult) msg.obj;
1068 switch (msg.what) {
1069 case SUPPLY_PIN_COMPLETE:
1070 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1071 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001072 mRetryCount = msg.arg1;
1073 if (ar.exception != null) {
1074 if (ar.exception instanceof CommandException &&
1075 ((CommandException)(ar.exception)).getCommandError()
1076 == CommandException.Error.PASSWORD_INCORRECT) {
1077 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1078 } else {
1079 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1080 }
1081 } else {
1082 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 mDone = true;
1085 UnlockSim.this.notifyAll();
1086 }
1087 break;
1088 }
1089 }
1090 };
1091 UnlockSim.this.notifyAll();
1092 }
1093 Looper.loop();
1094 }
1095
1096 /*
1097 * Use PIN or PUK to unlock SIM card
1098 *
1099 * If PUK is null, unlock SIM card with PIN
1100 *
1101 * If PUK is not null, unlock SIM card with PUK and set PIN code
1102 */
Wink Saville9de0f752013-10-22 19:04:03 -07001103 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001104
1105 while (mHandler == null) {
1106 try {
1107 wait();
1108 } catch (InterruptedException e) {
1109 Thread.currentThread().interrupt();
1110 }
1111 }
1112 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1113
1114 if (puk == null) {
1115 mSimCard.supplyPin(pin, callback);
1116 } else {
1117 mSimCard.supplyPuk(puk, pin, callback);
1118 }
1119
1120 while (!mDone) {
1121 try {
1122 Log.d(LOG_TAG, "wait for done");
1123 wait();
1124 } catch (InterruptedException e) {
1125 // Restore the interrupted status
1126 Thread.currentThread().interrupt();
1127 }
1128 }
1129 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001130 int[] resultArray = new int[2];
1131 resultArray[0] = mResult;
1132 resultArray[1] = mRetryCount;
1133 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 }
1135 }
1136
1137 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001139
1140 }
1141
Wink Savilleb564aae2014-10-23 10:18:09 -07001142 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 // No permission check needed here: this call is harmless, and it's
1144 // needed for the ServiceState.requestStateUpdate() call (which is
1145 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001146 final Phone phone = getPhone(subId);
1147 if (phone != null) {
1148 phone.updateServiceLocation();
1149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 }
1151
1152 public boolean isRadioOn() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001153 return isRadioOnForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001154 }
1155
Wink Savilleb564aae2014-10-23 10:18:09 -07001156 public boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001157 final Phone phone = getPhone(subId);
1158 if (phone != null) {
1159 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1160 } else {
1161 return false;
1162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 }
1164
1165 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001166 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 }
Wink Saville36469e72014-06-11 15:17:00 -07001169
Wink Savilleb564aae2014-10-23 10:18:09 -07001170 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001172 final Phone phone = getPhone(subId);
1173 if (phone != null) {
1174 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1175 }
Wink Saville36469e72014-06-11 15:17:00 -07001176 }
1177
1178 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001179 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001180 }
1181
Wink Savilleb564aae2014-10-23 10:18:09 -07001182 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001183 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001184 final Phone phone = getPhone(subId);
1185 if (phone == null) {
1186 return false;
1187 }
1188 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001189 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001190 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192 return true;
1193 }
Wink Saville36469e72014-06-11 15:17:00 -07001194
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001195 public boolean needMobileRadioShutdown() {
1196 /*
1197 * If any of the Radios are available, it will need to be
1198 * shutdown. So return true if any Radio is available.
1199 */
1200 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1201 Phone phone = PhoneFactory.getPhone(i);
1202 if (phone != null && phone.isRadioAvailable()) return true;
1203 }
1204 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1205 return false;
1206 }
1207
1208 public void shutdownMobileRadios() {
1209 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1210 logv("Shutting down Phone " + i);
1211 shutdownRadioUsingPhoneId(i);
1212 }
1213 }
1214
1215 private void shutdownRadioUsingPhoneId(int phoneId) {
1216 enforceModifyPermission();
1217 Phone phone = PhoneFactory.getPhone(phoneId);
1218 if (phone != null && phone.isRadioAvailable()) {
1219 phone.shutdownRadio();
1220 }
1221 }
1222
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 public boolean setRadioPower(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001224 return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001225 }
1226
Wink Savilleb564aae2014-10-23 10:18:09 -07001227 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001229 final Phone phone = getPhone(subId);
1230 if (phone != null) {
1231 phone.setRadioPower(turnOn);
1232 return true;
1233 } else {
1234 return false;
1235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 }
1237
Wink Saville36469e72014-06-11 15:17:00 -07001238 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001239 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240 public boolean enableDataConnectivity() {
1241 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001242 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001243 final Phone phone = getPhone(subId);
1244 if (phone != null) {
1245 phone.setDataEnabled(true);
1246 return true;
1247 } else {
1248 return false;
1249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Wink Saville36469e72014-06-11 15:17:00 -07001252 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001253 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 public boolean disableDataConnectivity() {
1255 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001256 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001257 final Phone phone = getPhone(subId);
1258 if (phone != null) {
1259 phone.setDataEnabled(false);
1260 return true;
1261 } else {
1262 return false;
1263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 }
1265
Wink Saville36469e72014-06-11 15:17:00 -07001266 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001267 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001269 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001270 final Phone phone = getPhone(subId);
1271 if (phone != null) {
1272 return phone.isDataConnectivityPossible();
1273 } else {
1274 return false;
1275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 }
1277
1278 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001279 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
Wink Savilleb564aae2014-10-23 10:18:09 -07001282 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001284 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1285 return false;
1286 }
Wink Saville36469e72014-06-11 15:17:00 -07001287 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 }
1289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 public int getCallState() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001291 return getCallStateForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001292 }
1293
Wink Savilleb564aae2014-10-23 10:18:09 -07001294 public int getCallStateForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001295 return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 }
1297
Sanket Padawe356d7632015-06-22 14:03:32 -07001298 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001300 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001301 if (phone != null) {
1302 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1303 } else {
1304 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 }
1307
Sanket Padawe356d7632015-06-22 14:03:32 -07001308 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001310 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001311 if (phone != null) {
1312 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1313 } else {
1314 return TelephonyManager.DATA_ACTIVITY_NONE;
1315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 }
1317
1318 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001319 public Bundle getCellLocation(String callingPackage) {
1320 enforceFineOrCoarseLocationPermission("getCellLocation");
1321
1322 // OP_COARSE_LOCATION controls both fine and coarse location.
1323 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1324 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001325 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001326 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 }
1328
Jake Hambye994d462014-02-03 13:10:13 -08001329 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 if (DBG_LOC) log("getCellLocation: is active user");
1331 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001332 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001333 if (phone == null) {
1334 return null;
1335 }
Legler Wu2c01cdf2014-12-08 19:00:59 +08001336 phone.getCellLocation().fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 return data;
1338 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001339 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 return null;
1341 }
1342 }
1343
Svetoslav64fad262015-04-14 14:35:21 -07001344 private void enforceFineOrCoarseLocationPermission(String message) {
1345 try {
1346 mApp.enforceCallingOrSelfPermission(
1347 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1348 } catch (SecurityException e) {
1349 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1350 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1351 // is the weaker precondition
1352 mApp.enforceCallingOrSelfPermission(
1353 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1354 }
1355 }
1356
1357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 @Override
1359 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Sanket Padawe356d7632015-06-22 14:03:32 -07001363 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 mApp.enforceCallingOrSelfPermission(
1366 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001367 final Phone phone = getPhone(subId);
1368 if (phone != null) {
1369 phone.enableLocationUpdates();
1370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 }
1372
1373 @Override
1374 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Sanket Padawe356d7632015-06-22 14:03:32 -07001378 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001379 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mApp.enforceCallingOrSelfPermission(
1381 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001382 final Phone phone = getPhone(subId);
1383 if (phone != null) {
1384 phone.disableLocationUpdates();
1385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 }
1387
1388 @Override
1389 @SuppressWarnings("unchecked")
1390 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001391 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1392
1393 // OP_COARSE_LOCATION controls both fine and coarse location.
1394 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1395 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1396 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001397 }
1398
1399 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1400 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1401 return null;
1402 }
Svetoslav64fad262015-04-14 14:35:21 -07001403
Jake Hambye994d462014-02-03 13:10:13 -08001404 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1406
1407 ArrayList<NeighboringCellInfo> cells = null;
1408
1409 try {
1410 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Wink Saville36469e72014-06-11 15:17:00 -07001411 CMD_HANDLE_NEIGHBORING_CELL, null, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001413 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 }
1415 return cells;
1416 } else {
1417 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1418 return null;
1419 }
1420 }
1421
1422
1423 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001424 public List<CellInfo> getAllCellInfo(String callingPackage) {
1425 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1426
1427 // OP_COARSE_LOCATION controls both fine and coarse location.
1428 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1429 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1430 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 }
1432
Jake Hambye994d462014-02-03 13:10:13 -08001433 if (checkIfCallerIsSelfOrForegroundUser()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434 if (DBG_LOC) log("getAllCellInfo: is active user");
Legler Wu2c01cdf2014-12-08 19:00:59 +08001435 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1436 for (Phone phone : PhoneFactory.getPhones()) {
1437 cellInfos.addAll(phone.getAllCellInfo());
1438 }
1439 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 } else {
1441 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1442 return null;
1443 }
1444 }
1445
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001446 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 public void setCellInfoListRate(int rateInMillis) {
1448 mPhone.setCellInfoListRate(rateInMillis);
1449 }
1450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 //
1452 // Internal helper methods.
1453 //
1454
Jake Hambye994d462014-02-03 13:10:13 -08001455 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 boolean ok;
1457
1458 boolean self = Binder.getCallingUid() == Process.myUid();
1459 if (!self) {
1460 // Get the caller's user id then clear the calling identity
1461 // which will be restored in the finally clause.
1462 int callingUser = UserHandle.getCallingUserId();
1463 long ident = Binder.clearCallingIdentity();
1464
1465 try {
1466 // With calling identity cleared the current user is the foreground user.
1467 int foregroundUser = ActivityManager.getCurrentUser();
1468 ok = (foregroundUser == callingUser);
1469 if (DBG_LOC) {
1470 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1471 + " callingUser=" + callingUser + " ok=" + ok);
1472 }
1473 } catch (Exception ex) {
1474 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1475 ok = false;
1476 } finally {
1477 Binder.restoreCallingIdentity(ident);
1478 }
1479 } else {
1480 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1481 ok = true;
1482 }
1483 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1484 return ok;
1485 }
1486
1487 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1489 *
1490 * @throws SecurityException if the caller does not have the required permission
1491 */
1492 private void enforceModifyPermission() {
1493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1494 }
1495
1496 /**
Junda Liua2e36012014-07-09 18:30:01 -07001497 * Make sure either system app or the caller has carrier privilege.
1498 *
1499 * @throws SecurityException if the caller does not have the required permission/privilege
1500 */
1501 private void enforceModifyPermissionOrCarrierPrivilege() {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001502 int permission = mApp.checkCallingOrSelfPermission(
1503 android.Manifest.permission.MODIFY_PHONE_STATE);
1504 if (permission == PackageManager.PERMISSION_GRANTED) {
1505 return;
1506 }
1507
1508 log("No modify permission, check carrier privilege next.");
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001509 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001510 loge("No Carrier Privilege.");
1511 throw new SecurityException("No modify permission or carrier privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001512 }
1513 }
1514
1515 /**
1516 * Make sure the caller has carrier privilege.
1517 *
1518 * @throws SecurityException if the caller does not have the required permission
1519 */
1520 private void enforceCarrierPrivilege() {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001521 if (getCarrierPrivilegeStatus() != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001522 loge("No Carrier Privilege.");
1523 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001524 }
1525 }
1526
1527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 * Make sure the caller has the CALL_PHONE permission.
1529 *
1530 * @throws SecurityException if the caller does not have the required permission
1531 */
1532 private void enforceCallPermission() {
1533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1534 }
1535
Shishir Agrawal566b7612013-10-28 14:41:00 -07001536 /**
Gabriel Peal36ebb0d2014-03-20 09:20:43 -07001537 * Make sure the caller has the READ_PRIVILEGED_PHONE_STATE permission.
1538 *
1539 * @throws SecurityException if the caller does not have the required permission
1540 */
1541 private void enforcePrivilegedPhoneStatePermission() {
1542 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1543 null);
1544 }
1545
Stuart Scott8eef64f2015-04-08 15:13:54 -07001546 private void enforceConnectivityInternalPermission() {
1547 mApp.enforceCallingOrSelfPermission(
1548 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1549 "ConnectivityService");
1550 }
1551
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 private String createTelUrl(String number) {
1553 if (TextUtils.isEmpty(number)) {
1554 return null;
1555 }
1556
Jake Hambye994d462014-02-03 13:10:13 -08001557 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 }
1559
Ihab Awadf9e92732013-12-05 18:02:52 -08001560 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1562 }
1563
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001564 private static void logv(String msg) {
1565 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1566 }
1567
Ihab Awadf9e92732013-12-05 18:02:52 -08001568 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1570 }
1571
1572 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001573 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001574 }
1575
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001577 public int getActivePhoneTypeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001578 final Phone phone = getPhone(subId);
1579 if (phone == null) {
1580 return PhoneConstants.PHONE_TYPE_NONE;
1581 } else {
1582 return getPhone(subId).getPhoneType();
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
1586 /**
1587 * Returns the CDMA ERI icon index to display
1588 */
1589 public int getCdmaEriIconIndex() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public int getCdmaEriIconIndexForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 final Phone phone = getPhone(subId);
1596 if (phone != null) {
1597 return phone.getCdmaEriIconIndex();
1598 } else {
1599 return -1;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
1603 /**
1604 * Returns the CDMA ERI icon mode,
1605 * 0 - ON
1606 * 1 - FLASHING
1607 */
1608 public int getCdmaEriIconMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001609 return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001610 }
1611
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001613 public int getCdmaEriIconModeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 return phone.getCdmaEriIconMode();
1617 } else {
1618 return -1;
1619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
1622 /**
1623 * Returns the CDMA ERI text,
1624 */
1625 public String getCdmaEriText() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001626 return getCdmaEriTextForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001630 public String getCdmaEriTextForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 final Phone phone = getPhone(subId);
1632 if (phone != null) {
1633 return phone.getCdmaEriText();
1634 } else {
1635 return null;
1636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 }
1638
1639 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001640 * Returns the CDMA MDN.
1641 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001643 public String getCdmaMdn(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001644 enforceModifyPermissionOrCarrierPrivilege();
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 final Phone phone = getPhone(subId);
1646 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1647 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001648 } else {
1649 return null;
1650 }
1651 }
1652
1653 /**
1654 * Returns the CDMA MIN.
1655 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001657 public String getCdmaMin(int subId) {
Junda Liuca05d5d2014-08-14 22:36:34 -07001658 enforceModifyPermissionOrCarrierPrivilege();
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 final Phone phone = getPhone(subId);
1660 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1661 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001662 } else {
1663 return null;
1664 }
1665 }
1666
1667 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 * Returns true if CDMA provisioning needs to run.
1669 */
1670 public boolean needsOtaServiceProvisioning() {
1671 return mPhone.needsOtaServiceProvisioning();
1672 }
1673
1674 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001675 * Sets the voice mail number of a given subId.
1676 */
1677 @Override
1678 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08001679 enforceCarrierPrivilege();
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001680 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1681 new Pair<String, String>(alphaTag, number), new Integer(subId));
1682 return success;
1683 }
1684
1685 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 * Returns the unread count of voicemails
1687 */
1688 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001689 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001690 }
1691
1692 /**
1693 * Returns the unread count of voicemails for a subId
1694 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 return phone.getVoiceMessageCount();
1700 } else {
1701 return 0;
1702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 /**
1706 * Returns the data network type
1707 *
1708 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1709 */
1710 @Override
1711 public int getNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001712 return getNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001713 }
1714
1715 /**
1716 * Returns the network type for a subId
1717 */
1718 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001719 public int getNetworkTypeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 final Phone phone = getPhone(subId);
1721 if (phone != null) {
1722 return phone.getServiceState().getDataNetworkType();
1723 } else {
1724 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 /**
1729 * Returns the data network type
1730 */
1731 @Override
1732 public int getDataNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 return getDataNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
1736 /**
1737 * Returns the data network type for a subId
1738 */
1739 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001740 public int getDataNetworkTypeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
1743 return phone.getServiceState().getDataNetworkType();
1744 } else {
1745 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
1749 /**
1750 * Returns the data network type
1751 */
1752 @Override
1753 public int getVoiceNetworkType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001754 return getVoiceNetworkTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
1757 /**
1758 * Returns the Voice network type for a subId
1759 */
1760 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001761 public int getVoiceNetworkTypeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 final Phone phone = getPhone(subId);
1763 if (phone != null) {
1764 return phone.getServiceState().getVoiceNetworkType();
1765 } else {
1766 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
1770 /**
1771 * @return true if a ICC card is present
1772 */
1773 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001774 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001775 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07001776 }
1777
1778 /**
1779 * @return true if a ICC card is present for a slotId
1780 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001781 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001783 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 final Phone phone = getPhone(subId[0]);
1785 if (subId != null && phone != null) {
1786 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001787 } else {
1788 return false;
1789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
1792 /**
1793 * Return if the current radio is LTE on CDMA. This
1794 * is a tri-state return value as for a period of time
1795 * the mode may be unknown.
1796 *
1797 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001798 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 */
1800 public int getLteOnCdmaMode() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001801 return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001802 }
1803
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public int getLteOnCdmaModeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 final Phone phone = getPhone(subId);
1807 if (phone == null) {
1808 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1809 } else {
1810 return phone.getLteOnCdmaMode();
1811 }
Wink Saville36469e72014-06-11 15:17:00 -07001812 }
1813
1814 public void setPhone(Phone phone) {
1815 mPhone = phone;
1816 }
1817
1818 /**
1819 * {@hide}
1820 * Returns Default subId, 0 in the case of single standby.
1821 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001822 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001823 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001824 }
1825
Wink Savilleb564aae2014-10-23 10:18:09 -07001826 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001827 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001829
1830 /**
1831 * @see android.telephony.TelephonyManager.WifiCallingChoices
1832 */
1833 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001834 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1835 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001836 }
1837
1838 /**
1839 * @see android.telephony.TelephonyManager.WifiCallingChoices
1840 */
1841 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001842 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1843 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1844 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001845 }
1846
Sailesh Nepald1e68152013-12-12 19:08:02 -08001847 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001848 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001849 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001850 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001851
Shishir Agrawal566b7612013-10-28 14:41:00 -07001852 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001853 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) {
Junda Liua2e36012014-07-09 18:30:01 -07001854 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001855
1856 if (DBG) log("iccOpenLogicalChannel: " + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001857 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
1858 CMD_OPEN_CHANNEL, AID);
1859 if (DBG) log("iccOpenLogicalChannel: " + response);
1860 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001861 }
1862
1863 @Override
1864 public boolean iccCloseLogicalChannel(int channel) {
Junda Liua2e36012014-07-09 18:30:01 -07001865 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001866
1867 if (DBG) log("iccCloseLogicalChannel: " + channel);
1868 if (channel < 0) {
1869 return false;
1870 }
Jake Hambye994d462014-02-03 13:10:13 -08001871 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001872 if (DBG) log("iccCloseLogicalChannel: " + success);
1873 return success;
1874 }
1875
1876 @Override
1877 public String iccTransmitApduLogicalChannel(int channel, int cla,
1878 int command, int p1, int p2, int p3, String data) {
Junda Liua2e36012014-07-09 18:30:01 -07001879 enforceModifyPermissionOrCarrierPrivilege();
Shishir Agrawal566b7612013-10-28 14:41:00 -07001880
1881 if (DBG) {
1882 log("iccTransmitApduLogicalChannel: chnl=" + channel + " cla=" + cla +
1883 " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
1884 " data=" + data);
1885 }
1886
1887 if (channel < 0) {
1888 return "";
1889 }
1890
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001891 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawal566b7612013-10-28 14:41:00 -07001892 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data));
1893 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
1894
Shishir Agrawal566b7612013-10-28 14:41:00 -07001895 // Append the returned status code to the end of the response payload.
1896 String s = Integer.toHexString(
1897 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001898 if (response.payload != null) {
1899 s = IccUtils.bytesToHexString(response.payload) + s;
1900 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001901 return s;
1902 }
Jake Hambye994d462014-02-03 13:10:13 -08001903
Evan Charltonc66da362014-05-16 14:06:40 -07001904 @Override
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001905 public String iccTransmitApduBasicChannel(int cla, int command, int p1, int p2,
1906 int p3, String data) {
1907 enforceModifyPermissionOrCarrierPrivilege();
1908
1909 if (DBG) {
1910 log("iccTransmitApduBasicChannel: cla=" + cla + " cmd=" + command + " p1="
1911 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
1912 }
1913
1914 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
1915 new IccAPDUArgument(0, cla, command, p1, p2, p3, data));
1916 if (DBG) log("iccTransmitApduBasicChannel: " + response);
1917
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001918 // Append the returned status code to the end of the response payload.
1919 String s = Integer.toHexString(
1920 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07001921 if (response.payload != null) {
1922 s = IccUtils.bytesToHexString(response.payload) + s;
1923 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001924 return s;
1925 }
1926
1927 @Override
1928 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3,
1929 String filePath) {
1930 enforceModifyPermissionOrCarrierPrivilege();
1931
1932 if (DBG) {
1933 log("Exchange SIM_IO " + fileID + ":" + command + " " +
1934 p1 + " " + p2 + " " + p3 + ":" + filePath);
1935 }
1936
1937 IccIoResult response =
1938 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Yong Jiang3edf3782014-10-03 13:23:28 -05001939 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath));
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001940
1941 if (DBG) {
1942 log("Exchange SIM_IO [R]" + response);
1943 }
1944
1945 byte[] result = null;
1946 int length = 2;
1947 if (response.payload != null) {
1948 length = 2 + response.payload.length;
1949 result = new byte[length];
1950 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
1951 } else {
1952 result = new byte[length];
1953 }
1954
1955 result[length - 1] = (byte) response.sw2;
1956 result[length - 2] = (byte) response.sw1;
1957 return result;
1958 }
1959
1960 @Override
Evan Charltonc66da362014-05-16 14:06:40 -07001961 public String sendEnvelopeWithStatus(String content) {
Junda Liua2e36012014-07-09 18:30:01 -07001962 enforceModifyPermissionOrCarrierPrivilege();
Evan Charltonc66da362014-05-16 14:06:40 -07001963
1964 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content);
1965 if (response.payload == null) {
1966 return "";
1967 }
1968
1969 // Append the returned status code to the end of the response payload.
1970 String s = Integer.toHexString(
1971 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
1972 s = IccUtils.bytesToHexString(response.payload) + s;
1973 return s;
1974 }
1975
Jake Hambye994d462014-02-03 13:10:13 -08001976 /**
1977 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1978 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1979 *
1980 * @param itemID the ID of the item to read
1981 * @return the NV item as a String, or null on error.
1982 */
1983 @Override
1984 public String nvReadItem(int itemID) {
Junda Liua2e36012014-07-09 18:30:01 -07001985 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08001986 if (DBG) log("nvReadItem: item " + itemID);
1987 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
1988 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
1989 return value;
1990 }
1991
1992 /**
1993 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
1994 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
1995 *
1996 * @param itemID the ID of the item to read
1997 * @param itemValue the value to write, as a String
1998 * @return true on success; false on any failure
1999 */
2000 @Override
2001 public boolean nvWriteItem(int itemID, String itemValue) {
Junda Liua2e36012014-07-09 18:30:01 -07002002 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08002003 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2004 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2005 new Pair<Integer, String>(itemID, itemValue));
2006 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2007 return success;
2008 }
2009
2010 /**
2011 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2012 * Used for device configuration by some CDMA operators.
2013 *
2014 * @param preferredRoamingList byte array containing the new PRL
2015 * @return true on success; false on any failure
2016 */
2017 @Override
2018 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Junda Liua2e36012014-07-09 18:30:01 -07002019 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08002020 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2021 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2022 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2023 return success;
2024 }
2025
2026 /**
2027 * Perform the specified type of NV config reset.
2028 * Used for device configuration by some CDMA operators.
2029 *
2030 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2031 * @return true on success; false on any failure
2032 */
2033 @Override
2034 public boolean nvResetConfig(int resetType) {
Junda Liua2e36012014-07-09 18:30:01 -07002035 enforceModifyPermissionOrCarrierPrivilege();
Jake Hambye994d462014-02-03 13:10:13 -08002036 if (DBG) log("nvResetConfig: type " + resetType);
2037 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2038 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2039 return success;
2040 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002041
2042 /**
Wink Saville36469e72014-06-11 15:17:00 -07002043 * {@hide}
2044 * Returns Default sim, 0 in the case of single standby.
2045 */
2046 public int getDefaultSim() {
2047 //TODO Need to get it from Telephony Devcontroller
2048 return 0;
2049 }
2050
Svet Ganovb320e182015-04-16 12:30:10 -07002051 public String[] getPcscfAddress(String apnType, String callingPackage) {
2052 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2053 return new String[0];
2054 }
2055
2056
ram87fca6f2014-07-18 18:58:44 +05302057 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002058 }
2059
2060 public void setImsRegistrationState(boolean registered) {
2061 enforceModifyPermission();
2062 mPhone.setImsRegistrationState(registered);
2063 }
2064
2065 /**
Stuart Scott54788802015-03-30 13:18:01 -07002066 * Set the network selection mode to automatic.
2067 *
2068 */
2069 @Override
2070 public void setNetworkSelectionModeAutomatic(int subId) {
2071 enforceModifyPermissionOrCarrierPrivilege();
2072 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2073 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2074 }
2075
2076 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002077 * Get the calculated preferred network type.
2078 * Used for debugging incorrect network type.
2079 *
2080 * @return the preferred network type, defined in RILConstants.java.
2081 */
2082 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002083 public int getCalculatedPreferredNetworkType(String callingPackage) {
2084 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2085 return RILConstants.PREFERRED_NETWORK_MODE;
2086 }
2087
Amit Mahajan43330e02014-11-18 11:54:45 -08002088 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002089 }
2090
2091 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002092 * Get the preferred network type.
2093 * Used for device configuration by some CDMA operators.
2094 *
2095 * @return the preferred network type, defined in RILConstants.java.
2096 */
2097 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002098 public int getPreferredNetworkType(int subId) {
Junda Liua2e36012014-07-09 18:30:01 -07002099 enforceModifyPermissionOrCarrierPrivilege();
Jake Hamby7c27be32014-03-03 13:25:59 -08002100 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002101 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002102 int networkType = (result != null ? result[0] : -1);
2103 if (DBG) log("getPreferredNetworkType: " + networkType);
2104 return networkType;
2105 }
2106
2107 /**
2108 * Set the preferred network type.
2109 * Used for device configuration by some CDMA operators.
2110 *
2111 * @param networkType the preferred network type, defined in RILConstants.java.
2112 * @return true on success; false on any failure.
2113 */
2114 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002115 public boolean setPreferredNetworkType(int subId, int networkType) {
Junda Liua2e36012014-07-09 18:30:01 -07002116 enforceModifyPermissionOrCarrierPrivilege();
Stuart Scott54788802015-03-30 13:18:01 -07002117 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2118 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002119 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002120 if (success) {
2121 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002122 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002123 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002124 return success;
2125 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002126
2127 /**
Junda Liu475951f2014-11-07 16:45:03 -08002128 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2129 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2130 * tethering.
2131 *
2132 * @return 0: Not required. 1: required. 2: Not set.
2133 * @hide
2134 */
2135 @Override
2136 public int getTetherApnRequired() {
2137 enforceModifyPermissionOrCarrierPrivilege();
2138 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2139 Settings.Global.TETHER_DUN_REQUIRED, 2);
2140 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2141 // config_tether_apndata.
2142 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2143 dunRequired = 1;
2144 }
2145 return dunRequired;
2146 }
2147
2148 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002149 * Set mobile data enabled
2150 * Used by the user through settings etc to turn on/off mobile data
2151 *
2152 * @param enable {@code true} turn turn data on, else {@code false}
2153 */
2154 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002155 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07002156 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08002157 int phoneId = mSubscriptionController.getPhoneId(subId);
2158 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2159 Phone phone = PhoneFactory.getPhone(phoneId);
2160 if (phone != null) {
2161 log("setDataEnabled: subId=" + subId + " enable=" + enable);
2162 phone.setDataEnabled(enable);
2163 } else {
2164 loge("setDataEnabled: no phone for subId=" + subId);
2165 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002166 }
2167
2168 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002169 * Get whether mobile data is enabled.
2170 *
2171 * Note that this used to be available from ConnectivityService, gated by
2172 * ACCESS_NETWORK_STATE permission, so this will accept either that or
2173 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07002174 *
2175 * @return {@code true} if data is enabled else {@code false}
2176 */
2177 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002178 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002179 try {
2180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2181 null);
2182 } catch (Exception e) {
2183 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
2184 null);
2185 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002186 int phoneId = mSubscriptionController.getPhoneId(subId);
2187 log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2188 Phone phone = PhoneFactory.getPhone(phoneId);
2189 if (phone != null) {
2190 boolean retVal = phone.getDataEnabled();
2191 log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
2192 return retVal;
2193 } else {
2194 loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
2195 return false;
2196 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002197 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002198
2199 @Override
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002200 public int getCarrierPrivilegeStatus() {
Shishir Agrawal21409252015-01-15 23:33:50 -08002201 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002202 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002203 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002204 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2205 }
2206 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07002207 mPhone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002208 }
Junda Liu29340342014-07-10 15:23:27 -07002209
2210 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002211 public int checkCarrierPrivilegesForPackage(String pkgName) {
Shishir Agrawal21409252015-01-15 23:33:50 -08002212 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002213 if (card == null) {
2214 loge("checkCarrierPrivilegesForPackage: No UICC");
2215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2216 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002217 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2218 }
2219
2220 @Override
2221 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
2222 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2223 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2224 UiccCard card = UiccController.getInstance().getUiccCard(i);
2225 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002226 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002227 continue;
2228 }
2229
2230 result = card.getCarrierPrivilegeStatus(
2231 mPhone.getContext().getPackageManager(), pkgName);
2232 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2233 break;
2234 }
2235 }
2236
2237 return result;
Junda Liu29340342014-07-10 15:23:27 -07002238 }
Derek Tan89e89d42014-07-08 17:00:10 -07002239
2240 @Override
Junda Liue64de782015-04-16 17:19:16 -07002241 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2242 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2243 loge("phoneId " + phoneId + " is not valid.");
2244 return null;
2245 }
2246 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002247 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002248 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002249 return null ;
2250 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002251 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002252 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002253 }
2254
Wink Savilleb564aae2014-10-23 10:18:09 -07002255 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 final Phone phone = getPhone(subId);
2257 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002258 if (card == null) {
2259 loge("getIccId: No UICC");
2260 return null;
2261 }
2262 String iccId = card.getIccId();
2263 if (TextUtils.isEmpty(iccId)) {
2264 loge("getIccId: ICC ID is null or empty.");
2265 return null;
2266 }
2267 return iccId;
2268 }
2269
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002270 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002271 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2272 String number) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002273 enforceCarrierPrivilege();
Derek Tan97ebb422014-09-05 16:55:38 -07002274
Jeff Sharkey85190e62014-12-05 09:40:12 -08002275 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 final Phone phone = getPhone(subId);
2277 if (phone == null) {
2278 return false;
2279 }
2280 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002281
2282 if (DBG_MERGE) {
2283 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2284 + subscriberId + " to " + number);
2285 }
2286
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002287 if (TextUtils.isEmpty(iccId)) {
2288 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002289 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002290
Jeff Sharkey85190e62014-12-05 09:40:12 -08002291 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2292
2293 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002294 if (alphaTag == null) {
2295 editor.remove(alphaTagPrefKey);
2296 } else {
2297 editor.putString(alphaTagPrefKey, alphaTag);
2298 }
2299
Jeff Sharkey85190e62014-12-05 09:40:12 -08002300 // Record both the line number and IMSI for this ICCID, since we need to
2301 // track all merged IMSIs based on line number
2302 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2303 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002304 if (number == null) {
2305 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002306 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002307 } else {
2308 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002309 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002310 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002311
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002312 editor.commit();
2313 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002314 }
2315
2316 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002317 public String getLine1NumberForDisplay(int subId, String callingPackage) {
2318 if (!canReadPhoneState(callingPackage, "getLine1NumberForDisplay")) {
2319 return null;
2320 }
Derek Tan97ebb422014-09-05 16:55:38 -07002321
2322 String iccId = getIccId(subId);
2323 if (iccId != null) {
2324 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002325 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002326 }
Derek Tan97ebb422014-09-05 16:55:38 -07002327 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002328 }
2329
2330 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002331 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2332 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2333 return null;
2334 }
Derek Tan97ebb422014-09-05 16:55:38 -07002335
2336 String iccId = getIccId(subId);
2337 if (iccId != null) {
2338 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002339 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002340 }
Derek Tan97ebb422014-09-05 16:55:38 -07002341 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002342 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002343
2344 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002345 public String[] getMergedSubscriberIds(String callingPackage) {
2346 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2347 return null;
2348 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002349 final Context context = mPhone.getContext();
2350 final TelephonyManager tele = TelephonyManager.from(context);
2351 final SubscriptionManager sub = SubscriptionManager.from(context);
2352
2353 // Figure out what subscribers are currently active
2354 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002355 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2356 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final int[] subIds = sub.getActiveSubscriptionIdList();
2360 for (int subId : subIds) {
2361 activeSubscriberIds.add(tele.getSubscriberId(subId));
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002365 }
2366
2367 // First pass, find a number override for an active subscriber
2368 String mergeNumber = null;
2369 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2370 for (String key : prefs.keySet()) {
2371 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2372 final String subscriberId = (String) prefs.get(key);
2373 if (activeSubscriberIds.contains(subscriberId)) {
2374 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2375 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2376 mergeNumber = (String) prefs.get(numberKey);
2377 if (DBG_MERGE) {
2378 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2379 + " for active subscriber " + subscriberId);
2380 }
2381 if (!TextUtils.isEmpty(mergeNumber)) {
2382 break;
2383 }
2384 }
2385 }
2386 }
2387
2388 // Shortcut when no active merged subscribers
2389 if (TextUtils.isEmpty(mergeNumber)) {
2390 return null;
2391 }
2392
2393 // Second pass, find all subscribers under that line override
2394 final ArraySet<String> result = new ArraySet<>();
2395 for (String key : prefs.keySet()) {
2396 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2397 final String number = (String) prefs.get(key);
2398 if (mergeNumber.equals(number)) {
2399 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2400 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2401 final String subscriberId = (String) prefs.get(subscriberKey);
2402 if (!TextUtils.isEmpty(subscriberId)) {
2403 result.add(subscriberId);
2404 }
2405 }
2406 }
2407 }
2408
2409 final String[] resultArray = result.toArray(new String[result.size()]);
2410 Arrays.sort(resultArray);
2411 if (DBG_MERGE) {
2412 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2413 }
2414 return resultArray;
2415 }
2416
2417 @Override
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002418 public boolean setOperatorBrandOverride(String brand) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002419 enforceCarrierPrivilege();
Shishir Agrawala3dfd752014-09-04 13:25:42 -07002420 return mPhone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002421 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002422
2423 @Override
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002424 public boolean setRoamingOverride(List<String> gsmRoamingList,
2425 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2426 List<String> cdmaNonRoamingList) {
2427 enforceCarrierPrivilege();
2428 return mPhone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
2429 cdmaNonRoamingList);
2430 }
2431
2432 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002433 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2434 enforceModifyPermission();
2435
2436 int returnValue = 0;
2437 try {
2438 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2439 if(result.exception == null) {
2440 if (result.result != null) {
2441 byte[] responseData = (byte[])(result.result);
2442 if(responseData.length > oemResp.length) {
2443 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2444 responseData.length + "bytes. Buffer Size is " +
2445 oemResp.length + "bytes.");
2446 }
2447 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2448 returnValue = responseData.length;
2449 }
2450 } else {
2451 CommandException ex = (CommandException) result.exception;
2452 returnValue = ex.getCommandError().ordinal();
2453 if(returnValue > 0) returnValue *= -1;
2454 }
2455 } catch (RuntimeException e) {
2456 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2457 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2458 if(returnValue > 0) returnValue *= -1;
2459 }
2460
2461 return returnValue;
2462 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002463
2464 @Override
2465 public void setRadioCapability(RadioAccessFamily[] rafs) {
2466 try {
2467 ProxyController.getInstance().setRadioCapability(rafs);
2468 } catch (RuntimeException e) {
2469 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2470 }
2471 }
2472
2473 @Override
2474 public int getRadioAccessFamily(int phoneId) {
2475 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2476 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002477
2478 @Override
2479 public void enableVideoCalling(boolean enable) {
2480 enforceModifyPermission();
2481 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2482 editor.putBoolean(PREF_ENABLE_VIDEO_CALLING, enable);
2483 editor.commit();
2484 }
2485
2486 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002487 public boolean isVideoCallingEnabled(String callingPackage) {
2488 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2489 return false;
2490 }
2491
Andrew Lee77527ac2014-10-21 16:57:39 -07002492 // Check the user preference and the system-level IMS setting. Even if the user has
2493 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2494 // In the long run, we may instead need to check if there exists a connection service
2495 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002496 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2497 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
2498 && mTelephonySharedPreferences.getBoolean(PREF_ENABLE_VIDEO_CALLING, true);
Andrew Leedf14ead2014-10-17 14:22:52 -07002499 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002500
Andrew Leea1239f22015-03-02 17:44:07 -08002501 @Override
2502 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002503 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002504 }
2505
2506 @Override
2507 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002508 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002509 }
2510
Andrew Lee9431b832015-03-09 18:46:45 -07002511 @Override
2512 public boolean isTtyModeSupported() {
2513 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2514 TelephonyManager telephonyManager =
2515 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
2516 return !telephonyManager.isMultiSimEnabled() && telecomManager.isTtySupported();
2517 }
2518
2519 @Override
2520 public boolean isHearingAidCompatibilitySupported() {
2521 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2522 }
2523
Sanket Padawe7310cc72015-01-14 09:53:20 -08002524 /**
2525 * Returns the unique device ID of phone, for example, the IMEI for
2526 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2527 *
2528 * <p>Requires Permission:
2529 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2530 */
2531 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002532 public String getDeviceId(String callingPackage) {
2533 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2534 return null;
2535 }
2536
Sanket Padawe7310cc72015-01-14 09:53:20 -08002537 final Phone phone = PhoneFactory.getPhone(0);
2538 if (phone != null) {
2539 return phone.getDeviceId();
2540 } else {
2541 return null;
2542 }
2543 }
2544
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002545 /*
2546 * {@hide}
2547 * Returns the IMS Registration Status
2548 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08002549 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002550 public boolean isImsRegistered() {
2551 return mPhone.isImsRegistered();
2552 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08002553
2554 @Override
2555 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
2556 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
2557 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07002558
Nathan Haroldc55097a2015-03-11 18:14:50 -07002559 /*
2560 * {@hide}
2561 * Returns the IMS Registration Status
2562 */
2563 public boolean isWifiCallingEnabled() {
2564 return mPhone.isWifiCallingEnabled();
2565 }
2566
2567 /*
2568 * {@hide}
2569 * Returns the IMS Registration Status
2570 */
2571 public boolean isVolteEnabled() {
2572 return mPhone.isVolteEnabled();
2573 }
Svet Ganovb320e182015-04-16 12:30:10 -07002574
2575 private boolean canReadPhoneState(String callingPackage, String message) {
2576 mApp.enforceCallingOrSelfPermission(
2577 android.Manifest.permission.READ_PHONE_STATE, message);
2578
2579 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
2580 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2581 return false;
2582 }
2583
2584 return true;
2585 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07002586
2587 @Override
2588 public void factoryReset(int subId) {
2589 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07002590 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
2591 return;
2592 }
2593
Svet Ganovcc087f82015-05-12 20:35:54 -07002594 final long identity = Binder.clearCallingIdentity();
2595 try {
Stuart Scott981d8582015-04-21 14:09:50 -07002596 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
2597 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07002598 // Enable data
2599 setDataEnabled(subId, true);
2600 // Set network selection mode to automatic
2601 setNetworkSelectionModeAutomatic(subId);
2602 // Set preferred mobile network type to the best available
2603 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
2604 // Turn off roaming
2605 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002609 }
2610 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01002611
2612 @Override
2613 public String getLocaleFromDefaultSim() {
2614 // We query all subscriptions instead of just the active ones, because
2615 // this might be called early on in the provisioning flow when the
2616 // subscriptions potentially aren't active yet.
2617 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
2618 if (slist == null || slist.isEmpty()) {
2619 return null;
2620 }
2621
2622 // This function may be called very early, say, from the setup wizard, at
2623 // which point we won't have a default subscription set. If that's the case
2624 // we just choose the first, which will be valid in "most cases".
2625 final int defaultSubId = getDefaultSubscription();
2626 SubscriptionInfo info = null;
2627 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
2628 info = slist.get(0);
2629 } else {
2630 for (SubscriptionInfo item : slist) {
2631 if (item.getSubscriptionId() == defaultSubId) {
2632 info = item;
2633 break;
2634 }
2635 }
2636
2637 if (info == null) {
2638 return null;
2639 }
2640 }
2641
2642 // Try and fetch the locale from the carrier properties or from the SIM language
2643 // preferences (EF-PL and EF-LI)...
2644 final Phone defaultPhone = getPhone(info.getSubscriptionId());
2645 if (defaultPhone != null) {
2646 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
2647 if (localeFromDefaultSim != null) {
2648 return localeFromDefaultSim.toLanguageTag();
2649 }
2650 }
2651
2652 // .. if that doesn't work, try and guess the language from the sim MCC.
2653 final int mcc = info.getMcc();
2654 final Locale locale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc);
2655 if (locale != null) {
2656 return locale.toLanguageTag();
2657 }
2658
2659 return null;
2660 }
2661
2662 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 return mSubscriptionController.getAllSubInfoList(
2666 mPhone.getContext().getOpPackageName());
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
2670 }
2671
2672 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
2673 final long identity = Binder.clearCallingIdentity();
2674 try {
2675 return mSubscriptionController.getActiveSubscriptionInfoList(
2676 mPhone.getContext().getOpPackageName());
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
2680 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07002681
2682 /**
2683 * {@hide}
2684 * Returns the modem stats
2685 */
2686 @Override
2687 public ModemActivityInfo getModemActivityInfo() {
2688 return (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690}