blob: 75c6d8787c024206e20f4d44733fa87dc62b322d [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Santos Cordon7d4ddf62013-07-10 11:58:08 -070021import android.app.ActivityManager;
22import android.app.AppOpsManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070023import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.content.Context;
25import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070026import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080027import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070028import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.net.Uri;
30import android.os.AsyncResult;
31import android.os.Binder;
32import android.os.Bundle;
33import android.os.Handler;
34import android.os.Looper;
35import android.os.Message;
36import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070037import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.ServiceManager;
39import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070040import android.os.UserManager;
Sooraj Sasindran600a37a2016-07-18 11:57:25 -070041import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070042import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080043import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070044import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080045import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080046import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070047import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070048import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.telephony.CellInfo;
Sooraj Sasindran600a37a2016-07-18 11:57:25 -070050import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070051import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070052import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080053import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070054import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080056import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080057import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070058import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070059import android.telephony.TelephonyManager;
60import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080062import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080064import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080065import android.util.Slog;
Andrew Lee312e8172014-10-23 17:01:36 -070066import com.android.ims.ImsManager;
Brad Ebinger76681002017-01-23 13:50:20 -080067import com.android.ims.internal.IImsServiceController;
68import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070069import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070070import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070071import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080074import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010075import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070076import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import com.android.internal.telephony.Phone;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070079import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070080import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070081import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070082import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080083import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.uicc.IccIoResult;
85import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070086import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080088import com.android.internal.util.HexDump;
Ta-wei Yenb0f695b2016-08-08 17:33:11 -070089import com.android.phone.settings.VisualVoicemailSettingsUtil;
Nancy Chen31f9ba12016-01-06 11:42:12 -080090import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -070091import java.io.FileDescriptor;
92import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -080095import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +010096import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99/**
100 * Implementation of the ITelephony interface.
101 */
Santos Cordon117fee72014-05-16 17:56:12 -0700102public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 private static final String LOG_TAG = "PhoneInterfaceManager";
104 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
105 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107
108 // Message codes used with mMainThreadHandler
109 private static final int CMD_HANDLE_PIN_MMI = 1;
110 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
111 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
112 private static final int CMD_ANSWER_RINGING_CALL = 4;
113 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700114 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
115 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116 private static final int CMD_OPEN_CHANNEL = 9;
117 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
118 private static final int CMD_CLOSE_CHANNEL = 11;
119 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800120 private static final int CMD_NV_READ_ITEM = 13;
121 private static final int EVENT_NV_READ_ITEM_DONE = 14;
122 private static final int CMD_NV_WRITE_ITEM = 15;
123 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
124 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
125 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
126 private static final int CMD_NV_RESET_CONFIG = 19;
127 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800128 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
129 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
130 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
131 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800132 private static final int CMD_SEND_ENVELOPE = 25;
133 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700134 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
135 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
136 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
137 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
138 private static final int CMD_EXCHANGE_SIM_IO = 31;
139 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800140 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
141 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700142 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
143 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700144 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
145 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
147 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
148 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
149 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700150 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
151 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
152 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
153 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154
155 /** The singleton instance. */
156 private static PhoneInterfaceManager sInstance;
157
Wink Saville3ab207e2014-11-20 13:07:20 -0800158 private PhoneGlobals mApp;
159 private Phone mPhone;
160 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700161 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800162 private AppOpsManager mAppOps;
163 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800164 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800165 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166
Derek Tan97ebb422014-09-05 16:55:38 -0700167 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
168 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800169 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700170
171 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172 * A request object to use for transmitting data to an ICC.
173 */
174 private static final class IccAPDUArgument {
175 public int channel, cla, command, p1, p2, p3;
176 public String data;
177
178 public IccAPDUArgument(int channel, int cla, int command,
179 int p1, int p2, int p3, String data) {
180 this.channel = channel;
181 this.cla = cla;
182 this.command = command;
183 this.p1 = p1;
184 this.p2 = p2;
185 this.p3 = p3;
186 this.data = data;
187 }
188 }
189
190 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700191 * A request object to use for transmitting data to an ICC.
192 */
193 private static final class ManualNetworkSelectionArgument {
194 public OperatorInfo operatorInfo;
195 public boolean persistSelection;
196
197 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
198 this.operatorInfo = operatorInfo;
199 this.persistSelection = persistSelection;
200 }
201 }
202
203 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
205 * request after sending. The main thread will notify the request when it is complete.
206 */
207 private static final class MainThreadRequest {
208 /** The argument to use for the request */
209 public Object argument;
210 /** The result of the request that is run on the main thread */
211 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800212 // The subscriber id that this request applies to. Defaults to
213 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
214 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
216 public MainThreadRequest(Object argument) {
217 this.argument = argument;
218 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219
220 public MainThreadRequest(Object argument, Integer subId) {
221 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800222 if (subId != null) {
223 this.subId = subId;
224 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 }
227
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800228 private static final class IncomingThirdPartyCallArgs {
229 public final ComponentName component;
230 public final String callId;
231 public final String callerDisplayName;
232
233 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
234 String callerDisplayName) {
235 this.component = component;
236 this.callId = callId;
237 this.callerDisplayName = callerDisplayName;
238 }
239 }
240
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 /**
242 * A handler that processes messages on the main thread in the phone process. Since many
243 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
244 * inbound binder threads to the main thread in the phone process. The Binder thread
245 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
246 * on, which will be notified when the operation completes and will contain the result of the
247 * request.
248 *
249 * <p>If a MainThreadRequest object is provided in the msg.obj field,
250 * note that request.result must be set to something non-null for the calling thread to
251 * unblock.
252 */
253 private final class MainThreadHandler extends Handler {
254 @Override
255 public void handleMessage(Message msg) {
256 MainThreadRequest request;
257 Message onCompleted;
258 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800259 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700260 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261
262 switch (msg.what) {
Yorke Lee716f67e2015-06-17 15:39:16 -0700263 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700265 final Phone phone = getPhoneFromRequest(request);
266 request.result = phone != null ?
267 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
268 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 // Wake up the requesting thread
270 synchronized (request) {
271 request.notifyAll();
272 }
273 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275
276 case CMD_HANDLE_NEIGHBORING_CELL:
277 request = (MainThreadRequest) msg.obj;
278 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
279 request);
Sooraj Sasindran600a37a2016-07-18 11:57:25 -0700280 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 break;
282
283 case EVENT_NEIGHBORING_CELL_DONE:
284 ar = (AsyncResult) msg.obj;
285 request = (MainThreadRequest) ar.userObj;
286 if (ar.exception == null && ar.result != null) {
287 request.result = ar.result;
288 } else {
289 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800290 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 }
292 // Wake up the requesting thread
293 synchronized (request) {
294 request.notifyAll();
295 }
296 break;
297
298 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700299 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800300 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700301 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 break;
303
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 case CMD_END_CALL:
305 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800306 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700307 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700308 Phone phone = getPhone(end_subId);
309 if (phone == null) {
310 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
311 break;
312 }
313 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
315 // CDMA: If the user presses the Power button we treat it as
316 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700317 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
319 // GSM: End the call as per the Phone state
320 hungUp = PhoneUtils.hangup(mCM);
321 } else {
322 throw new IllegalStateException("Unexpected phone type: " + phoneType);
323 }
324 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
325 request.result = hungUp;
326 // Wake up the requesting thread
327 synchronized (request) {
328 request.notifyAll();
329 }
330 break;
331
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700332 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700333 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700334 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800335 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700336 if (uiccCard == null) {
337 loge("iccTransmitApduLogicalChannel: No UICC");
338 request.result = new IccIoResult(0x6F, 0, (byte[])null);
339 synchronized (request) {
340 request.notifyAll();
341 }
342 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700343 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
344 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700345 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700346 iccArgument.channel, iccArgument.cla, iccArgument.command,
347 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700348 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700350 break;
351
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700352 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700353 ar = (AsyncResult) msg.obj;
354 request = (MainThreadRequest) ar.userObj;
355 if (ar.exception == null && ar.result != null) {
356 request.result = ar.result;
357 } else {
358 request.result = new IccIoResult(0x6F, 0, (byte[])null);
359 if (ar.result == null) {
360 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800361 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700362 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800363 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700364 } else {
365 loge("iccTransmitApduLogicalChannel: Unknown exception");
366 }
367 }
368 synchronized (request) {
369 request.notifyAll();
370 }
371 break;
372
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700373 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
374 request = (MainThreadRequest) msg.obj;
375 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800376 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700377 if (uiccCard == null) {
378 loge("iccTransmitApduBasicChannel: No UICC");
379 request.result = new IccIoResult(0x6F, 0, (byte[])null);
380 synchronized (request) {
381 request.notifyAll();
382 }
383 } else {
384 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
385 request);
386 uiccCard.iccTransmitApduBasicChannel(
387 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
388 iccArgument.p3, iccArgument.data, onCompleted);
389 }
390 break;
391
392 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
393 ar = (AsyncResult) msg.obj;
394 request = (MainThreadRequest) ar.userObj;
395 if (ar.exception == null && ar.result != null) {
396 request.result = ar.result;
397 } else {
398 request.result = new IccIoResult(0x6F, 0, (byte[])null);
399 if (ar.result == null) {
400 loge("iccTransmitApduBasicChannel: Empty response");
401 } else if (ar.exception instanceof CommandException) {
402 loge("iccTransmitApduBasicChannel: CommandException: " +
403 ar.exception);
404 } else {
405 loge("iccTransmitApduBasicChannel: Unknown exception");
406 }
407 }
408 synchronized (request) {
409 request.notifyAll();
410 }
411 break;
412
413 case CMD_EXCHANGE_SIM_IO:
414 request = (MainThreadRequest) msg.obj;
415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 if (uiccCard == null) {
418 loge("iccExchangeSimIO: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
420 synchronized (request) {
421 request.notifyAll();
422 }
423 } else {
424 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
425 request);
426 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
427 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
428 iccArgument.data, onCompleted);
429 }
430 break;
431
432 case EVENT_EXCHANGE_SIM_IO_DONE:
433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6f, 0, (byte[])null);
439 }
440 synchronized (request) {
441 request.notifyAll();
442 }
443 break;
444
Derek Tan4d5e5c12014-02-04 11:54:58 -0800445 case CMD_SEND_ENVELOPE:
446 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800447 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 if (uiccCard == null) {
449 loge("sendEnvelopeWithStatus: No UICC");
450 request.result = new IccIoResult(0x6F, 0, (byte[])null);
451 synchronized (request) {
452 request.notifyAll();
453 }
454 } else {
455 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
456 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
457 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800458 break;
459
460 case EVENT_SEND_ENVELOPE_DONE:
461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800465 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("sendEnvelopeWithStatus: Empty response");
469 } else if (ar.exception instanceof CommandException) {
470 loge("sendEnvelopeWithStatus: CommandException: " +
471 ar.exception);
472 } else {
473 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
474 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800475 }
476 synchronized (request) {
477 request.notifyAll();
478 }
479 break;
480
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 case CMD_OPEN_CHANNEL:
482 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700484 if (uiccCard == null) {
485 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800486 request.result = new IccOpenLogicalChannelResponse(-1,
487 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700488 synchronized (request) {
489 request.notifyAll();
490 }
491 } else {
492 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
493 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
494 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 break;
496
497 case EVENT_OPEN_CHANNEL_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 int[] result = (int[]) ar.result;
503 int channelId = result[0];
504 byte[] selectResponse = null;
505 if (result.length > 1) {
506 selectResponse = new byte[result.length - 1];
507 for (int i = 1; i < result.length; ++i) {
508 selectResponse[i - 1] = (byte) result[i];
509 }
510 }
511 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700512 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700514 if (ar.result == null) {
515 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 if (ar.exception != null) {
518 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
519 }
520
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700521 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700522 if (ar.exception instanceof CommandException) {
523 CommandException.Error error =
524 ((CommandException) (ar.exception)).getCommandError();
525 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700526 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700527 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700528 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 }
530 }
531 openChannelResp = new IccOpenLogicalChannelResponse(
532 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700534 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 synchronized (request) {
536 request.notifyAll();
537 }
538 break;
539
540 case CMD_CLOSE_CHANNEL:
541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("iccCloseLogicalChannel: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 synchronized (request) {
547 request.notifyAll();
548 }
549 } else {
550 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
551 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 break;
554
555 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800556 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
557 break;
558
559 case CMD_NV_READ_ITEM:
560 request = (MainThreadRequest) msg.obj;
561 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
562 mPhone.nvReadItem((Integer) request.argument, onCompleted);
563 break;
564
565 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800571 request.result = "";
572 if (ar.result == null) {
573 loge("nvReadItem: Empty response");
574 } else if (ar.exception instanceof CommandException) {
575 loge("nvReadItem: CommandException: " +
576 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800578 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 }
580 }
581 synchronized (request) {
582 request.notifyAll();
583 }
584 break;
585
Jake Hambye994d462014-02-03 13:10:13 -0800586 case CMD_NV_WRITE_ITEM:
587 request = (MainThreadRequest) msg.obj;
588 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
589 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
590 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
591 break;
592
593 case EVENT_NV_WRITE_ITEM_DONE:
594 handleNullReturnEvent(msg, "nvWriteItem");
595 break;
596
597 case CMD_NV_WRITE_CDMA_PRL:
598 request = (MainThreadRequest) msg.obj;
599 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
600 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
601 break;
602
603 case EVENT_NV_WRITE_CDMA_PRL_DONE:
604 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
605 break;
606
607 case CMD_NV_RESET_CONFIG:
608 request = (MainThreadRequest) msg.obj;
609 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
610 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
611 break;
612
613 case EVENT_NV_RESET_CONFIG_DONE:
614 handleNullReturnEvent(msg, "nvResetConfig");
615 break;
616
Jake Hamby7c27be32014-03-03 13:25:59 -0800617 case CMD_GET_PREFERRED_NETWORK_TYPE:
618 request = (MainThreadRequest) msg.obj;
619 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700620 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800621 break;
622
623 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
624 ar = (AsyncResult) msg.obj;
625 request = (MainThreadRequest) ar.userObj;
626 if (ar.exception == null && ar.result != null) {
627 request.result = ar.result; // Integer
628 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800629 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800630 if (ar.result == null) {
631 loge("getPreferredNetworkType: Empty response");
632 } else if (ar.exception instanceof CommandException) {
633 loge("getPreferredNetworkType: CommandException: " +
634 ar.exception);
635 } else {
636 loge("getPreferredNetworkType: Unknown exception");
637 }
638 }
639 synchronized (request) {
640 request.notifyAll();
641 }
642 break;
643
644 case CMD_SET_PREFERRED_NETWORK_TYPE:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
647 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700648 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800649 break;
650
651 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
652 handleNullReturnEvent(msg, "setPreferredNetworkType");
653 break;
654
Steven Liu4bf01bc2014-07-17 11:05:29 -0500655 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
656 request = (MainThreadRequest)msg.obj;
657 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
658 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
659 break;
660
661 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
662 ar = (AsyncResult)msg.obj;
663 request = (MainThreadRequest)ar.userObj;
664 request.result = ar;
665 synchronized (request) {
666 request.notifyAll();
667 }
668 break;
669
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800670 case CMD_SET_VOICEMAIL_NUMBER:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
673 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800674 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
675 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800676 break;
677
678 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
679 handleNullReturnEvent(msg, "setVoicemailNumber");
680 break;
681
Stuart Scott54788802015-03-30 13:18:01 -0700682 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
685 request);
686 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
687 break;
688
689 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
690 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
691 break;
692
Shishir Agrawal302c8692015-06-19 13:49:39 -0700693 case CMD_PERFORM_NETWORK_SCAN:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
696 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
697 break;
698
699 case EVENT_PERFORM_NETWORK_SCAN_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 CellNetworkScanResult cellScanResult;
703 if (ar.exception == null && ar.result != null) {
704 cellScanResult = new CellNetworkScanResult(
705 CellNetworkScanResult.STATUS_SUCCESS,
706 (List<OperatorInfo>) ar.result);
707 } else {
708 if (ar.result == null) {
709 loge("getCellNetworkScanResults: Empty response");
710 }
711 if (ar.exception != null) {
712 loge("getCellNetworkScanResults: Exception: " + ar.exception);
713 }
714 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
715 if (ar.exception instanceof CommandException) {
716 CommandException.Error error =
717 ((CommandException) (ar.exception)).getCommandError();
718 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
719 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
720 } else if (error == CommandException.Error.GENERIC_FAILURE) {
721 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
722 }
723 }
724 cellScanResult = new CellNetworkScanResult(errorCode, null);
725 }
726 request.result = cellScanResult;
727 synchronized (request) {
728 request.notifyAll();
729 }
730 break;
731
732 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
733 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700734 ManualNetworkSelectionArgument selArg =
735 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700736 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
737 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700738 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
739 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
744 break;
745
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700746 case CMD_GET_MODEM_ACTIVITY_INFO:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700749 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700750 break;
751
752 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result;
757 } else {
758 if (ar.result == null) {
759 loge("queryModemActivityInfo: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("queryModemActivityInfo: CommandException: " +
762 ar.exception);
763 } else {
764 loge("queryModemActivityInfo: Unknown exception");
765 }
766 }
Amit Mahajand4766222016-01-28 15:28:28 -0800767 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
768 if (request.result == null) {
769 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
770 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700771 synchronized (request) {
772 request.notifyAll();
773 }
774 break;
775
Meng Wang1a7c35a2016-05-05 20:56:15 -0700776 case CMD_SET_ALLOWED_CARRIERS:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
779 mPhone.setAllowedCarriers(
780 (List<CarrierIdentifier>) request.argument,
781 onCompleted);
782 break;
783
784 case EVENT_SET_ALLOWED_CARRIERS_DONE:
785 ar = (AsyncResult) msg.obj;
786 request = (MainThreadRequest) ar.userObj;
787 if (ar.exception == null && ar.result != null) {
788 request.result = ar.result;
789 } else {
790 if (ar.result == null) {
791 loge("setAllowedCarriers: Empty response");
792 } else if (ar.exception instanceof CommandException) {
793 loge("setAllowedCarriers: CommandException: " +
794 ar.exception);
795 } else {
796 loge("setAllowedCarriers: Unknown exception");
797 }
798 }
799 // Result cannot be null. Return -1 on error.
800 if (request.result == null) {
801 request.result = new int[]{-1};
802 }
803 synchronized (request) {
804 request.notifyAll();
805 }
806 break;
807
808 case CMD_GET_ALLOWED_CARRIERS:
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
811 mPhone.getAllowedCarriers(onCompleted);
812 break;
813
814 case EVENT_GET_ALLOWED_CARRIERS_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null && ar.result != null) {
818 request.result = ar.result;
819 } else {
820 if (ar.result == null) {
821 loge("getAllowedCarriers: Empty response");
822 } else if (ar.exception instanceof CommandException) {
823 loge("getAllowedCarriers: CommandException: " +
824 ar.exception);
825 } else {
826 loge("getAllowedCarriers: Unknown exception");
827 }
828 }
829 // Result cannot be null. Return empty list of CarrierIdentifier.
830 if (request.result == null) {
831 request.result = new ArrayList<CarrierIdentifier>(0);
832 }
833 synchronized (request) {
834 request.notifyAll();
835 }
836 break;
837
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700838 default:
839 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
840 break;
841 }
842 }
Jake Hambye994d462014-02-03 13:10:13 -0800843
844 private void handleNullReturnEvent(Message msg, String command) {
845 AsyncResult ar = (AsyncResult) msg.obj;
846 MainThreadRequest request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null) {
848 request.result = true;
849 } else {
850 request.result = false;
851 if (ar.exception instanceof CommandException) {
852 loge(command + ": CommandException: " + ar.exception);
853 } else {
854 loge(command + ": Unknown exception");
855 }
856 }
857 synchronized (request) {
858 request.notifyAll();
859 }
860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700861 }
862
863 /**
864 * Posts the specified command to be executed on the main thread,
865 * waits for the request to complete, and returns the result.
866 * @see #sendRequestAsync
867 */
868 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800869 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700870 }
871
872 /**
873 * Posts the specified command to be executed on the main thread,
874 * waits for the request to complete, and returns the result.
875 * @see #sendRequestAsync
876 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800877 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700878 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
879 throw new RuntimeException("This method will deadlock if called from the main thread.");
880 }
881
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800882 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700883 Message msg = mMainThreadHandler.obtainMessage(command, request);
884 msg.sendToTarget();
885
886 // Wait for the request to complete
887 synchronized (request) {
888 while (request.result == null) {
889 try {
890 request.wait();
891 } catch (InterruptedException e) {
892 // Do nothing, go back and wait until the request is complete
893 }
894 }
895 }
896 return request.result;
897 }
898
899 /**
900 * Asynchronous ("fire and forget") version of sendRequest():
901 * Posts the specified command to be executed on the main thread, and
902 * returns immediately.
903 * @see #sendRequest
904 */
905 private void sendRequestAsync(int command) {
906 mMainThreadHandler.sendEmptyMessage(command);
907 }
908
909 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700910 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
911 * @see {@link #sendRequest(int,Object)}
912 */
913 private void sendRequestAsync(int command, Object argument) {
914 MainThreadRequest request = new MainThreadRequest(argument);
915 Message msg = mMainThreadHandler.obtainMessage(command, request);
916 msg.sendToTarget();
917 }
918
919 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700920 * Initialize the singleton PhoneInterfaceManager instance.
921 * This is only done once, at startup, from PhoneApp.onCreate().
922 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700923 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700924 synchronized (PhoneInterfaceManager.class) {
925 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700926 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700927 } else {
928 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
929 }
930 return sInstance;
931 }
932 }
933
934 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700935 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700936 mApp = app;
937 mPhone = phone;
938 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700939 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700940 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
941 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700942 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700943 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800944 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800945
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700946 publish();
947 }
948
949 private void publish() {
950 if (DBG) log("publish: " + this);
951
952 ServiceManager.addService("phone", this);
953 }
954
Stuart Scott584921c2015-01-15 17:10:34 -0800955 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800956 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
957 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -0800958 }
959
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800960 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
961 Phone phone = getPhoneFromRequest(request);
962 return phone == null ? null :
963 UiccController.getInstance().getUiccCard(phone.getPhoneId());
964 }
965
Wink Saville36469e72014-06-11 15:17:00 -0700966 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700967 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800968 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700970 //
971 // Implementation of the ITelephony interface.
972 //
973
974 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700975 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700976 }
977
Wink Savilleb564aae2014-10-23 10:18:09 -0700978 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700979 if (DBG) log("dial: " + number);
980 // No permission check needed here: This is just a wrapper around the
981 // ACTION_DIAL intent, which is available to any app since it puts up
982 // the UI before it does anything.
983
984 String url = createTelUrl(number);
985 if (url == null) {
986 return;
987 }
988
989 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -0700990 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700991 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
992 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
993 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
994 mApp.startActivity(intent);
995 }
996 }
997
998 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700999 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001000 }
1001
Wink Savilleb564aae2014-10-23 10:18:09 -07001002 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001003 if (DBG) log("call: " + number);
1004
1005 // This is just a wrapper around the ACTION_CALL intent, but we still
1006 // need to do a permission check since we're calling startActivity()
1007 // from the context of the phone app.
1008 enforceCallPermission();
1009
1010 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1011 != AppOpsManager.MODE_ALLOWED) {
1012 return;
1013 }
1014
1015 String url = createTelUrl(number);
1016 if (url == null) {
1017 return;
1018 }
1019
Wink Saville08874612014-08-31 19:19:58 -07001020 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001021 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001022 if (slist != null) {
1023 for (SubscriptionInfo subInfoRecord : slist) {
1024 if (subInfoRecord.getSubscriptionId() == subId) {
1025 isValid = true;
1026 break;
1027 }
Wink Saville08874612014-08-31 19:19:58 -07001028 }
1029 }
1030 if (isValid == false) {
1031 return;
1032 }
1033
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001034 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001035 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001036 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1037 mApp.startActivity(intent);
1038 }
1039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 /**
1041 * End a call based on call state
1042 * @return true is a call was ended
1043 */
1044 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001045 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001046 }
1047
1048 /**
1049 * End a call based on the call state of the subId
1050 * @return true is a call was ended
1051 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001052 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001054 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 }
1056
1057 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001058 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001059 }
1060
Wink Savilleb564aae2014-10-23 10:18:09 -07001061 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 if (DBG) log("answerRingingCall...");
1063 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1064 // but that can probably wait till the big TelephonyManager API overhaul.
1065 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1066 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001067 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 }
1069
1070 /**
1071 * Make the actual telephony calls to implement answerRingingCall().
1072 * This should only be called from the main thread of the Phone app.
1073 * @see #answerRingingCall
1074 *
1075 * TODO: it would be nice to return true if we answered the call, or
1076 * false if there wasn't actually a ringing incoming call, or some
1077 * other error occurred. (In other words, pass back the return value
1078 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1079 * But that would require calling this method via sendRequest() rather
1080 * than sendRequestAsync(), and right now we don't actually *need* that
1081 * return value, so let's just return void for now.
1082 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001083 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001084 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001086 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1087 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 if (hasActiveCall && hasHoldingCall) {
1089 // Both lines are in use!
1090 // TODO: provide a flag to let the caller specify what
1091 // policy to use if both lines are in use. (The current
1092 // behavior is hardwired to "answer incoming, end ongoing",
1093 // which is how the CALL button is specced to behave.)
1094 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1095 return;
1096 } else {
1097 // answerCall() will automatically hold the current active
1098 // call, if there is one.
1099 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1100 return;
1101 }
1102 } else {
1103 // No call was ringing.
1104 return;
1105 }
1106 }
1107
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001109 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001111 public void silenceRinger() {
1112 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 }
1114
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001115 @Override
1116 public boolean isOffhook(String callingPackage) {
1117 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001118 }
1119
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001120 @Override
1121 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1122 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1123 return false;
1124 }
1125
Sanket Padawe356d7632015-06-22 14:03:32 -07001126 final Phone phone = getPhone(subId);
1127 if (phone != null) {
1128 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1129 } else {
1130 return false;
1131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 }
1133
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001134 @Override
1135 public boolean isRinging(String callingPackage) {
1136 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001139 @Override
1140 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1141 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1142 return false;
1143 }
1144
Sanket Padawe356d7632015-06-22 14:03:32 -07001145 final Phone phone = getPhone(subId);
1146 if (phone != null) {
1147 return (phone.getState() == PhoneConstants.State.RINGING);
1148 } else {
1149 return false;
1150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001151 }
1152
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001153 @Override
1154 public boolean isIdle(String callingPackage) {
1155 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001156 }
1157
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001158 @Override
1159 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1160 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1161 return false;
1162 }
1163
Sanket Padawe356d7632015-06-22 14:03:32 -07001164 final Phone phone = getPhone(subId);
1165 if (phone != null) {
1166 return (phone.getState() == PhoneConstants.State.IDLE);
1167 } else {
1168 return false;
1169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 }
1171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001173 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001174 }
1175
Wink Savilleb564aae2014-10-23 10:18:09 -07001176 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001177 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001178 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1179 }
1180
1181 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001182 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
1184
Wink Savilleb564aae2014-10-23 10:18:09 -07001185 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001186 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001187 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1188 }
1189
1190 /** {@hide} */
1191 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001192 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001193 }
1194
Wink Savilleb564aae2014-10-23 10:18:09 -07001195 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001197 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 checkSimPin.start();
1199 return checkSimPin.unlockSim(null, pin);
1200 }
1201
Wink Saville9de0f752013-10-22 19:04:03 -07001202 /** {@hide} */
1203 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001204 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001205 }
1206
Wink Savilleb564aae2014-10-23 10:18:09 -07001207 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001209 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 checkSimPuk.start();
1211 return checkSimPuk.unlockSim(puk, pin);
1212 }
1213
1214 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001215 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 * a synchronous one.
1217 */
1218 private static class UnlockSim extends Thread {
1219
1220 private final IccCard mSimCard;
1221
1222 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001223 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1224 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225
1226 // For replies from SimCard interface
1227 private Handler mHandler;
1228
1229 // For async handler to identify request type
1230 private static final int SUPPLY_PIN_COMPLETE = 100;
1231
1232 public UnlockSim(IccCard simCard) {
1233 mSimCard = simCard;
1234 }
1235
1236 @Override
1237 public void run() {
1238 Looper.prepare();
1239 synchronized (UnlockSim.this) {
1240 mHandler = new Handler() {
1241 @Override
1242 public void handleMessage(Message msg) {
1243 AsyncResult ar = (AsyncResult) msg.obj;
1244 switch (msg.what) {
1245 case SUPPLY_PIN_COMPLETE:
1246 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1247 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001248 mRetryCount = msg.arg1;
1249 if (ar.exception != null) {
1250 if (ar.exception instanceof CommandException &&
1251 ((CommandException)(ar.exception)).getCommandError()
1252 == CommandException.Error.PASSWORD_INCORRECT) {
1253 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1254 } else {
1255 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1256 }
1257 } else {
1258 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 mDone = true;
1261 UnlockSim.this.notifyAll();
1262 }
1263 break;
1264 }
1265 }
1266 };
1267 UnlockSim.this.notifyAll();
1268 }
1269 Looper.loop();
1270 }
1271
1272 /*
1273 * Use PIN or PUK to unlock SIM card
1274 *
1275 * If PUK is null, unlock SIM card with PIN
1276 *
1277 * If PUK is not null, unlock SIM card with PUK and set PIN code
1278 */
Wink Saville9de0f752013-10-22 19:04:03 -07001279 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280
1281 while (mHandler == null) {
1282 try {
1283 wait();
1284 } catch (InterruptedException e) {
1285 Thread.currentThread().interrupt();
1286 }
1287 }
1288 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1289
1290 if (puk == null) {
1291 mSimCard.supplyPin(pin, callback);
1292 } else {
1293 mSimCard.supplyPuk(puk, pin, callback);
1294 }
1295
1296 while (!mDone) {
1297 try {
1298 Log.d(LOG_TAG, "wait for done");
1299 wait();
1300 } catch (InterruptedException e) {
1301 // Restore the interrupted status
1302 Thread.currentThread().interrupt();
1303 }
1304 }
1305 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001306 int[] resultArray = new int[2];
1307 resultArray[0] = mResult;
1308 resultArray[1] = mRetryCount;
1309 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311 }
1312
1313 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001315
1316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 // No permission check needed here: this call is harmless, and it's
1320 // needed for the ServiceState.requestStateUpdate() call (which is
1321 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001322 final Phone phone = getPhone(subId);
1323 if (phone != null) {
1324 phone.updateServiceLocation();
1325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 }
1327
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 @Override
1329 public boolean isRadioOn(String callingPackage) {
1330 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001333 @Override
1334 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1335 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1336 return false;
1337 }
1338 return isRadioOnForSubscriber(subId);
1339 }
1340
1341 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001342 final Phone phone = getPhone(subId);
1343 if (phone != null) {
1344 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1345 } else {
1346 return false;
1347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 }
1349
1350 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 }
Wink Saville36469e72014-06-11 15:17:00 -07001354
Wink Savilleb564aae2014-10-23 10:18:09 -07001355 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001357 final Phone phone = getPhone(subId);
1358 if (phone != null) {
1359 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1360 }
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
1363 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001368 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001369 final Phone phone = getPhone(subId);
1370 if (phone == null) {
1371 return false;
1372 }
1373 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001374 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 }
1377 return true;
1378 }
Wink Saville36469e72014-06-11 15:17:00 -07001379
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001380 public boolean needMobileRadioShutdown() {
1381 /*
1382 * If any of the Radios are available, it will need to be
1383 * shutdown. So return true if any Radio is available.
1384 */
1385 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1386 Phone phone = PhoneFactory.getPhone(i);
1387 if (phone != null && phone.isRadioAvailable()) return true;
1388 }
1389 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1390 return false;
1391 }
1392
1393 public void shutdownMobileRadios() {
1394 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1395 logv("Shutting down Phone " + i);
1396 shutdownRadioUsingPhoneId(i);
1397 }
1398 }
1399
1400 private void shutdownRadioUsingPhoneId(int phoneId) {
1401 enforceModifyPermission();
1402 Phone phone = PhoneFactory.getPhone(phoneId);
1403 if (phone != null && phone.isRadioAvailable()) {
1404 phone.shutdownRadio();
1405 }
1406 }
1407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 public boolean setRadioPower(boolean turnOn) {
Wei Liu9ae2a062016-08-08 11:09:34 -07001409 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1410 if (defaultPhone != null) {
1411 defaultPhone.setRadioPower(turnOn);
1412 return true;
1413 } else {
1414 loge("There's no default phone.");
1415 return false;
1416 }
Wink Saville36469e72014-06-11 15:17:00 -07001417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001421 final Phone phone = getPhone(subId);
1422 if (phone != null) {
1423 phone.setRadioPower(turnOn);
1424 return true;
1425 } else {
1426 return false;
1427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 }
1429
Wink Saville36469e72014-06-11 15:17:00 -07001430 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001431 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 public boolean enableDataConnectivity() {
1433 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001434 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001435 final Phone phone = getPhone(subId);
1436 if (phone != null) {
1437 phone.setDataEnabled(true);
1438 return true;
1439 } else {
1440 return false;
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 }
1443
Wink Saville36469e72014-06-11 15:17:00 -07001444 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001445 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 public boolean disableDataConnectivity() {
1447 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001448 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001449 final Phone phone = getPhone(subId);
1450 if (phone != null) {
1451 phone.setDataEnabled(false);
1452 return true;
1453 } else {
1454 return false;
1455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457
Wink Saville36469e72014-06-11 15:17:00 -07001458 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001459 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001461 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 return phone.isDataConnectivityPossible();
1465 } else {
1466 return false;
1467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 }
1469
1470 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001476 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1477 return false;
1478 }
Wink Saville36469e72014-06-11 15:17:00 -07001479 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001483 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
Shishir Agrawala9f32182016-04-12 12:00:16 -07001486 public int getCallStateForSlot(int slotId) {
1487 Phone phone = PhoneFactory.getPhone(slotId);
1488 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1489 DefaultPhoneNotifier.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 }
1491
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001494 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001495 if (phone != null) {
1496 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1497 } else {
1498 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
Sanket Padawe356d7632015-06-22 14:03:32 -07001502 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001503 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001504 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001505 if (phone != null) {
1506 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1507 } else {
1508 return TelephonyManager.DATA_ACTIVITY_NONE;
1509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 }
1511
1512 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001513 public Bundle getCellLocation(String callingPackage) {
1514 enforceFineOrCoarseLocationPermission("getCellLocation");
1515
1516 // OP_COARSE_LOCATION controls both fine and coarse location.
1517 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1518 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001519 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001520 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
1522
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001523 if (checkIfCallerIsSelfOrForegroundUser() ||
1524 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 if (DBG_LOC) log("getCellLocation: is active user");
1526 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001527 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 if (phone == null) {
1529 return null;
1530 }
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001531
1532 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1533 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 return data;
1535 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001536 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 return null;
1538 }
1539 }
1540
Svetoslav64fad262015-04-14 14:35:21 -07001541 private void enforceFineOrCoarseLocationPermission(String message) {
1542 try {
1543 mApp.enforceCallingOrSelfPermission(
1544 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1545 } catch (SecurityException e) {
1546 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1547 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1548 // is the weaker precondition
1549 mApp.enforceCallingOrSelfPermission(
1550 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1551 }
1552 }
1553
1554
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 @Override
1556 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001557 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001558 }
1559
Sanket Padawe356d7632015-06-22 14:03:32 -07001560 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 mApp.enforceCallingOrSelfPermission(
1563 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 final Phone phone = getPhone(subId);
1565 if (phone != null) {
1566 phone.enableLocationUpdates();
1567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
1569
1570 @Override
1571 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001572 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001573 }
1574
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001576 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 mApp.enforceCallingOrSelfPermission(
1578 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 final Phone phone = getPhone(subId);
1580 if (phone != null) {
1581 phone.disableLocationUpdates();
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 @Override
1586 @SuppressWarnings("unchecked")
1587 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001588 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1589
1590 // OP_COARSE_LOCATION controls both fine and coarse location.
1591 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1592 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1593 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
1596 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1597 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1598 return null;
1599 }
Svetoslav64fad262015-04-14 14:35:21 -07001600
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001601 if (checkIfCallerIsSelfOrForegroundUser() ||
1602 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1604
1605 ArrayList<NeighboringCellInfo> cells = null;
1606
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001607 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 try {
1609 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001610 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001611 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001613 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615 return cells;
1616 } else {
1617 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1618 return null;
1619 }
1620 }
1621
1622
1623 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001624 public List<CellInfo> getAllCellInfo(String callingPackage) {
1625 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1626
1627 // OP_COARSE_LOCATION controls both fine and coarse location.
1628 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1629 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1630 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001633 if (checkIfCallerIsSelfOrForegroundUser() ||
1634 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001636 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001637 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1638 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001639 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1640 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001641 }
1642 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 } else {
1644 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1645 return null;
1646 }
1647 }
1648
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001649 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 public void setCellInfoListRate(int rateInMillis) {
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07001651 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1652 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
Shishir Agrawala9f32182016-04-12 12:00:16 -07001655 @Override
1656 public String getImeiForSlot(int slotId, String callingPackage) {
1657 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1658 return null;
1659 }
1660 Phone phone = PhoneFactory.getPhone(slotId);
1661 return phone == null ? null : phone.getImei();
1662 }
1663
1664 @Override
1665 public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) {
1666 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1667 return null;
1668 }
1669 Phone phone = PhoneFactory.getPhone(slotId);
1670 return phone == null ? null : phone.getDeviceSvn();
1671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 //
1674 // Internal helper methods.
1675 //
1676
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001677 /**
1678 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1679 */
1680 private boolean checkCallerInteractAcrossUsersFull() {
1681 return mPhone.getContext().checkCallingOrSelfPermission(
1682 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1683 == PackageManager.PERMISSION_GRANTED;
1684 }
1685
Jake Hambye994d462014-02-03 13:10:13 -08001686 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 boolean ok;
1688
1689 boolean self = Binder.getCallingUid() == Process.myUid();
1690 if (!self) {
1691 // Get the caller's user id then clear the calling identity
1692 // which will be restored in the finally clause.
1693 int callingUser = UserHandle.getCallingUserId();
1694 long ident = Binder.clearCallingIdentity();
1695
1696 try {
1697 // With calling identity cleared the current user is the foreground user.
1698 int foregroundUser = ActivityManager.getCurrentUser();
1699 ok = (foregroundUser == callingUser);
1700 if (DBG_LOC) {
1701 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1702 + " callingUser=" + callingUser + " ok=" + ok);
1703 }
1704 } catch (Exception ex) {
1705 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1706 ok = false;
1707 } finally {
1708 Binder.restoreCallingIdentity(ident);
1709 }
1710 } else {
1711 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1712 ok = true;
1713 }
1714 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1715 return ok;
1716 }
1717
1718 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1720 *
1721 * @throws SecurityException if the caller does not have the required permission
1722 */
1723 private void enforceModifyPermission() {
1724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1725 }
1726
1727 /**
Junda Liua2e36012014-07-09 18:30:01 -07001728 * Make sure either system app or the caller has carrier privilege.
1729 *
1730 * @throws SecurityException if the caller does not have the required permission/privilege
1731 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001732 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001733 int permission = mApp.checkCallingOrSelfPermission(
1734 android.Manifest.permission.MODIFY_PHONE_STATE);
1735 if (permission == PackageManager.PERMISSION_GRANTED) {
1736 return;
1737 }
1738
1739 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001740 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001741 }
1742
1743 /**
1744 * Make sure the caller has carrier privilege.
1745 *
1746 * @throws SecurityException if the caller does not have the required permission
1747 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001748 private void enforceCarrierPrivilege(int subId) {
1749 if (getCarrierPrivilegeStatus(subId) !=
1750 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001751 loge("No Carrier Privilege.");
1752 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001753 }
1754 }
1755
1756 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 * Make sure the caller has the CALL_PHONE permission.
1758 *
1759 * @throws SecurityException if the caller does not have the required permission
1760 */
1761 private void enforceCallPermission() {
1762 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1763 }
1764
Stuart Scott8eef64f2015-04-08 15:13:54 -07001765 private void enforceConnectivityInternalPermission() {
1766 mApp.enforceCallingOrSelfPermission(
1767 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1768 "ConnectivityService");
1769 }
1770
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 private String createTelUrl(String number) {
1772 if (TextUtils.isEmpty(number)) {
1773 return null;
1774 }
1775
Jake Hambye994d462014-02-03 13:10:13 -08001776 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Ihab Awadf9e92732013-12-05 18:02:52 -08001779 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1781 }
1782
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001783 private static void logv(String msg) {
1784 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1785 }
1786
Ihab Awadf9e92732013-12-05 18:02:52 -08001787 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1789 }
1790
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001791 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001793 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001794 }
1795
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 @Override
Shishir Agrawala9f32182016-04-12 12:00:16 -07001797 public int getActivePhoneTypeForSlot(int slotId) {
1798 final Phone phone = PhoneFactory.getPhone(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 if (phone == null) {
1800 return PhoneConstants.PHONE_TYPE_NONE;
1801 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001802 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
1806 /**
1807 * Returns the CDMA ERI icon index to display
1808 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001809 @Override
1810 public int getCdmaEriIconIndex(String callingPackage) {
1811 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001812 }
1813
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001815 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1816 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1817 return -1;
1818 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 final Phone phone = getPhone(subId);
1820 if (phone != null) {
1821 return phone.getCdmaEriIconIndex();
1822 } else {
1823 return -1;
1824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
1827 /**
1828 * Returns the CDMA ERI icon mode,
1829 * 0 - ON
1830 * 1 - FLASHING
1831 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001832 @Override
1833 public int getCdmaEriIconMode(String callingPackage) {
1834 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001835 }
1836
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001838 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1839 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1840 return -1;
1841 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001842 final Phone phone = getPhone(subId);
1843 if (phone != null) {
1844 return phone.getCdmaEriIconMode();
1845 } else {
1846 return -1;
1847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
1850 /**
1851 * Returns the CDMA ERI text,
1852 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001853 @Override
1854 public String getCdmaEriText(String callingPackage) {
1855 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001856 }
1857
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001859 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1860 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1861 return null;
1862 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001863 final Phone phone = getPhone(subId);
1864 if (phone != null) {
1865 return phone.getCdmaEriText();
1866 } else {
1867 return null;
1868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
1871 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001872 * Returns the CDMA MDN.
1873 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001875 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001876 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 final Phone phone = getPhone(subId);
1878 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1879 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001880 } else {
1881 return null;
1882 }
1883 }
1884
1885 /**
1886 * Returns the CDMA MIN.
1887 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001889 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001890 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 final Phone phone = getPhone(subId);
1892 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1893 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001894 } else {
1895 return null;
1896 }
1897 }
1898
1899 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 * Returns true if CDMA provisioning needs to run.
1901 */
1902 public boolean needsOtaServiceProvisioning() {
1903 return mPhone.needsOtaServiceProvisioning();
1904 }
1905
1906 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001907 * Sets the voice mail number of a given subId.
1908 */
1909 @Override
1910 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001911 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001912 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1913 new Pair<String, String>(alphaTag, number), new Integer(subId));
1914 return success;
1915 }
1916
Ta-wei Yen87c49842016-05-13 21:19:52 -07001917 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07001918 public void setVisualVoicemailEnabled(String callingPackage,
1919 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
1920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1921 if (!TextUtils.equals(callingPackage,
1922 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
1923 enforceModifyPermissionOrCarrierPrivilege(
1924 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
1925 }
1926 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
1927 }
1928
1929 @Override
1930 public boolean isVisualVoicemailEnabled(String callingPackage,
1931 PhoneAccountHandle phoneAccountHandle) {
1932 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
1933 return false;
1934 }
1935 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
1936 }
1937
1938 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001939 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1940 VisualVoicemailSmsFilterSettings settings) {
1941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001942 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001943 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
1944 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001945 }
1946
1947 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001948 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
1949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001950 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001951 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001952 }
1953
1954 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001955 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
1956 String callingPackage, int subId) {
1957 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001958 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001959 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001960 }
1961
1962 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001963 public VisualVoicemailSmsFilterSettings getSystemVisualVoicemailSmsFilterSettings(
1964 String packageName, int subId) {
1965 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07001966 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001967 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), packageName, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001968 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001969 /**
fionaxuef039d42016-11-14 13:36:14 -08001970 * Sets the voice activation state of a given subId.
1971 */
1972 @Override
1973 public void setVoiceActivationState(int subId, int activationState) {
1974 enforceModifyPermissionOrCarrierPrivilege(subId);
1975 final Phone phone = getPhone(subId);
1976 if (phone != null) {
1977 phone.setVoiceActivationState(activationState);
1978 } else {
1979 loge("setVoiceActivationState fails with invalid subId: " + subId);
1980 }
1981 }
1982
1983 /**
1984 * Sets the data activation state of a given subId.
1985 */
1986 @Override
1987 public void setDataActivationState(int subId, int activationState) {
1988 enforceModifyPermissionOrCarrierPrivilege(subId);
1989 final Phone phone = getPhone(subId);
1990 if (phone != null) {
1991 phone.setDataActivationState(activationState);
1992 } else {
1993 loge("setVoiceActivationState fails with invalid subId: " + subId);
1994 }
1995 }
1996
1997 /**
1998 * Returns the voice activation state of a given subId.
1999 */
2000 @Override
2001 public int getVoiceActivationState(int subId, String callingPackage) {
2002 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2003 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2004 }
2005 final Phone phone = getPhone(subId);
2006 if (phone != null) {
2007 return phone.getVoiceActivationState();
2008 } else {
2009 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2010 }
2011 }
2012
2013 /**
2014 * Returns the data activation state of a given subId.
2015 */
2016 @Override
2017 public int getDataActivationState(int subId, String callingPackage) {
2018 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2019 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2020 }
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 return phone.getDataActivationState();
2024 } else {
2025 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2026 }
2027 }
2028
2029 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 * Returns the unread count of voicemails
2031 */
2032 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002033 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
2036 /**
2037 * Returns the unread count of voicemails for a subId
2038 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002039 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002040 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002041 final Phone phone = getPhone(subId);
2042 if (phone != null) {
2043 return phone.getVoiceMessageCount();
2044 } else {
2045 return 0;
2046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048
2049 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002050 * Returns the data network type.
2051 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 *
2053 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2054 */
2055 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002056 public int getNetworkType() {
2057 final Phone phone = getPhone(getDefaultSubscription());
2058 if (phone != null) {
2059 return phone.getServiceState().getDataNetworkType();
2060 } else {
2061 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2062 }
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
2065 /**
2066 * Returns the network type for a subId
2067 */
2068 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002069 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2070 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2071 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2072 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002073
Sanket Padawe356d7632015-06-22 14:03:32 -07002074 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002075 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 return phone.getServiceState().getDataNetworkType();
2077 } else {
2078 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 }
2081
2082 /**
2083 * Returns the data network type
2084 */
2085 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002086 public int getDataNetworkType(String callingPackage) {
2087 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002088 }
2089
2090 /**
2091 * Returns the data network type for a subId
2092 */
2093 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002094 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2095 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2097 }
2098
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 return phone.getServiceState().getDataNetworkType();
2102 } else {
2103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106
2107 /**
Wink Saville36469e72014-06-11 15:17:00 -07002108 * Returns the Voice network type for a subId
2109 */
2110 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002111 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2112 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2114 }
2115
Sanket Padawe356d7632015-06-22 14:03:32 -07002116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 return phone.getServiceState().getVoiceNetworkType();
2119 } else {
2120 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 }
2123
2124 /**
2125 * @return true if a ICC card is present
2126 */
2127 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002128 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002129 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002130 }
2131
2132 /**
2133 * @return true if a ICC card is present for a slotId
2134 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002136 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002137 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002138 final Phone phone = getPhone(subId[0]);
2139 if (subId != null && phone != null) {
2140 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002141 } else {
2142 return false;
2143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
2146 /**
2147 * Return if the current radio is LTE on CDMA. This
2148 * is a tri-state return value as for a period of time
2149 * the mode may be unknown.
2150 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002151 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002153 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002155 @Override
2156 public int getLteOnCdmaMode(String callingPackage) {
2157 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002158 }
2159
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002161 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2162 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2163 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2164 }
2165
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 final Phone phone = getPhone(subId);
2167 if (phone == null) {
2168 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2169 } else {
2170 return phone.getLteOnCdmaMode();
2171 }
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
2174 public void setPhone(Phone phone) {
2175 mPhone = phone;
2176 }
2177
2178 /**
2179 * {@hide}
2180 * Returns Default subId, 0 in the case of single standby.
2181 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002182 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002183 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002184 }
2185
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 private int getSlotForDefaultSubscription() {
2187 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2188 }
2189
Wink Savilleb564aae2014-10-23 10:18:09 -07002190 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002191 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002193
2194 /**
2195 * @see android.telephony.TelephonyManager.WifiCallingChoices
2196 */
2197 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002198 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2199 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002200 }
2201
2202 /**
2203 * @see android.telephony.TelephonyManager.WifiCallingChoices
2204 */
2205 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002206 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2207 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2208 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002209 }
2210
Sailesh Nepald1e68152013-12-12 19:08:02 -08002211 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002212 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002213 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002214 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002215
Shishir Agrawal566b7612013-10-28 14:41:00 -07002216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002217 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
2218 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002219
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002220 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002221 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002222 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002223 if (DBG) log("iccOpenLogicalChannel: " + response);
2224 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002225 }
2226
2227 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002228 public boolean iccCloseLogicalChannel(int subId, int channel) {
2229 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002230
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002231 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002232 if (channel < 0) {
2233 return false;
2234 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002235 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002236 if (DBG) log("iccCloseLogicalChannel: " + success);
2237 return success;
2238 }
2239
2240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002241 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002242 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002243 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002244
2245 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002246 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2247 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002248 " data=" + data);
2249 }
2250
2251 if (channel < 0) {
2252 return "";
2253 }
2254
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002255 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002256 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002257 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2258
Shishir Agrawal566b7612013-10-28 14:41:00 -07002259 // Append the returned status code to the end of the response payload.
2260 String s = Integer.toHexString(
2261 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002262 if (response.payload != null) {
2263 s = IccUtils.bytesToHexString(response.payload) + s;
2264 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002265 return s;
2266 }
Jake Hambye994d462014-02-03 13:10:13 -08002267
Evan Charltonc66da362014-05-16 14:06:40 -07002268 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002269 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002270 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002271 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002272
2273 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002274 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2275 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002276 }
2277
2278 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002279 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002280 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2281
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002282 // Append the returned status code to the end of the response payload.
2283 String s = Integer.toHexString(
2284 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002285 if (response.payload != null) {
2286 s = IccUtils.bytesToHexString(response.payload) + s;
2287 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002288 return s;
2289 }
2290
2291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002292 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002293 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002294 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002295
2296 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002297 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002298 p1 + " " + p2 + " " + p3 + ":" + filePath);
2299 }
2300
2301 IccIoResult response =
2302 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002303 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2304 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002305
2306 if (DBG) {
2307 log("Exchange SIM_IO [R]" + response);
2308 }
2309
2310 byte[] result = null;
2311 int length = 2;
2312 if (response.payload != null) {
2313 length = 2 + response.payload.length;
2314 result = new byte[length];
2315 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2316 } else {
2317 result = new byte[length];
2318 }
2319
2320 result[length - 1] = (byte) response.sw2;
2321 result[length - 2] = (byte) response.sw1;
2322 return result;
2323 }
2324
2325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002326 public String sendEnvelopeWithStatus(int subId, String content) {
2327 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002328
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002329 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002330 if (response.payload == null) {
2331 return "";
2332 }
2333
2334 // Append the returned status code to the end of the response payload.
2335 String s = Integer.toHexString(
2336 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2337 s = IccUtils.bytesToHexString(response.payload) + s;
2338 return s;
2339 }
2340
Jake Hambye994d462014-02-03 13:10:13 -08002341 /**
2342 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2343 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2344 *
2345 * @param itemID the ID of the item to read
2346 * @return the NV item as a String, or null on error.
2347 */
2348 @Override
2349 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002350 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002351 if (DBG) log("nvReadItem: item " + itemID);
2352 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2353 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2354 return value;
2355 }
2356
2357 /**
2358 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2359 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2360 *
2361 * @param itemID the ID of the item to read
2362 * @param itemValue the value to write, as a String
2363 * @return true on success; false on any failure
2364 */
2365 @Override
2366 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002367 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002368 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2369 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2370 new Pair<Integer, String>(itemID, itemValue));
2371 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2372 return success;
2373 }
2374
2375 /**
2376 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2377 * Used for device configuration by some CDMA operators.
2378 *
2379 * @param preferredRoamingList byte array containing the new PRL
2380 * @return true on success; false on any failure
2381 */
2382 @Override
2383 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002384 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002385 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2386 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2387 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2388 return success;
2389 }
2390
2391 /**
2392 * Perform the specified type of NV config reset.
2393 * Used for device configuration by some CDMA operators.
2394 *
2395 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2396 * @return true on success; false on any failure
2397 */
2398 @Override
2399 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002401 if (DBG) log("nvResetConfig: type " + resetType);
2402 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2403 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2404 return success;
2405 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002406
2407 /**
Wink Saville36469e72014-06-11 15:17:00 -07002408 * {@hide}
2409 * Returns Default sim, 0 in the case of single standby.
2410 */
2411 public int getDefaultSim() {
2412 //TODO Need to get it from Telephony Devcontroller
2413 return 0;
2414 }
2415
Svet Ganovb320e182015-04-16 12:30:10 -07002416 public String[] getPcscfAddress(String apnType, String callingPackage) {
2417 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2418 return new String[0];
2419 }
2420
2421
ram87fca6f2014-07-18 18:58:44 +05302422 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002423 }
2424
Brad Ebinger76681002017-01-23 13:50:20 -08002425 /**
2426 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2427 * feature or {@link null} if the service is not available. If an ImsServiceController is
2428 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2429 * feature updates.
2430 */
2431 public IImsServiceController getImsServiceControllerAndListen(int slotId, int feature,
2432 IImsServiceFeatureListener callback) {
2433 enforceModifyPermission();
2434 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotId, feature,
2435 callback);
2436 }
2437
Wink Saville36469e72014-06-11 15:17:00 -07002438 public void setImsRegistrationState(boolean registered) {
2439 enforceModifyPermission();
2440 mPhone.setImsRegistrationState(registered);
2441 }
2442
2443 /**
Stuart Scott54788802015-03-30 13:18:01 -07002444 * Set the network selection mode to automatic.
2445 *
2446 */
2447 @Override
2448 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002449 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002450 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2451 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2452 }
2453
2454 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002455 * Set the network selection mode to manual with the selected carrier.
2456 */
2457 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002458 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2459 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002461 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002462 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2463 persistSelection);
2464 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002465 }
2466
2467 /**
2468 * Scans for available networks.
2469 */
2470 @Override
2471 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002473 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2474 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2475 CMD_PERFORM_NETWORK_SCAN, null, subId);
2476 return result;
2477 }
2478
2479 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002480 * Get the calculated preferred network type.
2481 * Used for debugging incorrect network type.
2482 *
2483 * @return the preferred network type, defined in RILConstants.java.
2484 */
2485 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002486 public int getCalculatedPreferredNetworkType(String callingPackage) {
2487 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2488 return RILConstants.PREFERRED_NETWORK_MODE;
2489 }
2490
Amit Mahajan43330e02014-11-18 11:54:45 -08002491 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002492 }
2493
2494 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002495 * Get the preferred network type.
2496 * Used for device configuration by some CDMA operators.
2497 *
2498 * @return the preferred network type, defined in RILConstants.java.
2499 */
2500 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002501 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002503 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002504 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002505 int networkType = (result != null ? result[0] : -1);
2506 if (DBG) log("getPreferredNetworkType: " + networkType);
2507 return networkType;
2508 }
2509
2510 /**
2511 * Set the preferred network type.
2512 * Used for device configuration by some CDMA operators.
2513 *
2514 * @param networkType the preferred network type, defined in RILConstants.java.
2515 * @return true on success; false on any failure.
2516 */
2517 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002518 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002520 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2521 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002522 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002523 if (success) {
2524 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002525 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002526 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002527 return success;
2528 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002529
2530 /**
Junda Liu475951f2014-11-07 16:45:03 -08002531 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2532 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2533 * tethering.
2534 *
2535 * @return 0: Not required. 1: required. 2: Not set.
2536 * @hide
2537 */
2538 @Override
2539 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002541 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2542 Settings.Global.TETHER_DUN_REQUIRED, 2);
2543 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2544 // config_tether_apndata.
2545 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2546 dunRequired = 1;
2547 }
2548 return dunRequired;
2549 }
2550
2551 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002552 * Set mobile data enabled
2553 * Used by the user through settings etc to turn on/off mobile data
2554 *
2555 * @param enable {@code true} turn turn data on, else {@code false}
2556 */
2557 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002558 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002559 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002560 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002561 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002562 Phone phone = PhoneFactory.getPhone(phoneId);
2563 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002564 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002565 phone.setDataEnabled(enable);
2566 } else {
2567 loge("setDataEnabled: no phone for subId=" + subId);
2568 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002569 }
2570
2571 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002572 * Get whether mobile data is enabled.
2573 *
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002574 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002575 *
2576 * @return {@code true} if data is enabled else {@code false}
2577 */
2578 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002579 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002580 try {
2581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2582 null);
2583 } catch (Exception e) {
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002584 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002585 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002586 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002587 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002588 Phone phone = PhoneFactory.getPhone(phoneId);
2589 if (phone != null) {
2590 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002591 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002592 return retVal;
2593 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002594 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002595 return false;
2596 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002597 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002598
2599 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002600 public int getCarrierPrivilegeStatus(int subId) {
2601 final Phone phone = getPhone(subId);
2602 if (phone == null) {
2603 loge("getCarrierPrivilegeStatus: Invalid subId");
2604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2605 }
2606 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002607 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002608 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2610 }
2611 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002612 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002613 }
Junda Liu29340342014-07-10 15:23:27 -07002614
2615 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002616 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002617 if (TextUtils.isEmpty(pkgName))
2618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002619 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002620 if (card == null) {
2621 loge("checkCarrierPrivilegesForPackage: No UICC");
2622 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2623 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002624 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2625 }
2626
2627 @Override
2628 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002629 if (TextUtils.isEmpty(pkgName))
2630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002631 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2633 UiccCard card = UiccController.getInstance().getUiccCard(i);
2634 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002635 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002636 continue;
2637 }
2638
2639 result = card.getCarrierPrivilegeStatus(
2640 mPhone.getContext().getPackageManager(), pkgName);
2641 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2642 break;
2643 }
2644 }
2645
2646 return result;
Junda Liu29340342014-07-10 15:23:27 -07002647 }
Derek Tan89e89d42014-07-08 17:00:10 -07002648
2649 @Override
Junda Liue64de782015-04-16 17:19:16 -07002650 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2651 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2652 loge("phoneId " + phoneId + " is not valid.");
2653 return null;
2654 }
2655 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002656 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002657 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002658 return null ;
2659 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002660 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002661 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002662 }
2663
Amith Yamasani6e118872016-02-19 12:53:51 -08002664 @Override
2665 public List<String> getPackagesWithCarrierPrivileges() {
2666 PackageManager pm = mPhone.getContext().getPackageManager();
2667 List<String> privilegedPackages = new ArrayList<>();
2668 List<PackageInfo> packages = null;
2669 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2670 UiccCard card = UiccController.getInstance().getUiccCard(i);
2671 if (card == null) {
2672 // No UICC in that slot.
2673 continue;
2674 }
2675 if (card.hasCarrierPrivilegeRules()) {
2676 if (packages == null) {
2677 // Only check packages in user 0 for now
2678 packages = pm.getInstalledPackagesAsUser(
2679 PackageManager.MATCH_DISABLED_COMPONENTS
2680 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2681 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2682 }
2683 for (int p = packages.size() - 1; p >= 0; p--) {
2684 PackageInfo pkgInfo = packages.get(p);
2685 if (pkgInfo != null && pkgInfo.packageName != null
2686 && card.getCarrierPrivilegeStatus(pkgInfo)
2687 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2688 privilegedPackages.add(pkgInfo.packageName);
2689 }
2690 }
2691 }
2692 }
2693 return privilegedPackages;
2694 }
2695
Wink Savilleb564aae2014-10-23 10:18:09 -07002696 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 final Phone phone = getPhone(subId);
2698 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002699 if (card == null) {
2700 loge("getIccId: No UICC");
2701 return null;
2702 }
2703 String iccId = card.getIccId();
2704 if (TextUtils.isEmpty(iccId)) {
2705 loge("getIccId: ICC ID is null or empty.");
2706 return null;
2707 }
2708 return iccId;
2709 }
2710
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002711 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002712 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2713 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002714 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002715
Jeff Sharkey85190e62014-12-05 09:40:12 -08002716 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 final Phone phone = getPhone(subId);
2718 if (phone == null) {
2719 return false;
2720 }
2721 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002722
2723 if (DBG_MERGE) {
2724 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2725 + subscriberId + " to " + number);
2726 }
2727
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002728 if (TextUtils.isEmpty(iccId)) {
2729 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002730 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002731
Jeff Sharkey85190e62014-12-05 09:40:12 -08002732 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2733
2734 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002735 if (alphaTag == null) {
2736 editor.remove(alphaTagPrefKey);
2737 } else {
2738 editor.putString(alphaTagPrefKey, alphaTag);
2739 }
2740
Jeff Sharkey85190e62014-12-05 09:40:12 -08002741 // Record both the line number and IMSI for this ICCID, since we need to
2742 // track all merged IMSIs based on line number
2743 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2744 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002745 if (number == null) {
2746 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002747 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002748 } else {
2749 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002750 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002751 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002752
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002753 editor.commit();
2754 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002755 }
2756
2757 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002758 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002759 // This is open to apps with WRITE_SMS.
2760 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002761 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002762 return null;
2763 }
Derek Tan97ebb422014-09-05 16:55:38 -07002764
2765 String iccId = getIccId(subId);
2766 if (iccId != null) {
2767 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002768 if (DBG_MERGE) {
2769 log("getLine1NumberForDisplay returning " +
2770 mTelephonySharedPreferences.getString(numberPrefKey, null));
2771 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002772 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002773 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002774 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002775 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002776 }
2777
2778 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002779 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2780 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2781 return null;
2782 }
Derek Tan97ebb422014-09-05 16:55:38 -07002783
2784 String iccId = getIccId(subId);
2785 if (iccId != null) {
2786 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002787 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002788 }
Derek Tan97ebb422014-09-05 16:55:38 -07002789 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002790 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002791
2792 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002793 public String[] getMergedSubscriberIds(String callingPackage) {
2794 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2795 return null;
2796 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002797 final Context context = mPhone.getContext();
2798 final TelephonyManager tele = TelephonyManager.from(context);
2799 final SubscriptionManager sub = SubscriptionManager.from(context);
2800
2801 // Figure out what subscribers are currently active
2802 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002803 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2804 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 final int[] subIds = sub.getActiveSubscriptionIdList();
2808 for (int subId : subIds) {
2809 activeSubscriberIds.add(tele.getSubscriberId(subId));
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002813 }
2814
2815 // First pass, find a number override for an active subscriber
2816 String mergeNumber = null;
2817 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2818 for (String key : prefs.keySet()) {
2819 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2820 final String subscriberId = (String) prefs.get(key);
2821 if (activeSubscriberIds.contains(subscriberId)) {
2822 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2823 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2824 mergeNumber = (String) prefs.get(numberKey);
2825 if (DBG_MERGE) {
2826 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2827 + " for active subscriber " + subscriberId);
2828 }
2829 if (!TextUtils.isEmpty(mergeNumber)) {
2830 break;
2831 }
2832 }
2833 }
2834 }
2835
2836 // Shortcut when no active merged subscribers
2837 if (TextUtils.isEmpty(mergeNumber)) {
2838 return null;
2839 }
2840
2841 // Second pass, find all subscribers under that line override
2842 final ArraySet<String> result = new ArraySet<>();
2843 for (String key : prefs.keySet()) {
2844 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2845 final String number = (String) prefs.get(key);
2846 if (mergeNumber.equals(number)) {
2847 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2848 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2849 final String subscriberId = (String) prefs.get(subscriberKey);
2850 if (!TextUtils.isEmpty(subscriberId)) {
2851 result.add(subscriberId);
2852 }
2853 }
2854 }
2855 }
2856
2857 final String[] resultArray = result.toArray(new String[result.size()]);
2858 Arrays.sort(resultArray);
2859 if (DBG_MERGE) {
2860 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2861 }
2862 return resultArray;
2863 }
2864
2865 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002866 public boolean setOperatorBrandOverride(int subId, String brand) {
2867 enforceCarrierPrivilege(subId);
2868 final Phone phone = getPhone(subId);
2869 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002870 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002871
2872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002873 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002874 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2875 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002876 enforceCarrierPrivilege(subId);
2877 final Phone phone = getPhone(subId);
2878 if (phone == null) {
2879 return false;
2880 }
2881 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002882 cdmaNonRoamingList);
2883 }
2884
2885 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002886 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2887 enforceModifyPermission();
2888
2889 int returnValue = 0;
2890 try {
2891 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2892 if(result.exception == null) {
2893 if (result.result != null) {
2894 byte[] responseData = (byte[])(result.result);
2895 if(responseData.length > oemResp.length) {
2896 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2897 responseData.length + "bytes. Buffer Size is " +
2898 oemResp.length + "bytes.");
2899 }
2900 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2901 returnValue = responseData.length;
2902 }
2903 } else {
2904 CommandException ex = (CommandException) result.exception;
2905 returnValue = ex.getCommandError().ordinal();
2906 if(returnValue > 0) returnValue *= -1;
2907 }
2908 } catch (RuntimeException e) {
2909 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2910 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2911 if(returnValue > 0) returnValue *= -1;
2912 }
2913
2914 return returnValue;
2915 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002916
2917 @Override
2918 public void setRadioCapability(RadioAccessFamily[] rafs) {
2919 try {
2920 ProxyController.getInstance().setRadioCapability(rafs);
2921 } catch (RuntimeException e) {
2922 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2923 }
2924 }
2925
2926 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002927 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2928 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2929 return RadioAccessFamily.RAF_UNKNOWN;
2930 }
2931
Wink Saville5d475dd2014-10-17 15:00:58 -07002932 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2933 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002934
2935 @Override
2936 public void enableVideoCalling(boolean enable) {
2937 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002938 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002939 }
2940
2941 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002942 public boolean isVideoCallingEnabled(String callingPackage) {
2943 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2944 return false;
2945 }
2946
Andrew Lee77527ac2014-10-21 16:57:39 -07002947 // Check the user preference and the system-level IMS setting. Even if the user has
2948 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2949 // In the long run, we may instead need to check if there exists a connection service
2950 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002951 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2952 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002953 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002954 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002955
Andrew Leea1239f22015-03-02 17:44:07 -08002956 @Override
2957 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002958 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002959 }
2960
2961 @Override
2962 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002963 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002964 }
2965
Andrew Lee9431b832015-03-09 18:46:45 -07002966 @Override
2967 public boolean isTtyModeSupported() {
2968 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2969 TelephonyManager telephonyManager =
2970 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08002971 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07002972 }
2973
2974 @Override
2975 public boolean isHearingAidCompatibilitySupported() {
2976 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2977 }
2978
Sanket Padawe7310cc72015-01-14 09:53:20 -08002979 /**
2980 * Returns the unique device ID of phone, for example, the IMEI for
2981 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2982 *
2983 * <p>Requires Permission:
2984 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2985 */
2986 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002987 public String getDeviceId(String callingPackage) {
2988 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2989 return null;
2990 }
2991
Sanket Padawe7310cc72015-01-14 09:53:20 -08002992 final Phone phone = PhoneFactory.getPhone(0);
2993 if (phone != null) {
2994 return phone.getDeviceId();
2995 } else {
2996 return null;
2997 }
2998 }
2999
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003000 /*
3001 * {@hide}
3002 * Returns the IMS Registration Status
3003 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003004 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003005 public boolean isImsRegistered() {
3006 return mPhone.isImsRegistered();
3007 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003008
3009 @Override
3010 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3011 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3012 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003013
Nathan Haroldc55097a2015-03-11 18:14:50 -07003014 /*
3015 * {@hide}
3016 * Returns the IMS Registration Status
3017 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003018 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003019 return mPhone.isWifiCallingEnabled();
3020 }
3021
3022 /*
3023 * {@hide}
3024 * Returns the IMS Registration Status
3025 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003026 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003027 return mPhone.isVolteEnabled();
3028 }
Svet Ganovb320e182015-04-16 12:30:10 -07003029
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003030 /*
3031 * {@hide} Returns the IMS Registration Status
3032 */
3033 public boolean isVideoTelephonyAvailable() {
3034 return mPhone.isVideoEnabled();
3035 }
3036
Svet Ganovb320e182015-04-16 12:30:10 -07003037 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003038 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003039 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003040 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3041
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003042 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003043 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003044 } catch (SecurityException e) {
3045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3046 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003047 }
Svet Ganovb320e182015-04-16 12:30:10 -07003048
3049 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3050 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3051 return false;
3052 }
3053
3054 return true;
3055 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003056
Makoto Onukifee69342015-06-29 14:44:50 -07003057 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003058 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003059 */
3060 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003061 // Default SMS app can always read it.
3062 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3063 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3064 return true;
3065 }
3066 try {
3067 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003068 } catch (SecurityException readPhoneStateSecurityException) {
3069 try {
3070 // Can be read with READ_SMS too.
3071 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3072 return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
3073 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
3074 } catch (SecurityException readSmsSecurityException) {
3075 // Throw exception with message including both READ_PHONE_STATE and READ_SMS
3076 // permissions
3077 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3078 " nor current process has " + android.Manifest.permission.READ_PHONE_STATE +
3079 " or " + android.Manifest.permission.READ_SMS + ".");
3080 }
Makoto Onukie4072d12015-08-03 15:12:23 -07003081 }
Makoto Onukifee69342015-06-29 14:44:50 -07003082 }
3083
Stuart Scott8eef64f2015-04-08 15:13:54 -07003084 @Override
3085 public void factoryReset(int subId) {
3086 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003087 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3088 return;
3089 }
3090
Svet Ganovcc087f82015-05-12 20:35:54 -07003091 final long identity = Binder.clearCallingIdentity();
3092 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003093 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3094 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003095 // Enable data
3096 setDataEnabled(subId, true);
3097 // Set network selection mode to automatic
3098 setNetworkSelectionModeAutomatic(subId);
3099 // Set preferred mobile network type to the best available
3100 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3101 // Turn off roaming
3102 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3103 }
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003106 }
3107 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003108
3109 @Override
3110 public String getLocaleFromDefaultSim() {
3111 // We query all subscriptions instead of just the active ones, because
3112 // this might be called early on in the provisioning flow when the
3113 // subscriptions potentially aren't active yet.
3114 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3115 if (slist == null || slist.isEmpty()) {
3116 return null;
3117 }
3118
3119 // This function may be called very early, say, from the setup wizard, at
3120 // which point we won't have a default subscription set. If that's the case
3121 // we just choose the first, which will be valid in "most cases".
3122 final int defaultSubId = getDefaultSubscription();
3123 SubscriptionInfo info = null;
3124 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3125 info = slist.get(0);
3126 } else {
3127 for (SubscriptionInfo item : slist) {
3128 if (item.getSubscriptionId() == defaultSubId) {
3129 info = item;
3130 break;
3131 }
3132 }
3133
3134 if (info == null) {
3135 return null;
3136 }
3137 }
3138
3139 // Try and fetch the locale from the carrier properties or from the SIM language
3140 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003141 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003142 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003143 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003144 if (defaultPhone != null) {
3145 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3146 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003147 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003148 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3149 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003150 } else {
3151 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003152 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003153 }
3154 }
3155
Narayan Kamath011676f2015-07-29 12:04:08 +01003156 // The SIM language preferences only store a language (e.g. fr = French), not an
3157 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3158 // the SIM and carrier preferences does not include a country we add the country
3159 // determined from the SIM MCC to provide an exact locale.
3160 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003161 if (mccLocale != null) {
3162 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3163 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003164 }
3165
Tony Hill183b2de2015-06-24 14:53:58 +01003166 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003167 return null;
3168 }
3169
3170 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 return mSubscriptionController.getAllSubInfoList(
3174 mPhone.getContext().getOpPackageName());
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
3178 }
3179
3180 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 return mSubscriptionController.getActiveSubscriptionInfoList(
3184 mPhone.getContext().getOpPackageName());
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003189
3190 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003191 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3192 * representing the state of the modem.
3193 *
3194 * NOTE: This clears the modem state, so there should only every be one caller.
3195 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003196 */
3197 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003198 public void requestModemActivityInfo(ResultReceiver result) {
3199 enforceModifyPermission();
3200
3201 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3202 Bundle bundle = new Bundle();
3203 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3204 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003205 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003206
3207 /**
3208 * {@hide}
3209 * Returns the service state information on specified subscription.
3210 */
3211 @Override
3212 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3213
3214 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3215 return null;
3216 }
3217
3218 final Phone phone = getPhone(subId);
3219 if (phone == null) {
3220 return null;
3221 }
3222
3223 return phone.getServiceState();
3224 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003225
3226 /**
3227 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3228 *
3229 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3230 * voicemail ringtone.
3231 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3232 * PhoneAccount.
3233 */
3234 @Override
3235 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3236 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3237 if (phone == null) {
3238 return null;
3239 }
3240
3241 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3242 }
3243
3244 /**
3245 * Returns whether vibration is set for voicemail notification in Phone settings.
3246 *
3247 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3248 * voicemail vibration setting.
3249 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3250 */
3251 @Override
3252 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3253 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3254 if (phone == null) {
3255 return false;
3256 }
3257
3258 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3259 }
3260
Youhan Wange64578a2016-05-02 15:32:42 -07003261 /**
3262 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3263 *
3264 * @throws SecurityException if the caller does not have the required permission
3265 */
3266 private void enforceReadPrivilegedPermission() {
3267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3268 null);
3269 }
3270
3271 /**
3272 * Return the application ID for the app type.
3273 *
3274 * @param subId the subscription ID that this request applies to.
3275 * @param appType the uicc app type.
3276 * @return Application ID for specificied app type, or null if no uicc.
3277 */
3278 @Override
3279 public String getAidForAppType(int subId, int appType) {
3280 enforceReadPrivilegedPermission();
3281 Phone phone = getPhone(subId);
3282 if (phone == null) {
3283 return null;
3284 }
3285 String aid = null;
3286 try {
3287 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3288 .getApplicationByType(appType).getAid();
3289 } catch (Exception e) {
3290 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3291 }
3292 return aid;
3293 }
3294
Youhan Wang4001d252016-05-11 10:29:41 -07003295 /**
3296 * Return the Electronic Serial Number.
3297 *
3298 * @param subId the subscription ID that this request applies to.
3299 * @return ESN or null if error.
3300 */
3301 @Override
3302 public String getEsn(int subId) {
3303 enforceReadPrivilegedPermission();
3304 Phone phone = getPhone(subId);
3305 if (phone == null) {
3306 return null;
3307 }
3308 String esn = null;
3309 try {
3310 esn = phone.getEsn();
3311 } catch (Exception e) {
3312 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3313 }
3314 return esn;
3315 }
3316
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003317 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003318 * Return the Preferred Roaming List Version.
3319 *
3320 * @param subId the subscription ID that this request applies to.
3321 * @return PRLVersion or null if error.
3322 */
3323 @Override
3324 public String getCdmaPrlVersion(int subId) {
3325 enforceReadPrivilegedPermission();
3326 Phone phone = getPhone(subId);
3327 if (phone == null) {
3328 return null;
3329 }
3330 String cdmaPrlVersion = null;
3331 try {
3332 cdmaPrlVersion = phone.getCdmaPrlVersion();
3333 } catch (Exception e) {
3334 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3335 }
3336 return cdmaPrlVersion;
3337 }
3338
3339 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003340 * Get snapshot of Telephony histograms
3341 * @return List of Telephony histograms
3342 * @hide
3343 */
3344 @Override
3345 public List<TelephonyHistogram> getTelephonyHistograms() {
3346 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3347 return RIL.getTelephonyRILTimingHistograms();
3348 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003349
3350 /**
3351 * {@hide}
3352 * Set the allowed carrier list for slotId
3353 * Require system privileges. In the future we may add this to carrier APIs.
3354 *
3355 * @return The number of carriers set successfully, should match length of carriers
3356 */
3357 @Override
3358 public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
3359 enforceModifyPermission();
3360 int subId = SubscriptionManager.getSubId(slotId)[0];
3361 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3362 return retVal[0];
3363 }
3364
3365 /**
3366 * {@hide}
3367 * Get the allowed carrier list for slotId.
3368 * Require system privileges. In the future we may add this to carrier APIs.
3369 *
3370 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3371 * means all carriers are allowed.
3372 */
3373 @Override
3374 public List<CarrierIdentifier> getAllowedCarriers(int slotId) {
3375 enforceReadPrivilegedPermission();
3376 int subId = SubscriptionManager.getSubId(slotId)[0];
3377 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3378 }
3379
fionaxu59545b42016-05-25 15:53:37 -07003380 /**
3381 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3382 * @param subId the subscription ID that this action applies to.
3383 * @param enabled control enable or disable metered apns.
3384 * {@hide}
3385 */
3386 @Override
3387 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3388 enforceModifyPermission();
3389 final Phone phone = getPhone(subId);
3390 if (phone == null) {
3391 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3392 return;
3393 }
3394 try {
3395 phone.carrierActionSetMeteredApnsEnabled(enabled);
3396 } catch (Exception e) {
3397 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3398 }
3399 }
3400
3401 /**
3402 * Action set from carrier signalling broadcast receivers to enable/disable radio
3403 * @param subId the subscription ID that this action applies to.
3404 * @param enabled control enable or disable radio.
3405 * {@hide}
3406 */
3407 @Override
3408 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3409 enforceModifyPermission();
3410 final Phone phone = getPhone(subId);
3411 if (phone == null) {
3412 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3413 return;
3414 }
3415 try {
3416 phone.carrierActionSetRadioEnabled(enabled);
3417 } catch (Exception e) {
3418 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3419 }
3420 }
3421
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003422 /**
3423 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3424 * bug report is being generated.
3425 */
3426 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003427 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003428 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3429 != PackageManager.PERMISSION_GRANTED) {
3430 writer.println("Permission Denial: can't dump Phone from pid="
3431 + Binder.getCallingPid()
3432 + ", uid=" + Binder.getCallingUid()
3433 + "without permission "
3434 + android.Manifest.permission.DUMP);
3435 return;
3436 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003437 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003438 }
Jack Yueb89b242016-06-22 13:27:47 -07003439
3440 /**
3441 * Get aggregated video call data usage from all subscriptions since boot.
3442 * @return total data usage in bytes
3443 * {@hide}
3444 */
3445 @Override
3446 public long getVtDataUsage() {
3447 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3448 null);
3449
3450 // NetworkStatsService keeps tracking the active network interface and identity. It will
3451 // record the delta with the corresponding network identity. What we need to do here is
3452 // returning total video call data usage from all subscriptions since boot.
3453
3454 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3455 // simultaneous VT calls.
3456 final Phone[] phones = PhoneFactory.getPhones();
3457 long total = 0;
3458 for (Phone phone : phones) {
3459 total += phone.getVtDataUsage();
3460 }
3461 return total;
3462 }
Jack Yu75ab2952016-07-08 14:29:33 -07003463
3464 /**
3465 * Policy control of data connection. Usually used when data limit is passed.
3466 * @param enabled True if enabling the data, otherwise disabling.
3467 * @param subId Subscription index
3468 * {@hide}
3469 */
3470 @Override
3471 public void setPolicyDataEnabled(boolean enabled, int subId) {
3472 enforceModifyPermission();
3473 Phone phone = getPhone(subId);
3474 if (phone != null) {
3475 phone.setPolicyDataEnabled(enabled);
3476 }
3477 }
Sooraj Sasindran600a37a2016-07-18 11:57:25 -07003478
3479 /**
3480 * Get Client request stats
3481 * @return List of Client Request Stats
3482 * @hide
3483 */
3484 @Override
3485 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3486 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3487 return null;
3488 }
3489
3490 Phone phone = getPhone(subId);
3491 if (phone != null) {
3492 return phone.getClientRequestStats();
3493 }
3494
3495 return null;
3496 }
3497
3498 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3499 if (workSource != null) {
3500 return workSource;
3501 }
3502
3503 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3504 workSource = new WorkSource(uid, packageName);
3505 return workSource;
3506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003507}