blob: 74938581ebf7be3dbe1515c6cde7c36c548a0674 [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
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Process;
Tyler Gunn65d45c22017-06-05 11:22:26 -070043import android.os.PersistableBundle;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
46import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080080import com.android.ims.internal.IImsServiceController;
81import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070082import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070083import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070084import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080088import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010089import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070090import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070091import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080093import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070094import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070095import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070098import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080099import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700100import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700101import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.uicc.IccIoResult;
103import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800104import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700105import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800106import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700108import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800109import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700110import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800111import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700112import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700113import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700115import java.io.FileDescriptor;
116import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800120import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100121import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800122import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123
124/**
125 * Implementation of the ITelephony interface.
126 */
Santos Cordon117fee72014-05-16 17:56:12 -0700127public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 private static final String LOG_TAG = "PhoneInterfaceManager";
129 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
130 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132
133 // Message codes used with mMainThreadHandler
134 private static final int CMD_HANDLE_PIN_MMI = 1;
135 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
136 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
137 private static final int CMD_ANSWER_RINGING_CALL = 4;
138 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700139 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
140 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141 private static final int CMD_OPEN_CHANNEL = 9;
142 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
143 private static final int CMD_CLOSE_CHANNEL = 11;
144 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800145 private static final int CMD_NV_READ_ITEM = 13;
146 private static final int EVENT_NV_READ_ITEM_DONE = 14;
147 private static final int CMD_NV_WRITE_ITEM = 15;
148 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
149 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
150 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
151 private static final int CMD_NV_RESET_CONFIG = 19;
152 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800153 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
154 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
155 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
156 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800157 private static final int CMD_SEND_ENVELOPE = 25;
158 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700159 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
160 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
161 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
162 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
163 private static final int CMD_EXCHANGE_SIM_IO = 31;
164 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800165 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
166 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700167 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
168 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700169 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
170 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
172 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
173 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
174 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700175 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
176 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
177 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
178 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700179 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
181 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182
183 /** The singleton instance. */
184 private static PhoneInterfaceManager sInstance;
185
Wink Saville3ab207e2014-11-20 13:07:20 -0800186 private PhoneGlobals mApp;
187 private Phone mPhone;
188 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700189 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800190 private AppOpsManager mAppOps;
191 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800192 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800193 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Derek Tan97ebb422014-09-05 16:55:38 -0700195 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
196 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700198
Derek Tan740e1672017-06-27 14:56:27 -0700199 // The AID of ISD-R.
200 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
201
yinxub1bed742017-04-17 11:45:04 -0700202 private NetworkScanRequestTracker mNetworkScanRequestTracker;
203
Derek Tan89e89d42014-07-08 17:00:10 -0700204 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205 * A request object to use for transmitting data to an ICC.
206 */
207 private static final class IccAPDUArgument {
208 public int channel, cla, command, p1, p2, p3;
209 public String data;
210
211 public IccAPDUArgument(int channel, int cla, int command,
212 int p1, int p2, int p3, String data) {
213 this.channel = channel;
214 this.cla = cla;
215 this.command = command;
216 this.p1 = p1;
217 this.p2 = p2;
218 this.p3 = p3;
219 this.data = data;
220 }
221 }
222
223 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700224 * A request object to use for transmitting data to an ICC.
225 */
226 private static final class ManualNetworkSelectionArgument {
227 public OperatorInfo operatorInfo;
228 public boolean persistSelection;
229
230 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
231 this.operatorInfo = operatorInfo;
232 this.persistSelection = persistSelection;
233 }
234 }
235
236 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
238 * request after sending. The main thread will notify the request when it is complete.
239 */
240 private static final class MainThreadRequest {
241 /** The argument to use for the request */
242 public Object argument;
243 /** The result of the request that is run on the main thread */
244 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800245 // The subscriber id that this request applies to. Defaults to
246 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
247 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 public MainThreadRequest(Object argument) {
250 this.argument = argument;
251 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800252
253 public MainThreadRequest(Object argument, Integer subId) {
254 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800255 if (subId != null) {
256 this.subId = subId;
257 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 }
260
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800261 private static final class IncomingThirdPartyCallArgs {
262 public final ComponentName component;
263 public final String callId;
264 public final String callerDisplayName;
265
266 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
267 String callerDisplayName) {
268 this.component = component;
269 this.callId = callId;
270 this.callerDisplayName = callerDisplayName;
271 }
272 }
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /**
275 * A handler that processes messages on the main thread in the phone process. Since many
276 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
277 * inbound binder threads to the main thread in the phone process. The Binder thread
278 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
279 * on, which will be notified when the operation completes and will contain the result of the
280 * request.
281 *
282 * <p>If a MainThreadRequest object is provided in the msg.obj field,
283 * note that request.result must be set to something non-null for the calling thread to
284 * unblock.
285 */
286 private final class MainThreadHandler extends Handler {
287 @Override
288 public void handleMessage(Message msg) {
289 MainThreadRequest request;
290 Message onCompleted;
291 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800292 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700293 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294
295 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700296 case CMD_HANDLE_USSD_REQUEST: {
297 request = (MainThreadRequest) msg.obj;
298 final Phone phone = getPhoneFromRequest(request);
299 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
300 String ussdRequest = ussdObject.first;
301 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700302
303 if (!isUssdApiAllowed(request.subId)) {
304 // Carrier does not support use of this API, return failure.
305 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
306 UssdResponse response = new UssdResponse(ussdRequest, null);
307 Bundle returnData = new Bundle();
308 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
309 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
310
311 request.result = true;
312 synchronized (request) {
313 request.notifyAll();
314 }
315 return;
316 }
317
Tyler Gunn52dcf772017-04-26 11:30:31 -0700318 try {
319 request.result = phone != null ?
320 phone.handleUssdRequest(ussdRequest, wrappedCallback)
321 : false;
322 } catch (CallStateException cse) {
323 request.result = false;
324 }
pkanwar32d516d2016-10-14 19:37:38 -0700325 // Wake up the requesting thread
326 synchronized (request) {
327 request.notifyAll();
328 }
329 break;
330 }
331
Yorke Lee716f67e2015-06-17 15:39:16 -0700332 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700334 final Phone phone = getPhoneFromRequest(request);
335 request.result = phone != null ?
336 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
337 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Wake up the requesting thread
339 synchronized (request) {
340 request.notifyAll();
341 }
342 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
345 case CMD_HANDLE_NEIGHBORING_CELL:
346 request = (MainThreadRequest) msg.obj;
347 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
348 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700349 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 break;
351
352 case EVENT_NEIGHBORING_CELL_DONE:
353 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 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800359 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 }
361 // Wake up the requesting thread
362 synchronized (request) {
363 request.notifyAll();
364 }
365 break;
366
367 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700368 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800369 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700370 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 case CMD_END_CALL:
374 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800375 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700376 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700377 Phone phone = getPhone(end_subId);
378 if (phone == null) {
379 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
380 break;
381 }
382 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
384 // CDMA: If the user presses the Power button we treat it as
385 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700386 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
388 // GSM: End the call as per the Phone state
389 hungUp = PhoneUtils.hangup(mCM);
390 } else {
391 throw new IllegalStateException("Unexpected phone type: " + phoneType);
392 }
393 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
394 request.result = hungUp;
395 // Wake up the requesting thread
396 synchronized (request) {
397 request.notifyAll();
398 }
399 break;
400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700405 if (uiccCard == null) {
406 loge("iccTransmitApduLogicalChannel: No UICC");
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
408 synchronized (request) {
409 request.notifyAll();
410 }
411 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
413 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument.channel, iccArgument.cla, iccArgument.command,
416 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 break;
420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 ar = (AsyncResult) msg.obj;
423 request = (MainThreadRequest) ar.userObj;
424 if (ar.exception == null && ar.result != null) {
425 request.result = ar.result;
426 } else {
427 request.result = new IccIoResult(0x6F, 0, (byte[])null);
428 if (ar.result == null) {
429 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800430 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800432 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 } else {
434 loge("iccTransmitApduLogicalChannel: Unknown exception");
435 }
436 }
437 synchronized (request) {
438 request.notifyAll();
439 }
440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
443 request = (MainThreadRequest) msg.obj;
444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduBasicChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 synchronized (request) {
450 request.notifyAll();
451 }
452 } else {
453 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
454 request);
455 uiccCard.iccTransmitApduBasicChannel(
456 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
457 iccArgument.p3, iccArgument.data, onCompleted);
458 }
459 break;
460
461 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
462 ar = (AsyncResult) msg.obj;
463 request = (MainThreadRequest) ar.userObj;
464 if (ar.exception == null && ar.result != null) {
465 request.result = ar.result;
466 } else {
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
468 if (ar.result == null) {
469 loge("iccTransmitApduBasicChannel: Empty response");
470 } else if (ar.exception instanceof CommandException) {
471 loge("iccTransmitApduBasicChannel: CommandException: " +
472 ar.exception);
473 } else {
474 loge("iccTransmitApduBasicChannel: Unknown exception");
475 }
476 }
477 synchronized (request) {
478 request.notifyAll();
479 }
480 break;
481
482 case CMD_EXCHANGE_SIM_IO:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccExchangeSimIO: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 synchronized (request) {
490 request.notifyAll();
491 }
492 } else {
493 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
494 request);
495 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
496 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
497 iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_EXCHANGE_SIM_IO_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6f, 0, (byte[])null);
508 }
509 synchronized (request) {
510 request.notifyAll();
511 }
512 break;
513
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 case CMD_SEND_ENVELOPE:
515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800516 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 if (uiccCard == null) {
518 loge("sendEnvelopeWithStatus: No UICC");
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 synchronized (request) {
521 request.notifyAll();
522 }
523 } else {
524 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
525 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
526 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 break;
528
529 case EVENT_SEND_ENVELOPE_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("sendEnvelopeWithStatus: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("sendEnvelopeWithStatus: CommandException: " +
540 ar.exception);
541 } else {
542 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
543 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 }
545 synchronized (request) {
546 request.notifyAll();
547 }
548 break;
549
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 case CMD_OPEN_CHANNEL:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800553 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 if (uiccCard == null) {
555 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800556 request.result = new IccOpenLogicalChannelResponse(-1,
557 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 synchronized (request) {
559 request.notifyAll();
560 }
561 } else {
562 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
564 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
568 case EVENT_OPEN_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 int[] result = (int[]) ar.result;
574 int channelId = result[0];
575 byte[] selectResponse = null;
576 if (result.length > 1) {
577 selectResponse = new byte[result.length - 1];
578 for (int i = 1; i < result.length; ++i) {
579 selectResponse[i - 1] = (byte) result[i];
580 }
581 }
582 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.result == null) {
586 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (ar.exception != null) {
589 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
590 }
591
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700593 if (ar.exception instanceof CommandException) {
594 CommandException.Error error =
595 ((CommandException) (ar.exception)).getCommandError();
596 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700598 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 }
601 }
602 openChannelResp = new IccOpenLogicalChannelResponse(
603 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700605 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 synchronized (request) {
607 request.notifyAll();
608 }
609 break;
610
611 case CMD_CLOSE_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 if (uiccCard == null) {
615 loge("iccCloseLogicalChannel: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
617 synchronized (request) {
618 request.notifyAll();
619 }
620 } else {
621 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
622 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
623 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 break;
625
626 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800627 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
628 break;
629
630 case CMD_NV_READ_ITEM:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
633 mPhone.nvReadItem((Integer) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800642 request.result = "";
643 if (ar.result == null) {
644 loge("nvReadItem: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("nvReadItem: CommandException: " +
647 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800649 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 }
651 }
652 synchronized (request) {
653 request.notifyAll();
654 }
655 break;
656
Jake Hambye994d462014-02-03 13:10:13 -0800657 case CMD_NV_WRITE_ITEM:
658 request = (MainThreadRequest) msg.obj;
659 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
660 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
661 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
662 break;
663
664 case EVENT_NV_WRITE_ITEM_DONE:
665 handleNullReturnEvent(msg, "nvWriteItem");
666 break;
667
668 case CMD_NV_WRITE_CDMA_PRL:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
671 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
672 break;
673
674 case EVENT_NV_WRITE_CDMA_PRL_DONE:
675 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
676 break;
677
678 case CMD_NV_RESET_CONFIG:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
681 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
682 break;
683
684 case EVENT_NV_RESET_CONFIG_DONE:
685 handleNullReturnEvent(msg, "nvResetConfig");
686 break;
687
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 case CMD_GET_PREFERRED_NETWORK_TYPE:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700691 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 break;
693
694 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result; // Integer
699 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800700 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 if (ar.result == null) {
702 loge("getPreferredNetworkType: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("getPreferredNetworkType: CommandException: " +
705 ar.exception);
706 } else {
707 loge("getPreferredNetworkType: Unknown exception");
708 }
709 }
710 synchronized (request) {
711 request.notifyAll();
712 }
713 break;
714
715 case CMD_SET_PREFERRED_NETWORK_TYPE:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
718 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700719 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
723 handleNullReturnEvent(msg, "setPreferredNetworkType");
724 break;
725
Steven Liu4bf01bc2014-07-17 11:05:29 -0500726 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
727 request = (MainThreadRequest)msg.obj;
728 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
729 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
730 break;
731
732 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
733 ar = (AsyncResult)msg.obj;
734 request = (MainThreadRequest)ar.userObj;
735 request.result = ar;
736 synchronized (request) {
737 request.notifyAll();
738 }
739 break;
740
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800741 case CMD_SET_VOICEMAIL_NUMBER:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
744 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800745 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
746 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800747 break;
748
749 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
750 handleNullReturnEvent(msg, "setVoicemailNumber");
751 break;
752
Stuart Scott54788802015-03-30 13:18:01 -0700753 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
756 request);
757 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
758 break;
759
760 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
761 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
762 break;
763
Shishir Agrawal302c8692015-06-19 13:49:39 -0700764 case CMD_PERFORM_NETWORK_SCAN:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
767 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
768 break;
769
770 case EVENT_PERFORM_NETWORK_SCAN_DONE:
771 ar = (AsyncResult) msg.obj;
772 request = (MainThreadRequest) ar.userObj;
773 CellNetworkScanResult cellScanResult;
774 if (ar.exception == null && ar.result != null) {
775 cellScanResult = new CellNetworkScanResult(
776 CellNetworkScanResult.STATUS_SUCCESS,
777 (List<OperatorInfo>) ar.result);
778 } else {
779 if (ar.result == null) {
780 loge("getCellNetworkScanResults: Empty response");
781 }
782 if (ar.exception != null) {
783 loge("getCellNetworkScanResults: Exception: " + ar.exception);
784 }
785 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
786 if (ar.exception instanceof CommandException) {
787 CommandException.Error error =
788 ((CommandException) (ar.exception)).getCommandError();
789 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
790 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
791 } else if (error == CommandException.Error.GENERIC_FAILURE) {
792 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
793 }
794 }
795 cellScanResult = new CellNetworkScanResult(errorCode, null);
796 }
797 request.result = cellScanResult;
798 synchronized (request) {
799 request.notifyAll();
800 }
801 break;
802
803 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
804 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700805 ManualNetworkSelectionArgument selArg =
806 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
808 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700809 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
810 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
813 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
814 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
815 break;
816
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 case CMD_GET_MODEM_ACTIVITY_INFO:
818 request = (MainThreadRequest) msg.obj;
819 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700820 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700821 break;
822
823 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null && ar.result != null) {
827 request.result = ar.result;
828 } else {
829 if (ar.result == null) {
830 loge("queryModemActivityInfo: Empty response");
831 } else if (ar.exception instanceof CommandException) {
832 loge("queryModemActivityInfo: CommandException: " +
833 ar.exception);
834 } else {
835 loge("queryModemActivityInfo: Unknown exception");
836 }
837 }
Amit Mahajand4766222016-01-28 15:28:28 -0800838 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
839 if (request.result == null) {
840 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
841 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700842 synchronized (request) {
843 request.notifyAll();
844 }
845 break;
846
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 case CMD_SET_ALLOWED_CARRIERS:
848 request = (MainThreadRequest) msg.obj;
849 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
850 mPhone.setAllowedCarriers(
851 (List<CarrierIdentifier>) request.argument,
852 onCompleted);
853 break;
854
855 case EVENT_SET_ALLOWED_CARRIERS_DONE:
856 ar = (AsyncResult) msg.obj;
857 request = (MainThreadRequest) ar.userObj;
858 if (ar.exception == null && ar.result != null) {
859 request.result = ar.result;
860 } else {
861 if (ar.result == null) {
862 loge("setAllowedCarriers: Empty response");
863 } else if (ar.exception instanceof CommandException) {
864 loge("setAllowedCarriers: CommandException: " +
865 ar.exception);
866 } else {
867 loge("setAllowedCarriers: Unknown exception");
868 }
869 }
870 // Result cannot be null. Return -1 on error.
871 if (request.result == null) {
872 request.result = new int[]{-1};
873 }
874 synchronized (request) {
875 request.notifyAll();
876 }
877 break;
878
879 case CMD_GET_ALLOWED_CARRIERS:
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
882 mPhone.getAllowedCarriers(onCompleted);
883 break;
884
885 case EVENT_GET_ALLOWED_CARRIERS_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result;
890 } else {
891 if (ar.result == null) {
892 loge("getAllowedCarriers: Empty response");
893 } else if (ar.exception instanceof CommandException) {
894 loge("getAllowedCarriers: CommandException: " +
895 ar.exception);
896 } else {
897 loge("getAllowedCarriers: Unknown exception");
898 }
899 }
900 // Result cannot be null. Return empty list of CarrierIdentifier.
901 if (request.result == null) {
902 request.result = new ArrayList<CarrierIdentifier>(0);
903 }
904 synchronized (request) {
905 request.notifyAll();
906 }
907 break;
908
Nathan Haroldb3014052017-01-25 15:57:32 -0800909 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 request.result = new IllegalArgumentException(
916 "Failed to retrieve Forbidden Plmns");
917 if (ar.result == null) {
918 loge("getForbiddenPlmns: Empty response");
919 } else {
920 loge("getForbiddenPlmns: Unknown exception");
921 }
922 }
923 synchronized (request) {
924 request.notifyAll();
925 }
926 break;
927
928 case CMD_GET_FORBIDDEN_PLMNS:
929 request = (MainThreadRequest) msg.obj;
930 uiccCard = getUiccCardFromRequest(request);
931 if (uiccCard == null) {
932 loge("getForbiddenPlmns() UiccCard is null");
933 request.result = new IllegalArgumentException(
934 "getForbiddenPlmns() UiccCard is null");
935 synchronized (request) {
936 request.notifyAll();
937 }
938 break;
939 }
940 Integer appType = (Integer) request.argument;
941 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
942 if (uiccApp == null) {
943 loge("getForbiddenPlmns() no app with specified type -- "
944 + appType);
945 request.result = new IllegalArgumentException("Failed to get UICC App");
946 synchronized (request) {
947 request.notifyAll();
948 }
949 break;
950 } else {
951 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
952 + " specified type -- " + appType);
953 }
954 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
955 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
956 onCompleted);
957 break;
958
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 default:
960 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
961 break;
962 }
963 }
Jake Hambye994d462014-02-03 13:10:13 -0800964
965 private void handleNullReturnEvent(Message msg, String command) {
966 AsyncResult ar = (AsyncResult) msg.obj;
967 MainThreadRequest request = (MainThreadRequest) ar.userObj;
968 if (ar.exception == null) {
969 request.result = true;
970 } else {
971 request.result = false;
972 if (ar.exception instanceof CommandException) {
973 loge(command + ": CommandException: " + ar.exception);
974 } else {
975 loge(command + ": Unknown exception");
976 }
977 }
978 synchronized (request) {
979 request.notifyAll();
980 }
981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700982 }
983
984 /**
985 * Posts the specified command to be executed on the main thread,
986 * waits for the request to complete, and returns the result.
987 * @see #sendRequestAsync
988 */
989 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800990 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700991 }
992
993 /**
994 * Posts the specified command to be executed on the main thread,
995 * waits for the request to complete, and returns the result.
996 * @see #sendRequestAsync
997 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800998 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700999 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1000 throw new RuntimeException("This method will deadlock if called from the main thread.");
1001 }
1002
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001003 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 Message msg = mMainThreadHandler.obtainMessage(command, request);
1005 msg.sendToTarget();
1006
1007 // Wait for the request to complete
1008 synchronized (request) {
1009 while (request.result == null) {
1010 try {
1011 request.wait();
1012 } catch (InterruptedException e) {
1013 // Do nothing, go back and wait until the request is complete
1014 }
1015 }
1016 }
1017 return request.result;
1018 }
1019
1020 /**
1021 * Asynchronous ("fire and forget") version of sendRequest():
1022 * Posts the specified command to be executed on the main thread, and
1023 * returns immediately.
1024 * @see #sendRequest
1025 */
1026 private void sendRequestAsync(int command) {
1027 mMainThreadHandler.sendEmptyMessage(command);
1028 }
1029
1030 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001031 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1032 * @see {@link #sendRequest(int,Object)}
1033 */
1034 private void sendRequestAsync(int command, Object argument) {
1035 MainThreadRequest request = new MainThreadRequest(argument);
1036 Message msg = mMainThreadHandler.obtainMessage(command, request);
1037 msg.sendToTarget();
1038 }
1039
1040 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001041 * Initialize the singleton PhoneInterfaceManager instance.
1042 * This is only done once, at startup, from PhoneApp.onCreate().
1043 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001044 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 synchronized (PhoneInterfaceManager.class) {
1046 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001047 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001048 } else {
1049 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1050 }
1051 return sInstance;
1052 }
1053 }
1054
1055 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001056 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 mApp = app;
1058 mPhone = phone;
1059 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001060 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1062 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001063 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001064 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001065 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001066 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001067
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 publish();
1069 }
1070
1071 private void publish() {
1072 if (DBG) log("publish: " + this);
1073
1074 ServiceManager.addService("phone", this);
1075 }
1076
Stuart Scott584921c2015-01-15 17:10:34 -08001077 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001078 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1079 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001080 }
1081
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001082 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1083 Phone phone = getPhoneFromRequest(request);
1084 return phone == null ? null :
1085 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1086 }
1087
Wink Saville36469e72014-06-11 15:17:00 -07001088 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001089 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001090 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001092 //
1093 // Implementation of the ITelephony interface.
1094 //
1095
1096 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001097 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001098 }
1099
Wink Savilleb564aae2014-10-23 10:18:09 -07001100 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001101 if (DBG) log("dial: " + number);
1102 // No permission check needed here: This is just a wrapper around the
1103 // ACTION_DIAL intent, which is available to any app since it puts up
1104 // the UI before it does anything.
1105
1106 String url = createTelUrl(number);
1107 if (url == null) {
1108 return;
1109 }
1110
1111 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001112 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1114 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1115 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1116 mApp.startActivity(intent);
1117 }
1118 }
1119
1120 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001121 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001122 }
1123
Wink Savilleb564aae2014-10-23 10:18:09 -07001124 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 if (DBG) log("call: " + number);
1126
1127 // This is just a wrapper around the ACTION_CALL intent, but we still
1128 // need to do a permission check since we're calling startActivity()
1129 // from the context of the phone app.
1130 enforceCallPermission();
1131
1132 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1133 != AppOpsManager.MODE_ALLOWED) {
1134 return;
1135 }
1136
1137 String url = createTelUrl(number);
1138 if (url == null) {
1139 return;
1140 }
1141
Wink Saville08874612014-08-31 19:19:58 -07001142 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001143 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001144 if (slist != null) {
1145 for (SubscriptionInfo subInfoRecord : slist) {
1146 if (subInfoRecord.getSubscriptionId() == subId) {
1147 isValid = true;
1148 break;
1149 }
Wink Saville08874612014-08-31 19:19:58 -07001150 }
1151 }
1152 if (isValid == false) {
1153 return;
1154 }
1155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001156 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001157 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1159 mApp.startActivity(intent);
1160 }
1161
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 /**
1163 * End a call based on call state
1164 * @return true is a call was ended
1165 */
1166 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001167 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001168 }
1169
1170 /**
1171 * End a call based on the call state of the subId
1172 * @return true is a call was ended
1173 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001174 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001176 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 }
1178
1179 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001180 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
Wink Savilleb564aae2014-10-23 10:18:09 -07001183 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 if (DBG) log("answerRingingCall...");
1185 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1186 // but that can probably wait till the big TelephonyManager API overhaul.
1187 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1188 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001189 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
1192 /**
1193 * Make the actual telephony calls to implement answerRingingCall().
1194 * This should only be called from the main thread of the Phone app.
1195 * @see #answerRingingCall
1196 *
1197 * TODO: it would be nice to return true if we answered the call, or
1198 * false if there wasn't actually a ringing incoming call, or some
1199 * other error occurred. (In other words, pass back the return value
1200 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1201 * But that would require calling this method via sendRequest() rather
1202 * than sendRequestAsync(), and right now we don't actually *need* that
1203 * return value, so let's just return void for now.
1204 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001205 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001206 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001208 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1209 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 if (hasActiveCall && hasHoldingCall) {
1211 // Both lines are in use!
1212 // TODO: provide a flag to let the caller specify what
1213 // policy to use if both lines are in use. (The current
1214 // behavior is hardwired to "answer incoming, end ongoing",
1215 // which is how the CALL button is specced to behave.)
1216 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1217 return;
1218 } else {
1219 // answerCall() will automatically hold the current active
1220 // call, if there is one.
1221 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1222 return;
1223 }
1224 } else {
1225 // No call was ringing.
1226 return;
1227 }
1228 }
1229
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001231 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001233 public void silenceRinger() {
1234 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 }
1236
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001237 @Override
1238 public boolean isOffhook(String callingPackage) {
1239 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001240 }
1241
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001242 @Override
1243 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1244 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1245 return false;
1246 }
1247
Sanket Padawe356d7632015-06-22 14:03:32 -07001248 final Phone phone = getPhone(subId);
1249 if (phone != null) {
1250 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1251 } else {
1252 return false;
1253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 }
1255
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001256 @Override
1257 public boolean isRinging(String callingPackage) {
1258 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001259 }
1260
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 @Override
1262 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1263 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1264 return false;
1265 }
1266
Sanket Padawe356d7632015-06-22 14:03:32 -07001267 final Phone phone = getPhone(subId);
1268 if (phone != null) {
1269 return (phone.getState() == PhoneConstants.State.RINGING);
1270 } else {
1271 return false;
1272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 }
1274
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001275 @Override
1276 public boolean isIdle(String callingPackage) {
1277 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 @Override
1281 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1282 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1283 return false;
1284 }
1285
Sanket Padawe356d7632015-06-22 14:03:32 -07001286 final Phone phone = getPhone(subId);
1287 if (phone != null) {
1288 return (phone.getState() == PhoneConstants.State.IDLE);
1289 } else {
1290 return false;
1291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 }
1293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001295 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001296 }
1297
Wink Savilleb564aae2014-10-23 10:18:09 -07001298 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001300 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1301 }
1302
1303 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001309 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1310 }
1311
1312 /** {@hide} */
1313 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001319 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 checkSimPin.start();
1321 return checkSimPin.unlockSim(null, pin);
1322 }
1323
Wink Saville9de0f752013-10-22 19:04:03 -07001324 /** {@hide} */
1325 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001331 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 checkSimPuk.start();
1333 return checkSimPuk.unlockSim(puk, pin);
1334 }
1335
1336 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001337 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 * a synchronous one.
1339 */
1340 private static class UnlockSim extends Thread {
1341
1342 private final IccCard mSimCard;
1343
1344 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001345 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1346 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347
1348 // For replies from SimCard interface
1349 private Handler mHandler;
1350
1351 // For async handler to identify request type
1352 private static final int SUPPLY_PIN_COMPLETE = 100;
1353
1354 public UnlockSim(IccCard simCard) {
1355 mSimCard = simCard;
1356 }
1357
1358 @Override
1359 public void run() {
1360 Looper.prepare();
1361 synchronized (UnlockSim.this) {
1362 mHandler = new Handler() {
1363 @Override
1364 public void handleMessage(Message msg) {
1365 AsyncResult ar = (AsyncResult) msg.obj;
1366 switch (msg.what) {
1367 case SUPPLY_PIN_COMPLETE:
1368 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1369 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001370 mRetryCount = msg.arg1;
1371 if (ar.exception != null) {
1372 if (ar.exception instanceof CommandException &&
1373 ((CommandException)(ar.exception)).getCommandError()
1374 == CommandException.Error.PASSWORD_INCORRECT) {
1375 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1376 } else {
1377 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1378 }
1379 } else {
1380 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 mDone = true;
1383 UnlockSim.this.notifyAll();
1384 }
1385 break;
1386 }
1387 }
1388 };
1389 UnlockSim.this.notifyAll();
1390 }
1391 Looper.loop();
1392 }
1393
1394 /*
1395 * Use PIN or PUK to unlock SIM card
1396 *
1397 * If PUK is null, unlock SIM card with PIN
1398 *
1399 * If PUK is not null, unlock SIM card with PUK and set PIN code
1400 */
Wink Saville9de0f752013-10-22 19:04:03 -07001401 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402
1403 while (mHandler == null) {
1404 try {
1405 wait();
1406 } catch (InterruptedException e) {
1407 Thread.currentThread().interrupt();
1408 }
1409 }
1410 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1411
1412 if (puk == null) {
1413 mSimCard.supplyPin(pin, callback);
1414 } else {
1415 mSimCard.supplyPuk(puk, pin, callback);
1416 }
1417
1418 while (!mDone) {
1419 try {
1420 Log.d(LOG_TAG, "wait for done");
1421 wait();
1422 } catch (InterruptedException e) {
1423 // Restore the interrupted status
1424 Thread.currentThread().interrupt();
1425 }
1426 }
1427 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001428 int[] resultArray = new int[2];
1429 resultArray[0] = mResult;
1430 resultArray[1] = mRetryCount;
1431 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 }
1433 }
1434
1435 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001436 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001437
1438 }
1439
Wink Savilleb564aae2014-10-23 10:18:09 -07001440 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 // No permission check needed here: this call is harmless, and it's
1442 // needed for the ServiceState.requestStateUpdate() call (which is
1443 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001444 final Phone phone = getPhone(subId);
1445 if (phone != null) {
1446 phone.updateServiceLocation();
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001450 @Override
1451 public boolean isRadioOn(String callingPackage) {
1452 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001455 @Override
1456 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1457 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1458 return false;
1459 }
1460 return isRadioOnForSubscriber(subId);
1461 }
1462
1463 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001464 final Phone phone = getPhone(subId);
1465 if (phone != null) {
1466 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1467 } else {
1468 return false;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 }
1471
1472 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001473 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001474
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 }
Wink Saville36469e72014-06-11 15:17:00 -07001476
Wink Savilleb564aae2014-10-23 10:18:09 -07001477 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001479 final Phone phone = getPhone(subId);
1480 if (phone != null) {
1481 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1482 }
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
1485 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001490 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001491 final Phone phone = getPhone(subId);
1492 if (phone == null) {
1493 return false;
1494 }
1495 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001496 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001497 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 }
1499 return true;
1500 }
Wink Saville36469e72014-06-11 15:17:00 -07001501
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001502 public boolean needMobileRadioShutdown() {
1503 /*
1504 * If any of the Radios are available, it will need to be
1505 * shutdown. So return true if any Radio is available.
1506 */
1507 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1508 Phone phone = PhoneFactory.getPhone(i);
1509 if (phone != null && phone.isRadioAvailable()) return true;
1510 }
1511 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1512 return false;
1513 }
1514
1515 public void shutdownMobileRadios() {
1516 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1517 logv("Shutting down Phone " + i);
1518 shutdownRadioUsingPhoneId(i);
1519 }
1520 }
1521
1522 private void shutdownRadioUsingPhoneId(int phoneId) {
1523 enforceModifyPermission();
1524 Phone phone = PhoneFactory.getPhone(phoneId);
1525 if (phone != null && phone.isRadioAvailable()) {
1526 phone.shutdownRadio();
1527 }
1528 }
1529
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001531 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001532 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1533 if (defaultPhone != null) {
1534 defaultPhone.setRadioPower(turnOn);
1535 return true;
1536 } else {
1537 loge("There's no default phone.");
1538 return false;
1539 }
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001544 final Phone phone = getPhone(subId);
1545 if (phone != null) {
1546 phone.setRadioPower(turnOn);
1547 return true;
1548 } else {
1549 return false;
1550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 }
1552
Wink Saville36469e72014-06-11 15:17:00 -07001553 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 public boolean enableDataConnectivity() {
1556 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001557 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 final Phone phone = getPhone(subId);
1559 if (phone != null) {
1560 phone.setDataEnabled(true);
1561 return true;
1562 } else {
1563 return false;
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Saville36469e72014-06-11 15:17:00 -07001567 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 public boolean disableDataConnectivity() {
1570 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001571 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 final Phone phone = getPhone(subId);
1573 if (phone != null) {
1574 phone.setDataEnabled(false);
1575 return true;
1576 } else {
1577 return false;
1578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
1580
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001582 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 final Phone phone = getPhone(subId);
1584 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001585 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 } else {
1587 return false;
1588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
1591 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001593 }
1594
pkanwarae03a6b2016-11-06 20:37:09 -08001595 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001596 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001597 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1598 return;
1599 }
1600 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1601 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1602 };
1603
Wink Savilleb564aae2014-10-23 10:18:09 -07001604 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1607 return false;
1608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001613 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001614 }
1615
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001616 public int getCallStateForSlot(int slotIndex) {
1617 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001618 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001619 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001624 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001626 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001628 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
1631
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001634 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 if (phone != null) {
1636 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1637 } else {
1638 return TelephonyManager.DATA_ACTIVITY_NONE;
1639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 }
1641
1642 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001643 public Bundle getCellLocation(String callingPackage) {
1644 enforceFineOrCoarseLocationPermission("getCellLocation");
1645
1646 // OP_COARSE_LOCATION controls both fine and coarse location.
1647 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1648 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001649 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001650 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001653 if (checkIfCallerIsSelfOrForegroundUser() ||
1654 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 if (DBG_LOC) log("getCellLocation: is active user");
1656 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001657 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 if (phone == null) {
1659 return null;
1660 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001661
1662 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1663 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 return data;
1665 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001666 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 return null;
1668 }
1669 }
1670
Svetoslav64fad262015-04-14 14:35:21 -07001671 private void enforceFineOrCoarseLocationPermission(String message) {
1672 try {
1673 mApp.enforceCallingOrSelfPermission(
1674 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1675 } catch (SecurityException e) {
1676 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1677 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1678 // is the weaker precondition
1679 mApp.enforceCallingOrSelfPermission(
1680 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1681 }
1682 }
1683
1684
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001686 public String getNetworkCountryIsoForPhone(int phoneId) {
1687 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1688 // registered cell info, so return a NULL country instead.
1689 final long identity = Binder.clearCallingIdentity();
1690 try {
1691 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1692 if (TelephonyManager.NETWORK_TYPE_IWLAN
1693 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1694 return "";
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
1698 }
1699 return TelephonyManager.getTelephonyProperty(
1700 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1701 }
1702
1703 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001705 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001706 }
1707
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 mApp.enforceCallingOrSelfPermission(
1711 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 final Phone phone = getPhone(subId);
1713 if (phone != null) {
1714 phone.enableLocationUpdates();
1715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 }
1717
1718 @Override
1719 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001720 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001724 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 mApp.enforceCallingOrSelfPermission(
1726 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
1729 phone.disableLocationUpdates();
1730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 }
1732
1733 @Override
1734 @SuppressWarnings("unchecked")
1735 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001736 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1737
1738 // OP_COARSE_LOCATION controls both fine and coarse location.
1739 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1740 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1741 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743
1744 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1745 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1746 return null;
1747 }
Svetoslav64fad262015-04-14 14:35:21 -07001748
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001749 if (checkIfCallerIsSelfOrForegroundUser() ||
1750 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1752
1753 ArrayList<NeighboringCellInfo> cells = null;
1754
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001755 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 try {
1757 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001758 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001759 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001761 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763 return cells;
1764 } else {
1765 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1766 return null;
1767 }
1768 }
1769
1770
1771 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001772 public List<CellInfo> getAllCellInfo(String callingPackage) {
1773 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1774
1775 // OP_COARSE_LOCATION controls both fine and coarse location.
1776 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1777 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1778 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001781 if (checkIfCallerIsSelfOrForegroundUser() ||
1782 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001784 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001785 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1786 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001787 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1788 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001789 }
1790 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 } else {
1792 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1793 return null;
1794 }
1795 }
1796
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001799 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001800 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1801 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001805 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001806 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1807 return null;
1808 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001809 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001810 return phone == null ? null : phone.getImei();
1811 }
1812
1813 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001814 public String getMeidForSlot(int slotIndex, String callingPackage) {
1815 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1816 return null;
1817 }
1818 Phone phone = PhoneFactory.getPhone(slotIndex);
1819 return phone == null ? null : phone.getMeid();
1820 }
1821
1822 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001823 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001824 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1825 return null;
1826 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001827 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001828 return phone == null ? null : phone.getDeviceSvn();
1829 }
1830
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 //
1832 // Internal helper methods.
1833 //
1834
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001835 /**
1836 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1837 */
1838 private boolean checkCallerInteractAcrossUsersFull() {
1839 return mPhone.getContext().checkCallingOrSelfPermission(
1840 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1841 == PackageManager.PERMISSION_GRANTED;
1842 }
1843
Jake Hambye994d462014-02-03 13:10:13 -08001844 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 boolean ok;
1846
1847 boolean self = Binder.getCallingUid() == Process.myUid();
1848 if (!self) {
1849 // Get the caller's user id then clear the calling identity
1850 // which will be restored in the finally clause.
1851 int callingUser = UserHandle.getCallingUserId();
1852 long ident = Binder.clearCallingIdentity();
1853
1854 try {
1855 // With calling identity cleared the current user is the foreground user.
1856 int foregroundUser = ActivityManager.getCurrentUser();
1857 ok = (foregroundUser == callingUser);
1858 if (DBG_LOC) {
1859 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1860 + " callingUser=" + callingUser + " ok=" + ok);
1861 }
1862 } catch (Exception ex) {
1863 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1864 ok = false;
1865 } finally {
1866 Binder.restoreCallingIdentity(ident);
1867 }
1868 } else {
1869 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1870 ok = true;
1871 }
1872 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1873 return ok;
1874 }
1875
1876 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1878 *
1879 * @throws SecurityException if the caller does not have the required permission
1880 */
1881 private void enforceModifyPermission() {
1882 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1883 }
1884
1885 /**
Junda Liua2e36012014-07-09 18:30:01 -07001886 * Make sure either system app or the caller has carrier privilege.
1887 *
1888 * @throws SecurityException if the caller does not have the required permission/privilege
1889 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001890 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001891 int permission = mApp.checkCallingOrSelfPermission(
1892 android.Manifest.permission.MODIFY_PHONE_STATE);
1893 if (permission == PackageManager.PERMISSION_GRANTED) {
1894 return;
1895 }
1896
1897 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001898 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001899 }
1900
1901 /**
1902 * Make sure the caller has carrier privilege.
1903 *
1904 * @throws SecurityException if the caller does not have the required permission
1905 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001906 private void enforceCarrierPrivilege(int subId) {
1907 if (getCarrierPrivilegeStatus(subId) !=
1908 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001909 loge("No Carrier Privilege.");
1910 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001911 }
1912 }
1913
1914 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 * Make sure the caller has the CALL_PHONE permission.
1916 *
1917 * @throws SecurityException if the caller does not have the required permission
1918 */
1919 private void enforceCallPermission() {
1920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1921 }
1922
Stuart Scott8eef64f2015-04-08 15:13:54 -07001923 private void enforceConnectivityInternalPermission() {
1924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1926 "ConnectivityService");
1927 }
1928
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 private String createTelUrl(String number) {
1930 if (TextUtils.isEmpty(number)) {
1931 return null;
1932 }
1933
Jake Hambye994d462014-02-03 13:10:13 -08001934 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 }
1936
Ihab Awadf9e92732013-12-05 18:02:52 -08001937 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1939 }
1940
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001941 private static void logv(String msg) {
1942 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1943 }
1944
Ihab Awadf9e92732013-12-05 18:02:52 -08001945 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1947 }
1948
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001951 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952 }
1953
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001955 public int getActivePhoneTypeForSlot(int slotIndex) {
1956 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 if (phone == null) {
1958 return PhoneConstants.PHONE_TYPE_NONE;
1959 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001960 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
1964 /**
1965 * Returns the CDMA ERI icon index to display
1966 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001967 @Override
1968 public int getCdmaEriIconIndex(String callingPackage) {
1969 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001970 }
1971
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001973 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1974 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1975 return -1;
1976 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 final Phone phone = getPhone(subId);
1978 if (phone != null) {
1979 return phone.getCdmaEriIconIndex();
1980 } else {
1981 return -1;
1982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
1985 /**
1986 * Returns the CDMA ERI icon mode,
1987 * 0 - ON
1988 * 1 - FLASHING
1989 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001990 @Override
1991 public int getCdmaEriIconMode(String callingPackage) {
1992 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001993 }
1994
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001996 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1997 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1998 return -1;
1999 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 return phone.getCdmaEriIconMode();
2003 } else {
2004 return -1;
2005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 }
2007
2008 /**
2009 * Returns the CDMA ERI text,
2010 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002011 @Override
2012 public String getCdmaEriText(String callingPackage) {
2013 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002014 }
2015
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002017 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
2018 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
2019 return null;
2020 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 return phone.getCdmaEriText();
2024 } else {
2025 return null;
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
2029 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002030 * Returns the CDMA MDN.
2031 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002032 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002033 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002034 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002035 final Phone phone = getPhone(subId);
2036 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2037 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002038 } else {
2039 return null;
2040 }
2041 }
2042
2043 /**
2044 * Returns the CDMA MIN.
2045 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002048 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002049 final Phone phone = getPhone(subId);
2050 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2051 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002052 } else {
2053 return null;
2054 }
2055 }
2056
2057 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 * Returns true if CDMA provisioning needs to run.
2059 */
2060 public boolean needsOtaServiceProvisioning() {
2061 return mPhone.needsOtaServiceProvisioning();
2062 }
2063
2064 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002065 * Sets the voice mail number of a given subId.
2066 */
2067 @Override
2068 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002069 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002070 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2071 new Pair<String, String>(alphaTag, number), new Integer(subId));
2072 return success;
2073 }
2074
Ta-wei Yen87c49842016-05-13 21:19:52 -07002075 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002076 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2078 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2079 if (!TextUtils.equals(callingPackage, systemDialer)) {
2080 throw new SecurityException("caller must be system dialer");
2081 }
2082 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2083 if (phoneAccountHandle == null){
2084 return null;
2085 }
2086 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2087 }
2088
2089 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002090 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2092 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2093 return null;
2094 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002095 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2096 }
2097
2098 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002099 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2100 VisualVoicemailSmsFilterSettings settings) {
2101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002102 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002103 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2104 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002105 }
2106
2107 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002108 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002110 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002111 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002112 }
2113
2114 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002115 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2116 String callingPackage, int subId) {
2117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002118 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002119 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002120 }
2121
2122 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002123 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002124 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002125 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002126 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2127 }
2128
2129 @Override
2130 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2131 String number, int port, String text, PendingIntent sentIntent) {
2132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002133 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002134 enforceSendSmsPermission();
2135 // Make the calls as the phone process.
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2139 if (port == 0) {
2140 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2141 sentIntent, null, false);
2142 } else {
2143 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2144 smsManager.sendDataMessageWithSelfPermissions(number, null,
2145 (short) port, data, sentIntent, null);
2146 }
2147 } finally {
2148 Binder.restoreCallingIdentity(identity);
2149 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002150 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002151 /**
fionaxu0152e512016-11-14 13:36:14 -08002152 * Sets the voice activation state of a given subId.
2153 */
2154 @Override
2155 public void setVoiceActivationState(int subId, int activationState) {
2156 enforceModifyPermissionOrCarrierPrivilege(subId);
2157 final Phone phone = getPhone(subId);
2158 if (phone != null) {
2159 phone.setVoiceActivationState(activationState);
2160 } else {
2161 loge("setVoiceActivationState fails with invalid subId: " + subId);
2162 }
2163 }
2164
2165 /**
2166 * Sets the data activation state of a given subId.
2167 */
2168 @Override
2169 public void setDataActivationState(int subId, int activationState) {
2170 enforceModifyPermissionOrCarrierPrivilege(subId);
2171 final Phone phone = getPhone(subId);
2172 if (phone != null) {
2173 phone.setDataActivationState(activationState);
2174 } else {
2175 loge("setVoiceActivationState fails with invalid subId: " + subId);
2176 }
2177 }
2178
2179 /**
2180 * Returns the voice activation state of a given subId.
2181 */
2182 @Override
2183 public int getVoiceActivationState(int subId, String callingPackage) {
2184 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2185 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2186 }
2187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 return phone.getVoiceActivationState();
2190 } else {
2191 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2192 }
2193 }
2194
2195 /**
2196 * Returns the data activation state of a given subId.
2197 */
2198 @Override
2199 public int getDataActivationState(int subId, String callingPackage) {
2200 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2201 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2202 }
2203 final Phone phone = getPhone(subId);
2204 if (phone != null) {
2205 return phone.getDataActivationState();
2206 } else {
2207 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2208 }
2209 }
2210
2211 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 * Returns the unread count of voicemails
2213 */
2214 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002215 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
2217
2218 /**
2219 * Returns the unread count of voicemails for a subId
2220 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002222 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 final Phone phone = getPhone(subId);
2224 if (phone != null) {
2225 return phone.getVoiceMessageCount();
2226 } else {
2227 return 0;
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
2231 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002232 * returns true, if the device is in a state where both voice and data
2233 * are supported simultaneously. This can change based on location or network condition.
2234 */
2235 @Override
2236 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2237 final Phone phone = getPhone(subId);
2238 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2239 }
2240
2241 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002242 * Send the dialer code if called from the current default dialer or the caller has
2243 * carrier privilege.
2244 * @param inputCode The dialer code to send
2245 */
2246 @Override
2247 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2249 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2250 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2251 enforceCarrierPrivilege(getDefaultSubscription());
2252 }
2253 mPhone.sendDialerSpecialCode(inputCode);
2254 }
2255
2256 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002257 * Returns the data network type.
2258 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 *
2260 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2261 */
2262 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002263 public int getNetworkType() {
2264 final Phone phone = getPhone(getDefaultSubscription());
2265 if (phone != null) {
2266 return phone.getServiceState().getDataNetworkType();
2267 } else {
2268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2269 }
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
2272 /**
2273 * Returns the network type for a subId
2274 */
2275 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002276 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2277 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2278 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2279 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002280
Sanket Padawe356d7632015-06-22 14:03:32 -07002281 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 return phone.getServiceState().getDataNetworkType();
2284 } else {
2285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
2289 /**
2290 * Returns the data network type
2291 */
2292 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 public int getDataNetworkType(String callingPackage) {
2294 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002295 }
2296
2297 /**
2298 * Returns the data network type for a subId
2299 */
2300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2302 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
2307 if (phone != null) {
2308 return phone.getServiceState().getDataNetworkType();
2309 } else {
2310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
Wink Saville36469e72014-06-11 15:17:00 -07002315 * Returns the Voice network type for a subId
2316 */
2317 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002318 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2319 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2320 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2321 }
2322
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 final Phone phone = getPhone(subId);
2324 if (phone != null) {
2325 return phone.getServiceState().getVoiceNetworkType();
2326 } else {
2327 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
2330
2331 /**
2332 * @return true if a ICC card is present
2333 */
2334 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002335 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002336 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2337 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
2340 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002341 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002344 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2345 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002346 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002347 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002348 } else {
2349 return false;
2350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
2353 /**
2354 * Return if the current radio is LTE on CDMA. This
2355 * is a tri-state return value as for a period of time
2356 * the mode may be unknown.
2357 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002358 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002360 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002362 @Override
2363 public int getLteOnCdmaMode(String callingPackage) {
2364 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002368 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2369 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2370 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2371 }
2372
Sanket Padawe356d7632015-06-22 14:03:32 -07002373 final Phone phone = getPhone(subId);
2374 if (phone == null) {
2375 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2376 } else {
2377 return phone.getLteOnCdmaMode();
2378 }
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
2381 public void setPhone(Phone phone) {
2382 mPhone = phone;
2383 }
2384
2385 /**
2386 * {@hide}
2387 * Returns Default subId, 0 in the case of single standby.
2388 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002389 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002390 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002391 }
2392
Shishir Agrawala9f32182016-04-12 12:00:16 -07002393 private int getSlotForDefaultSubscription() {
2394 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2395 }
2396
Wink Savilleb564aae2014-10-23 10:18:09 -07002397 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002398 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002400
2401 /**
2402 * @see android.telephony.TelephonyManager.WifiCallingChoices
2403 */
2404 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002405 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2406 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002407 }
2408
2409 /**
2410 * @see android.telephony.TelephonyManager.WifiCallingChoices
2411 */
2412 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002413 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2414 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2415 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002416 }
2417
Sailesh Nepald1e68152013-12-12 19:08:02 -08002418 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002419 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002420 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002421 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002422
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002424 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2425 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002426 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427
Derek Tan740e1672017-06-27 14:56:27 -07002428 if (TextUtils.equals(ISDR_AID, aid)) {
2429 // Only allows LPA to open logical channel to ISD-R.
2430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2431 ComponentInfo bestComponent =
2432 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2433 if (bestComponent == null
2434 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2435 loge("The calling package is not allowed to access ISD-R.");
2436 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2437 }
2438 }
2439
2440 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002441 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002442 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002443 if (DBG) log("iccOpenLogicalChannel: " + response);
2444 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002445 }
2446
2447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 public boolean iccCloseLogicalChannel(int subId, int channel) {
2449 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002450
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002452 if (channel < 0) {
2453 return false;
2454 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002456 if (DBG) log("iccCloseLogicalChannel: " + success);
2457 return success;
2458 }
2459
2460 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002461 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002462 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002463 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002464
2465 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2467 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002468 " data=" + data);
2469 }
2470
2471 if (channel < 0) {
2472 return "";
2473 }
2474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002477 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2478
Shishir Agrawal566b7612013-10-28 14:41:00 -07002479 // Append the returned status code to the end of the response payload.
2480 String s = Integer.toHexString(
2481 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002482 if (response.payload != null) {
2483 s = IccUtils.bytesToHexString(response.payload) + s;
2484 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002485 return s;
2486 }
Jake Hambye994d462014-02-03 13:10:13 -08002487
Evan Charltonc66da362014-05-16 14:06:40 -07002488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002489 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002490 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002491 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002492
2493 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002494 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2495 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002496 }
2497
2498 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002499 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002500 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2501
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002502 // Append the returned status code to the end of the response payload.
2503 String s = Integer.toHexString(
2504 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002505 if (response.payload != null) {
2506 s = IccUtils.bytesToHexString(response.payload) + s;
2507 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002508 return s;
2509 }
2510
2511 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002512 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002513 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515
2516 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002517 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002518 p1 + " " + p2 + " " + p3 + ":" + filePath);
2519 }
2520
2521 IccIoResult response =
2522 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2524 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002525
2526 if (DBG) {
2527 log("Exchange SIM_IO [R]" + response);
2528 }
2529
2530 byte[] result = null;
2531 int length = 2;
2532 if (response.payload != null) {
2533 length = 2 + response.payload.length;
2534 result = new byte[length];
2535 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2536 } else {
2537 result = new byte[length];
2538 }
2539
2540 result[length - 1] = (byte) response.sw2;
2541 result[length - 2] = (byte) response.sw1;
2542 return result;
2543 }
2544
Nathan Haroldb3014052017-01-25 15:57:32 -08002545 /**
2546 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2547 * on a particular subscription
2548 */
2549 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002550 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2551 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002552 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2553 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2554 return null;
2555 }
2556 Object response = sendRequest(
2557 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2558 if (response instanceof String[]) {
2559 return (String[]) response;
2560 }
2561 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2562 return null;
2563 }
2564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002565 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002566 public String sendEnvelopeWithStatus(int subId, String content) {
2567 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002568
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002569 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002570 if (response.payload == null) {
2571 return "";
2572 }
2573
2574 // Append the returned status code to the end of the response payload.
2575 String s = Integer.toHexString(
2576 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2577 s = IccUtils.bytesToHexString(response.payload) + s;
2578 return s;
2579 }
2580
Jake Hambye994d462014-02-03 13:10:13 -08002581 /**
2582 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2583 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2584 *
2585 * @param itemID the ID of the item to read
2586 * @return the NV item as a String, or null on error.
2587 */
2588 @Override
2589 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002590 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvReadItem: item " + itemID);
2592 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2593 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2594 return value;
2595 }
2596
2597 /**
2598 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2599 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2600 *
2601 * @param itemID the ID of the item to read
2602 * @param itemValue the value to write, as a String
2603 * @return true on success; false on any failure
2604 */
2605 @Override
2606 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002607 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002608 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2609 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2610 new Pair<Integer, String>(itemID, itemValue));
2611 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2612 return success;
2613 }
2614
2615 /**
2616 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2617 * Used for device configuration by some CDMA operators.
2618 *
2619 * @param preferredRoamingList byte array containing the new PRL
2620 * @return true on success; false on any failure
2621 */
2622 @Override
2623 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002624 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002625 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2626 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2627 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2628 return success;
2629 }
2630
2631 /**
2632 * Perform the specified type of NV config reset.
2633 * Used for device configuration by some CDMA operators.
2634 *
2635 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2636 * @return true on success; false on any failure
2637 */
2638 @Override
2639 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002640 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002641 if (DBG) log("nvResetConfig: type " + resetType);
2642 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2643 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2644 return success;
2645 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002646
2647 /**
Wink Saville36469e72014-06-11 15:17:00 -07002648 * {@hide}
2649 * Returns Default sim, 0 in the case of single standby.
2650 */
2651 public int getDefaultSim() {
2652 //TODO Need to get it from Telephony Devcontroller
2653 return 0;
2654 }
2655
Svet Ganovb320e182015-04-16 12:30:10 -07002656 public String[] getPcscfAddress(String apnType, String callingPackage) {
2657 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2658 return new String[0];
2659 }
2660
2661
ram87fca6f2014-07-18 18:58:44 +05302662 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002663 }
2664
Brad Ebinger51f743a2017-01-23 13:50:20 -08002665 /**
2666 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2667 * feature or {@link null} if the service is not available. If an ImsServiceController is
2668 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2669 * feature updates.
2670 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002671 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002672 IImsServiceFeatureListener callback) {
2673 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002674 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002675 callback);
2676 }
2677
Wink Saville36469e72014-06-11 15:17:00 -07002678 public void setImsRegistrationState(boolean registered) {
2679 enforceModifyPermission();
2680 mPhone.setImsRegistrationState(registered);
2681 }
2682
2683 /**
Stuart Scott54788802015-03-30 13:18:01 -07002684 * Set the network selection mode to automatic.
2685 *
2686 */
2687 @Override
2688 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002689 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002690 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2691 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2692 }
2693
2694 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002695 * Set the network selection mode to manual with the selected carrier.
2696 */
2697 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002698 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2699 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002700 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002701 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002702 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2703 persistSelection);
2704 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002705 }
2706
2707 /**
2708 * Scans for available networks.
2709 */
2710 @Override
2711 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002712 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002713 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2714 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2715 CMD_PERFORM_NETWORK_SCAN, null, subId);
2716 return result;
2717 }
2718
2719 /**
yinxub1bed742017-04-17 11:45:04 -07002720 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002721 *
yinxub1bed742017-04-17 11:45:04 -07002722 * @param subId id of the subscription
2723 * @param request contains the radio access networks with bands/channels to scan
2724 * @param messenger callback messenger for scan results or errors
2725 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002726 * @return the id of the requested scan which can be used to stop the scan.
2727 */
2728 @Override
2729 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2730 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002731 enforceModifyPermissionOrCarrierPrivilege(subId);
2732 return mNetworkScanRequestTracker.startNetworkScan(
2733 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002734 }
2735
2736 /**
2737 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002738 *
2739 * @param subId id of the subscription
2740 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002741 */
2742 @Override
2743 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002744 enforceModifyPermissionOrCarrierPrivilege(subId);
2745 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002746 }
2747
2748 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002749 * Get the calculated preferred network type.
2750 * Used for debugging incorrect network type.
2751 *
2752 * @return the preferred network type, defined in RILConstants.java.
2753 */
2754 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002755 public int getCalculatedPreferredNetworkType(String callingPackage) {
2756 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2757 return RILConstants.PREFERRED_NETWORK_MODE;
2758 }
2759
Amit Mahajan43330e02014-11-18 11:54:45 -08002760 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002761 }
2762
2763 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002764 * Get the preferred network type.
2765 * Used for device configuration by some CDMA operators.
2766 *
2767 * @return the preferred network type, defined in RILConstants.java.
2768 */
2769 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002770 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002771 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002772 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002773 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002774 int networkType = (result != null ? result[0] : -1);
2775 if (DBG) log("getPreferredNetworkType: " + networkType);
2776 return networkType;
2777 }
2778
2779 /**
2780 * Set the preferred network type.
2781 * Used for device configuration by some CDMA operators.
2782 *
2783 * @param networkType the preferred network type, defined in RILConstants.java.
2784 * @return true on success; false on any failure.
2785 */
2786 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002787 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002788 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002789 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2790 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002791 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002792 if (success) {
2793 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002794 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002795 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002796 return success;
2797 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002798
2799 /**
Junda Liu475951f2014-11-07 16:45:03 -08002800 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2801 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2802 * tethering.
2803 *
2804 * @return 0: Not required. 1: required. 2: Not set.
2805 * @hide
2806 */
2807 @Override
2808 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002809 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002810 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2811 Settings.Global.TETHER_DUN_REQUIRED, 2);
2812 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2813 // config_tether_apndata.
2814 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2815 dunRequired = 1;
2816 }
2817 return dunRequired;
2818 }
2819
2820 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002821 * Set mobile data enabled
2822 * Used by the user through settings etc to turn on/off mobile data
2823 *
2824 * @param enable {@code true} turn turn data on, else {@code false}
2825 */
2826 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002827 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002828 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002829 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002830 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002831 Phone phone = PhoneFactory.getPhone(phoneId);
2832 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002833 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002834 phone.setDataEnabled(enable);
2835 } else {
2836 loge("setDataEnabled: no phone for subId=" + subId);
2837 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002838 }
2839
2840 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002841 * Get whether mobile data is enabled.
2842 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002843 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002844 *
2845 * @return {@code true} if data is enabled else {@code false}
2846 */
2847 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002848 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002849 try {
2850 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2851 null);
2852 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002853 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002854 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002855 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002856 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002857 Phone phone = PhoneFactory.getPhone(phoneId);
2858 if (phone != null) {
2859 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002860 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002861 return retVal;
2862 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002863 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002864 return false;
2865 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002866 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002867
2868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002869 public int getCarrierPrivilegeStatus(int subId) {
2870 final Phone phone = getPhone(subId);
2871 if (phone == null) {
2872 loge("getCarrierPrivilegeStatus: Invalid subId");
2873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2874 }
2875 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002876 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002877 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2879 }
2880 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002881 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002882 }
Junda Liu29340342014-07-10 15:23:27 -07002883
2884 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002885 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002886 if (TextUtils.isEmpty(pkgName))
2887 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002888 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002889 if (card == null) {
2890 loge("checkCarrierPrivilegesForPackage: No UICC");
2891 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2892 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002893 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2894 }
2895
2896 @Override
2897 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002898 if (TextUtils.isEmpty(pkgName))
2899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002900 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2901 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2902 UiccCard card = UiccController.getInstance().getUiccCard(i);
2903 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002904 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002905 continue;
2906 }
2907
2908 result = card.getCarrierPrivilegeStatus(
2909 mPhone.getContext().getPackageManager(), pkgName);
2910 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2911 break;
2912 }
2913 }
2914
2915 return result;
Junda Liu29340342014-07-10 15:23:27 -07002916 }
Derek Tan89e89d42014-07-08 17:00:10 -07002917
2918 @Override
Junda Liue64de782015-04-16 17:19:16 -07002919 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2920 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2921 loge("phoneId " + phoneId + " is not valid.");
2922 return null;
2923 }
2924 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002925 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002926 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002927 return null ;
2928 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002929 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002930 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002931 }
2932
Amith Yamasani6e118872016-02-19 12:53:51 -08002933 @Override
2934 public List<String> getPackagesWithCarrierPrivileges() {
2935 PackageManager pm = mPhone.getContext().getPackageManager();
2936 List<String> privilegedPackages = new ArrayList<>();
2937 List<PackageInfo> packages = null;
2938 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2939 UiccCard card = UiccController.getInstance().getUiccCard(i);
2940 if (card == null) {
2941 // No UICC in that slot.
2942 continue;
2943 }
2944 if (card.hasCarrierPrivilegeRules()) {
2945 if (packages == null) {
2946 // Only check packages in user 0 for now
2947 packages = pm.getInstalledPackagesAsUser(
2948 PackageManager.MATCH_DISABLED_COMPONENTS
2949 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2950 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2951 }
2952 for (int p = packages.size() - 1; p >= 0; p--) {
2953 PackageInfo pkgInfo = packages.get(p);
2954 if (pkgInfo != null && pkgInfo.packageName != null
2955 && card.getCarrierPrivilegeStatus(pkgInfo)
2956 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2957 privilegedPackages.add(pkgInfo.packageName);
2958 }
2959 }
2960 }
2961 }
2962 return privilegedPackages;
2963 }
2964
Wink Savilleb564aae2014-10-23 10:18:09 -07002965 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002966 final Phone phone = getPhone(subId);
2967 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002968 if (card == null) {
2969 loge("getIccId: No UICC");
2970 return null;
2971 }
2972 String iccId = card.getIccId();
2973 if (TextUtils.isEmpty(iccId)) {
2974 loge("getIccId: ICC ID is null or empty.");
2975 return null;
2976 }
2977 return iccId;
2978 }
2979
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002980 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002981 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2982 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002983 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002984
Jeff Sharkey85190e62014-12-05 09:40:12 -08002985 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002986 final Phone phone = getPhone(subId);
2987 if (phone == null) {
2988 return false;
2989 }
2990 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002991
2992 if (DBG_MERGE) {
2993 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2994 + subscriberId + " to " + number);
2995 }
2996
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002997 if (TextUtils.isEmpty(iccId)) {
2998 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002999 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003000
Jeff Sharkey85190e62014-12-05 09:40:12 -08003001 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3002
3003 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003004 if (alphaTag == null) {
3005 editor.remove(alphaTagPrefKey);
3006 } else {
3007 editor.putString(alphaTagPrefKey, alphaTag);
3008 }
3009
Jeff Sharkey85190e62014-12-05 09:40:12 -08003010 // Record both the line number and IMSI for this ICCID, since we need to
3011 // track all merged IMSIs based on line number
3012 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3013 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003014 if (number == null) {
3015 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003016 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003017 } else {
3018 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003019 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003020 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003021
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003022 editor.commit();
3023 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003024 }
3025
3026 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003027 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003028 // This is open to apps with WRITE_SMS.
3029 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003030 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003031 return null;
3032 }
Derek Tan97ebb422014-09-05 16:55:38 -07003033
3034 String iccId = getIccId(subId);
3035 if (iccId != null) {
3036 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003037 if (DBG_MERGE) {
3038 log("getLine1NumberForDisplay returning " +
3039 mTelephonySharedPreferences.getString(numberPrefKey, null));
3040 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003041 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003042 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003043 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003044 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003045 }
3046
3047 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003048 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3049 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3050 return null;
3051 }
Derek Tan97ebb422014-09-05 16:55:38 -07003052
3053 String iccId = getIccId(subId);
3054 if (iccId != null) {
3055 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003056 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003057 }
Derek Tan97ebb422014-09-05 16:55:38 -07003058 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003059 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003060
3061 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003062 public String[] getMergedSubscriberIds(String callingPackage) {
3063 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3064 return null;
3065 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003066 final Context context = mPhone.getContext();
3067 final TelephonyManager tele = TelephonyManager.from(context);
3068 final SubscriptionManager sub = SubscriptionManager.from(context);
3069
3070 // Figure out what subscribers are currently active
3071 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003072 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3073 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 final int[] subIds = sub.getActiveSubscriptionIdList();
3077 for (int subId : subIds) {
3078 activeSubscriberIds.add(tele.getSubscriberId(subId));
3079 }
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003082 }
3083
3084 // First pass, find a number override for an active subscriber
3085 String mergeNumber = null;
3086 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3087 for (String key : prefs.keySet()) {
3088 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3089 final String subscriberId = (String) prefs.get(key);
3090 if (activeSubscriberIds.contains(subscriberId)) {
3091 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3092 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3093 mergeNumber = (String) prefs.get(numberKey);
3094 if (DBG_MERGE) {
3095 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3096 + " for active subscriber " + subscriberId);
3097 }
3098 if (!TextUtils.isEmpty(mergeNumber)) {
3099 break;
3100 }
3101 }
3102 }
3103 }
3104
3105 // Shortcut when no active merged subscribers
3106 if (TextUtils.isEmpty(mergeNumber)) {
3107 return null;
3108 }
3109
3110 // Second pass, find all subscribers under that line override
3111 final ArraySet<String> result = new ArraySet<>();
3112 for (String key : prefs.keySet()) {
3113 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3114 final String number = (String) prefs.get(key);
3115 if (mergeNumber.equals(number)) {
3116 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3117 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3118 final String subscriberId = (String) prefs.get(subscriberKey);
3119 if (!TextUtils.isEmpty(subscriberId)) {
3120 result.add(subscriberId);
3121 }
3122 }
3123 }
3124 }
3125
3126 final String[] resultArray = result.toArray(new String[result.size()]);
3127 Arrays.sort(resultArray);
3128 if (DBG_MERGE) {
3129 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3130 }
3131 return resultArray;
3132 }
3133
3134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003135 public boolean setOperatorBrandOverride(int subId, String brand) {
3136 enforceCarrierPrivilege(subId);
3137 final Phone phone = getPhone(subId);
3138 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003139 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003140
3141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003142 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003143 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3144 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003145 enforceCarrierPrivilege(subId);
3146 final Phone phone = getPhone(subId);
3147 if (phone == null) {
3148 return false;
3149 }
3150 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003151 cdmaNonRoamingList);
3152 }
3153
3154 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003155 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003156 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3157 enforceModifyPermission();
3158
3159 int returnValue = 0;
3160 try {
3161 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3162 if(result.exception == null) {
3163 if (result.result != null) {
3164 byte[] responseData = (byte[])(result.result);
3165 if(responseData.length > oemResp.length) {
3166 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3167 responseData.length + "bytes. Buffer Size is " +
3168 oemResp.length + "bytes.");
3169 }
3170 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3171 returnValue = responseData.length;
3172 }
3173 } else {
3174 CommandException ex = (CommandException) result.exception;
3175 returnValue = ex.getCommandError().ordinal();
3176 if(returnValue > 0) returnValue *= -1;
3177 }
3178 } catch (RuntimeException e) {
3179 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3180 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3181 if(returnValue > 0) returnValue *= -1;
3182 }
3183
3184 return returnValue;
3185 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003186
3187 @Override
3188 public void setRadioCapability(RadioAccessFamily[] rafs) {
3189 try {
3190 ProxyController.getInstance().setRadioCapability(rafs);
3191 } catch (RuntimeException e) {
3192 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3193 }
3194 }
3195
3196 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003197 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3198 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3199 return RadioAccessFamily.RAF_UNKNOWN;
3200 }
3201
Wink Saville5d475dd2014-10-17 15:00:58 -07003202 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3203 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003204
3205 @Override
3206 public void enableVideoCalling(boolean enable) {
3207 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003208 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003209 }
3210
3211 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003212 public boolean isVideoCallingEnabled(String callingPackage) {
3213 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3214 return false;
3215 }
3216
Andrew Lee77527ac2014-10-21 16:57:39 -07003217 // Check the user preference and the system-level IMS setting. Even if the user has
3218 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3219 // In the long run, we may instead need to check if there exists a connection service
3220 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003221 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3222 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003223 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003224 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003225
Andrew Leea1239f22015-03-02 17:44:07 -08003226 @Override
3227 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003228 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003229 }
3230
3231 @Override
3232 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003233 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003234 }
3235
Andrew Lee9431b832015-03-09 18:46:45 -07003236 @Override
3237 public boolean isTtyModeSupported() {
3238 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3239 TelephonyManager telephonyManager =
3240 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003241 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003242 }
3243
3244 @Override
3245 public boolean isHearingAidCompatibilitySupported() {
3246 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3247 }
3248
Sanket Padawe7310cc72015-01-14 09:53:20 -08003249 /**
3250 * Returns the unique device ID of phone, for example, the IMEI for
3251 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3252 *
3253 * <p>Requires Permission:
3254 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3255 */
3256 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003257 public String getDeviceId(String callingPackage) {
3258 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3259 return null;
3260 }
3261
Sanket Padawe7310cc72015-01-14 09:53:20 -08003262 final Phone phone = PhoneFactory.getPhone(0);
3263 if (phone != null) {
3264 return phone.getDeviceId();
3265 } else {
3266 return null;
3267 }
3268 }
3269
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003270 /*
3271 * {@hide}
3272 * Returns the IMS Registration Status
3273 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003274 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003275 public boolean isImsRegistered() {
3276 return mPhone.isImsRegistered();
3277 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003278
Ping Sun014fe8e2016-03-02 19:16:45 +08003279 /**
3280 * {@hide}
3281 * Returns the IMS Registration Status on a particular subid
3282 *
3283 * @param subId
3284 */
3285 public boolean isImsRegisteredForSubscriber(int subId) {
3286 Phone phone = getPhone(subId);
3287 if (phone != null) {
3288 return phone.isImsRegistered();
3289 } else {
3290 return false;
3291 }
3292 }
3293
Santos Cordon7a1885b2015-02-03 11:15:19 -08003294 @Override
3295 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3296 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3297 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003298
Nathan Haroldc55097a2015-03-11 18:14:50 -07003299 /*
3300 * {@hide}
3301 * Returns the IMS Registration Status
3302 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003303 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003304 return mPhone.isWifiCallingEnabled();
3305 }
3306
3307 /*
3308 * {@hide}
3309 * Returns the IMS Registration Status
3310 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003311 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003312 return mPhone.isVolteEnabled();
3313 }
Svet Ganovb320e182015-04-16 12:30:10 -07003314
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003315 /*
3316 * {@hide} Returns the IMS Registration Status
3317 */
3318 public boolean isVideoTelephonyAvailable() {
3319 return mPhone.isVideoEnabled();
3320 }
3321
Svet Ganovb320e182015-04-16 12:30:10 -07003322 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003323 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003324 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003325 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3326
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003327 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003328 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003329 } catch (SecurityException e) {
3330 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3331 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003332 }
Svet Ganovb320e182015-04-16 12:30:10 -07003333
3334 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3335 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3336 return false;
3337 }
3338
3339 return true;
3340 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003341
Makoto Onukifee69342015-06-29 14:44:50 -07003342 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003343 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003344 */
3345 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003346 // Default SMS app can always read it.
3347 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3348 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3349 return true;
3350 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003351
Makoto Onukie4072d12015-08-03 15:12:23 -07003352 try {
3353 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003354 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003355 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003356 // Can be read with READ_SMS too.
3357 try {
3358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3359 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3360 if (opCode != AppOpsManager.OP_NONE) {
3361 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3362 == AppOpsManager.MODE_ALLOWED;
3363 } else {
3364 return true;
3365 }
3366 } catch (SecurityException readSmsSecurityException) {
3367 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003368 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003369 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003370 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003371 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003372 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003373 if (opCode != AppOpsManager.OP_NONE) {
3374 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3375 == AppOpsManager.MODE_ALLOWED;
3376 } else {
3377 return true;
3378 }
3379 } catch (SecurityException readPhoneNumberSecurityException) {
3380 }
3381
3382 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3383 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3384 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003385 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003386 }
3387
Stuart Scott8eef64f2015-04-08 15:13:54 -07003388 @Override
3389 public void factoryReset(int subId) {
3390 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003391 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3392 return;
3393 }
3394
Svet Ganovcc087f82015-05-12 20:35:54 -07003395 final long identity = Binder.clearCallingIdentity();
3396 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003397 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3398 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003399 // Enable data
3400 setDataEnabled(subId, true);
3401 // Set network selection mode to automatic
3402 setNetworkSelectionModeAutomatic(subId);
3403 // Set preferred mobile network type to the best available
3404 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3405 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003406 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003407 }
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003410 }
3411 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003412
3413 @Override
3414 public String getLocaleFromDefaultSim() {
3415 // We query all subscriptions instead of just the active ones, because
3416 // this might be called early on in the provisioning flow when the
3417 // subscriptions potentially aren't active yet.
3418 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3419 if (slist == null || slist.isEmpty()) {
3420 return null;
3421 }
3422
3423 // This function may be called very early, say, from the setup wizard, at
3424 // which point we won't have a default subscription set. If that's the case
3425 // we just choose the first, which will be valid in "most cases".
3426 final int defaultSubId = getDefaultSubscription();
3427 SubscriptionInfo info = null;
3428 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3429 info = slist.get(0);
3430 } else {
3431 for (SubscriptionInfo item : slist) {
3432 if (item.getSubscriptionId() == defaultSubId) {
3433 info = item;
3434 break;
3435 }
3436 }
3437
3438 if (info == null) {
3439 return null;
3440 }
3441 }
3442
3443 // Try and fetch the locale from the carrier properties or from the SIM language
3444 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003445 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003446 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003447 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003448 if (defaultPhone != null) {
3449 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3450 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003451 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003452 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3453 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003454 } else {
3455 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003456 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003457 }
3458 }
3459
Narayan Kamath011676f2015-07-29 12:04:08 +01003460 // The SIM language preferences only store a language (e.g. fr = French), not an
3461 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3462 // the SIM and carrier preferences does not include a country we add the country
3463 // determined from the SIM MCC to provide an exact locale.
3464 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003465 if (mccLocale != null) {
3466 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3467 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003468 }
3469
Tony Hill183b2de2015-06-24 14:53:58 +01003470 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003471 return null;
3472 }
3473
3474 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 return mSubscriptionController.getAllSubInfoList(
3478 mPhone.getContext().getOpPackageName());
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
3482 }
3483
3484 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 return mSubscriptionController.getActiveSubscriptionInfoList(
3488 mPhone.getContext().getOpPackageName());
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
3491 }
3492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003493
3494 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003495 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3496 * representing the state of the modem.
3497 *
3498 * NOTE: This clears the modem state, so there should only every be one caller.
3499 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003500 */
3501 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003502 public void requestModemActivityInfo(ResultReceiver result) {
3503 enforceModifyPermission();
3504
3505 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3506 Bundle bundle = new Bundle();
3507 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3508 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003509 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003510
3511 /**
3512 * {@hide}
3513 * Returns the service state information on specified subscription.
3514 */
3515 @Override
3516 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3517
3518 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3519 return null;
3520 }
3521
3522 final Phone phone = getPhone(subId);
3523 if (phone == null) {
3524 return null;
3525 }
3526
3527 return phone.getServiceState();
3528 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003529
3530 /**
3531 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3532 *
3533 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3534 * voicemail ringtone.
3535 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3536 * PhoneAccount.
3537 */
3538 @Override
3539 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003540 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003541 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003542 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003543 }
3544
fionaxu7ed723d2017-05-30 18:58:54 -07003545 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003546 }
3547
3548 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003549 * Sets the per-account voicemail ringtone.
3550 *
3551 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3552 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3553 *
3554 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3555 * voicemail ringtone.
3556 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3557 * PhoneAccount.
3558 */
3559 @Override
3560 public void setVoicemailRingtoneUri(String callingPackage,
3561 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3563 if (!TextUtils.equals(callingPackage,
3564 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3565 enforceModifyPermissionOrCarrierPrivilege(
3566 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3567 }
3568 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3569 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003570 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003571 }
fionaxu7ed723d2017-05-30 18:58:54 -07003572 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003573 }
3574
3575 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003576 * Returns whether vibration is set for voicemail notification in Phone settings.
3577 *
3578 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3579 * voicemail vibration setting.
3580 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3581 */
3582 @Override
3583 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003584 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003585 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003586 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003587 }
3588
fionaxu7ed723d2017-05-30 18:58:54 -07003589 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003590 }
3591
Youhan Wange64578a2016-05-02 15:32:42 -07003592 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003593 * Sets the per-account voicemail vibration.
3594 *
3595 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3596 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3597 *
3598 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3599 * voicemail vibration setting.
3600 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3601 * specific PhoneAccount.
3602 */
3603 @Override
3604 public void setVoicemailVibrationEnabled(String callingPackage,
3605 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3606 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3607 if (!TextUtils.equals(callingPackage,
3608 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3609 enforceModifyPermissionOrCarrierPrivilege(
3610 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3611 }
3612
3613 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3614 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003615 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003616 }
fionaxu7ed723d2017-05-30 18:58:54 -07003617 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003618 }
3619
3620 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003621 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3622 *
3623 * @throws SecurityException if the caller does not have the required permission
3624 */
3625 private void enforceReadPrivilegedPermission() {
3626 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3627 null);
3628 }
3629
3630 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003631 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3632 * permission.
3633 *
3634 * @throws SecurityException if the caller does not have the required permission
3635 */
3636 private void enforceSendSmsPermission() {
3637 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3638 }
3639
3640 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003641 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003642 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003643 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003644 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003645 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003646 ComponentName componentName =
3647 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3648 if(componentName == null) {
3649 throw new SecurityException("Caller not current active visual voicemail package[null]");
3650 }
3651 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003652 if (!callingPackage.equals(vvmPackage)) {
3653 throw new SecurityException("Caller not current active visual voicemail package[" +
3654 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003655 }
3656 }
3657
3658 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003659 * Return the application ID for the app type.
3660 *
3661 * @param subId the subscription ID that this request applies to.
3662 * @param appType the uicc app type.
3663 * @return Application ID for specificied app type, or null if no uicc.
3664 */
3665 @Override
3666 public String getAidForAppType(int subId, int appType) {
3667 enforceReadPrivilegedPermission();
3668 Phone phone = getPhone(subId);
3669 if (phone == null) {
3670 return null;
3671 }
3672 String aid = null;
3673 try {
3674 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3675 .getApplicationByType(appType).getAid();
3676 } catch (Exception e) {
3677 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3678 }
3679 return aid;
3680 }
3681
Youhan Wang4001d252016-05-11 10:29:41 -07003682 /**
3683 * Return the Electronic Serial Number.
3684 *
3685 * @param subId the subscription ID that this request applies to.
3686 * @return ESN or null if error.
3687 */
3688 @Override
3689 public String getEsn(int subId) {
3690 enforceReadPrivilegedPermission();
3691 Phone phone = getPhone(subId);
3692 if (phone == null) {
3693 return null;
3694 }
3695 String esn = null;
3696 try {
3697 esn = phone.getEsn();
3698 } catch (Exception e) {
3699 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3700 }
3701 return esn;
3702 }
3703
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003704 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003705 * Return the Preferred Roaming List Version.
3706 *
3707 * @param subId the subscription ID that this request applies to.
3708 * @return PRLVersion or null if error.
3709 */
3710 @Override
3711 public String getCdmaPrlVersion(int subId) {
3712 enforceReadPrivilegedPermission();
3713 Phone phone = getPhone(subId);
3714 if (phone == null) {
3715 return null;
3716 }
3717 String cdmaPrlVersion = null;
3718 try {
3719 cdmaPrlVersion = phone.getCdmaPrlVersion();
3720 } catch (Exception e) {
3721 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3722 }
3723 return cdmaPrlVersion;
3724 }
3725
3726 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003727 * Get snapshot of Telephony histograms
3728 * @return List of Telephony histograms
3729 * @hide
3730 */
3731 @Override
3732 public List<TelephonyHistogram> getTelephonyHistograms() {
3733 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3734 return RIL.getTelephonyRILTimingHistograms();
3735 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003736
3737 /**
3738 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003739 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003740 * Require system privileges. In the future we may add this to carrier APIs.
3741 *
3742 * @return The number of carriers set successfully, should match length of carriers
3743 */
3744 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003745 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003746 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003747
Meng Wang9b7c4e92017-02-17 11:41:27 -08003748 if (carriers == null) {
3749 throw new NullPointerException("carriers cannot be null");
3750 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003751
3752 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003753 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3754 return retVal[0];
3755 }
3756
3757 /**
3758 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003759 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003760 * Require system privileges. In the future we may add this to carrier APIs.
3761 *
3762 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3763 * means all carriers are allowed.
3764 */
3765 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003766 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003767 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003768 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003769 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3770 }
3771
fionaxu59545b42016-05-25 15:53:37 -07003772 /**
3773 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3774 * @param subId the subscription ID that this action applies to.
3775 * @param enabled control enable or disable metered apns.
3776 * {@hide}
3777 */
3778 @Override
3779 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3780 enforceModifyPermission();
3781 final Phone phone = getPhone(subId);
3782 if (phone == null) {
3783 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3784 return;
3785 }
3786 try {
3787 phone.carrierActionSetMeteredApnsEnabled(enabled);
3788 } catch (Exception e) {
3789 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3790 }
3791 }
3792
3793 /**
3794 * Action set from carrier signalling broadcast receivers to enable/disable radio
3795 * @param subId the subscription ID that this action applies to.
3796 * @param enabled control enable or disable radio.
3797 * {@hide}
3798 */
3799 @Override
3800 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3801 enforceModifyPermission();
3802 final Phone phone = getPhone(subId);
3803 if (phone == null) {
3804 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3805 return;
3806 }
3807 try {
3808 phone.carrierActionSetRadioEnabled(enabled);
3809 } catch (Exception e) {
3810 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3811 }
3812 }
3813
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003814 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003815 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3816 * network status based on which carrier apps could apply actions accordingly,
3817 * enable/disable default url handler for example.
3818 *
3819 * @param subId the subscription ID that this action applies to.
3820 * @param report control start/stop reporting the default network status.
3821 * {@hide}
3822 */
3823 @Override
3824 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3825 enforceModifyPermission();
3826 final Phone phone = getPhone(subId);
3827 if (phone == null) {
3828 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3829 return;
3830 }
3831 try {
3832 phone.carrierActionReportDefaultNetworkStatus(report);
3833 } catch (Exception e) {
3834 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3835 }
3836 }
3837
3838 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003839 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3840 * bug report is being generated.
3841 */
3842 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003843 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003844 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3845 != PackageManager.PERMISSION_GRANTED) {
3846 writer.println("Permission Denial: can't dump Phone from pid="
3847 + Binder.getCallingPid()
3848 + ", uid=" + Binder.getCallingUid()
3849 + "without permission "
3850 + android.Manifest.permission.DUMP);
3851 return;
3852 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003853 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003854 }
Jack Yueb89b242016-06-22 13:27:47 -07003855
3856 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003857 * Get aggregated video call data usage since boot.
3858 *
3859 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3860 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003861 * {@hide}
3862 */
3863 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003864 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003865 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3866 null);
3867
Jack Yu84291ec2017-05-26 16:07:50 -07003868 // NetworkStatsService keeps tracking the active network interface and identity. It
3869 // records the delta with the corresponding network identity. We just return the total video
3870 // call data usage snapshot since boot.
3871 Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003874 }
Jack Yu84291ec2017-05-26 16:07:50 -07003875 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003876 }
Jack Yu75ab2952016-07-08 14:29:33 -07003877
3878 /**
3879 * Policy control of data connection. Usually used when data limit is passed.
3880 * @param enabled True if enabling the data, otherwise disabling.
3881 * @param subId Subscription index
3882 * {@hide}
3883 */
3884 @Override
3885 public void setPolicyDataEnabled(boolean enabled, int subId) {
3886 enforceModifyPermission();
3887 Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 phone.setPolicyDataEnabled(enabled);
3890 }
3891 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003892
3893 /**
3894 * Get Client request stats
3895 * @return List of Client Request Stats
3896 * @hide
3897 */
3898 @Override
3899 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3900 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3901 return null;
3902 }
3903
3904 Phone phone = getPhone(subId);
3905 if (phone != null) {
3906 return phone.getClientRequestStats();
3907 }
3908
3909 return null;
3910 }
3911
3912 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3913 if (workSource != null) {
3914 return workSource;
3915 }
3916
3917 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3918 workSource = new WorkSource(uid, packageName);
3919 return workSource;
3920 }
Jack Yueb4124c2017-02-16 15:32:43 -08003921
3922 /**
Grace Chen70990072017-03-24 17:21:30 -07003923 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003924 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003925 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003926 * @param state State of SIM (power down, power up, pass through)
3927 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3928 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3929 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003930 *
3931 **/
3932 @Override
Grace Chen70990072017-03-24 17:21:30 -07003933 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003934 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003935 Phone phone = PhoneFactory.getPhone(slotIndex);
3936
Jack Yueb4124c2017-02-16 15:32:43 -08003937 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003938 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003939 }
3940 }
Shuo Qiandd210312017-04-12 22:11:33 +00003941
Tyler Gunn65d45c22017-06-05 11:22:26 -07003942 private boolean isUssdApiAllowed(int subId) {
3943 CarrierConfigManager configManager =
3944 (CarrierConfigManager) mPhone.getContext().getSystemService(
3945 Context.CARRIER_CONFIG_SERVICE);
3946 if (configManager == null) {
3947 return false;
3948 }
3949 PersistableBundle pb = configManager.getConfigForSubId(subId);
3950 if (pb == null) {
3951 return false;
3952 }
3953 return pb.getBoolean(
3954 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3955 }
3956
Shuo Qiandd210312017-04-12 22:11:33 +00003957 /**
3958 * Check if phone is in emergency callback mode
3959 * @return true if phone is in emergency callback mode
3960 * @param subId sub id
3961 */
3962 public boolean getEmergencyCallbackMode(int subId) {
3963 final Phone phone = getPhone(subId);
3964 if (phone != null) {
3965 return phone.isInEcm();
3966 } else {
3967 return false;
3968 }
3969 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003970
3971 /**
3972 * Get the current signal strength information for the given subscription.
3973 * Because this information is not updated when the device is in a low power state
3974 * it should not be relied-upon to be current.
3975 * @param subId Subscription index
3976 * @return the most recent cached signal strength info from the modem
3977 */
3978 @Override
3979 public SignalStrength getSignalStrength(int subId) {
3980 Phone p = getPhone(subId);
3981 if (p == null) {
3982 return null;
3983 }
3984
3985 return p.getSignalStrength();
3986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987}