blob: ec42f80277ef4d2d613dcecc7b55bacea8fb02b3 [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.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Adam Lesinski903a54c2016-04-11 14:49:52 -070042import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.ServiceManager;
44import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070045import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070046import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070047import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080048import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070049import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080050import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080051import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070052import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070053import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070056import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070057import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080058import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070059import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070060import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080063import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070064import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080065import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080066import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070067import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070068import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080076
Andrew Lee312e8172014-10-23 17:01:36 -070077import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080078import com.android.ims.internal.IImsServiceController;
79import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070080import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070081import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070082import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070083import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080087import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010088import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070089import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070090import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080092import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070094import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070095import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070096import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070097import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080098import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -070099import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700100import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.uicc.IccIoResult;
102import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800103import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700104import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800105import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700107import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800108import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700109import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800110import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700111import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700112import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700114import java.io.FileDescriptor;
115import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800116import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800119import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122
123/**
124 * Implementation of the ITelephony interface.
125 */
Santos Cordon117fee72014-05-16 17:56:12 -0700126public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 private static final String LOG_TAG = "PhoneInterfaceManager";
128 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
129 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132 // Message codes used with mMainThreadHandler
133 private static final int CMD_HANDLE_PIN_MMI = 1;
134 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
135 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
136 private static final int CMD_ANSWER_RINGING_CALL = 4;
137 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700138 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
139 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140 private static final int CMD_OPEN_CHANNEL = 9;
141 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
142 private static final int CMD_CLOSE_CHANNEL = 11;
143 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800144 private static final int CMD_NV_READ_ITEM = 13;
145 private static final int EVENT_NV_READ_ITEM_DONE = 14;
146 private static final int CMD_NV_WRITE_ITEM = 15;
147 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
148 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
149 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
150 private static final int CMD_NV_RESET_CONFIG = 19;
151 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800152 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
153 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
154 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
155 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800156 private static final int CMD_SEND_ENVELOPE = 25;
157 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700158 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
159 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
160 private static final int CMD_EXCHANGE_SIM_IO = 31;
161 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800162 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
163 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700164 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
165 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700166 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
167 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
169 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
170 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
171 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700172 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
173 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
174 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
175 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700176 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
178 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179
180 /** The singleton instance. */
181 private static PhoneInterfaceManager sInstance;
182
Wink Saville3ab207e2014-11-20 13:07:20 -0800183 private PhoneGlobals mApp;
184 private Phone mPhone;
185 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700186 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800187 private AppOpsManager mAppOps;
188 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800189 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800190 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
Derek Tan97ebb422014-09-05 16:55:38 -0700192 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
193 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700195
Derek Tan740e1672017-06-27 14:56:27 -0700196 // The AID of ISD-R.
197 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
198
yinxub1bed742017-04-17 11:45:04 -0700199 private NetworkScanRequestTracker mNetworkScanRequestTracker;
200
Derek Tan89e89d42014-07-08 17:00:10 -0700201 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202 * A request object to use for transmitting data to an ICC.
203 */
204 private static final class IccAPDUArgument {
205 public int channel, cla, command, p1, p2, p3;
206 public String data;
207
208 public IccAPDUArgument(int channel, int cla, int command,
209 int p1, int p2, int p3, String data) {
210 this.channel = channel;
211 this.cla = cla;
212 this.command = command;
213 this.p1 = p1;
214 this.p2 = p2;
215 this.p3 = p3;
216 this.data = data;
217 }
218 }
219
220 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700221 * A request object to use for transmitting data to an ICC.
222 */
223 private static final class ManualNetworkSelectionArgument {
224 public OperatorInfo operatorInfo;
225 public boolean persistSelection;
226
227 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
228 this.operatorInfo = operatorInfo;
229 this.persistSelection = persistSelection;
230 }
231 }
232
233 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
235 * request after sending. The main thread will notify the request when it is complete.
236 */
237 private static final class MainThreadRequest {
238 /** The argument to use for the request */
239 public Object argument;
240 /** The result of the request that is run on the main thread */
241 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800242 // The subscriber id that this request applies to. Defaults to
243 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
244 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
246 public MainThreadRequest(Object argument) {
247 this.argument = argument;
248 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249
250 public MainThreadRequest(Object argument, Integer subId) {
251 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800252 if (subId != null) {
253 this.subId = subId;
254 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 }
257
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800258 private static final class IncomingThirdPartyCallArgs {
259 public final ComponentName component;
260 public final String callId;
261 public final String callerDisplayName;
262
263 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
264 String callerDisplayName) {
265 this.component = component;
266 this.callId = callId;
267 this.callerDisplayName = callerDisplayName;
268 }
269 }
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 /**
272 * A handler that processes messages on the main thread in the phone process. Since many
273 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
274 * inbound binder threads to the main thread in the phone process. The Binder thread
275 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
276 * on, which will be notified when the operation completes and will contain the result of the
277 * request.
278 *
279 * <p>If a MainThreadRequest object is provided in the msg.obj field,
280 * note that request.result must be set to something non-null for the calling thread to
281 * unblock.
282 */
283 private final class MainThreadHandler extends Handler {
284 @Override
285 public void handleMessage(Message msg) {
286 MainThreadRequest request;
287 Message onCompleted;
288 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800289 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700290 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
292 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700293 case CMD_HANDLE_USSD_REQUEST: {
294 request = (MainThreadRequest) msg.obj;
295 final Phone phone = getPhoneFromRequest(request);
296 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
297 String ussdRequest = ussdObject.first;
298 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700299
300 if (!isUssdApiAllowed(request.subId)) {
301 // Carrier does not support use of this API, return failure.
302 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
303 UssdResponse response = new UssdResponse(ussdRequest, null);
304 Bundle returnData = new Bundle();
305 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
306 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
307
308 request.result = true;
309 synchronized (request) {
310 request.notifyAll();
311 }
312 return;
313 }
314
Tyler Gunn52dcf772017-04-26 11:30:31 -0700315 try {
316 request.result = phone != null ?
317 phone.handleUssdRequest(ussdRequest, wrappedCallback)
318 : false;
319 } catch (CallStateException cse) {
320 request.result = false;
321 }
pkanwar32d516d2016-10-14 19:37:38 -0700322 // Wake up the requesting thread
323 synchronized (request) {
324 request.notifyAll();
325 }
326 break;
327 }
328
Yorke Lee716f67e2015-06-17 15:39:16 -0700329 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700331 final Phone phone = getPhoneFromRequest(request);
332 request.result = phone != null ?
333 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
334 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 // Wake up the requesting thread
336 synchronized (request) {
337 request.notifyAll();
338 }
339 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
342 case CMD_HANDLE_NEIGHBORING_CELL:
343 request = (MainThreadRequest) msg.obj;
344 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
345 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700346 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 break;
348
349 case EVENT_NEIGHBORING_CELL_DONE:
350 ar = (AsyncResult) msg.obj;
351 request = (MainThreadRequest) ar.userObj;
352 if (ar.exception == null && ar.result != null) {
353 request.result = ar.result;
354 } else {
355 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800356 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 }
358 // Wake up the requesting thread
359 synchronized (request) {
360 request.notifyAll();
361 }
362 break;
363
364 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700365 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800366 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700367 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 break;
369
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 case CMD_END_CALL:
371 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800372 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700373 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700374 Phone phone = getPhone(end_subId);
375 if (phone == null) {
376 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
377 break;
378 }
379 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
381 // CDMA: If the user presses the Power button we treat it as
382 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700383 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
385 // GSM: End the call as per the Phone state
386 hungUp = PhoneUtils.hangup(mCM);
387 } else {
388 throw new IllegalStateException("Unexpected phone type: " + phoneType);
389 }
390 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
391 request.result = hungUp;
392 // Wake up the requesting thread
393 synchronized (request) {
394 request.notifyAll();
395 }
396 break;
397
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700399 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800401 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700402 if (uiccCard == null) {
403 loge("iccTransmitApduLogicalChannel: No UICC");
404 request.result = new IccIoResult(0x6F, 0, (byte[])null);
405 synchronized (request) {
406 request.notifyAll();
407 }
408 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
410 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700411 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 iccArgument.channel, iccArgument.cla, iccArgument.command,
413 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 break;
417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 ar = (AsyncResult) msg.obj;
420 request = (MainThreadRequest) ar.userObj;
421 if (ar.exception == null && ar.result != null) {
422 request.result = ar.result;
423 } else {
424 request.result = new IccIoResult(0x6F, 0, (byte[])null);
425 if (ar.result == null) {
426 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800427 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800429 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 } else {
431 loge("iccTransmitApduLogicalChannel: Unknown exception");
432 }
433 }
434 synchronized (request) {
435 request.notifyAll();
436 }
437 break;
438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
440 request = (MainThreadRequest) msg.obj;
441 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 if (uiccCard == null) {
444 loge("iccTransmitApduBasicChannel: No UICC");
445 request.result = new IccIoResult(0x6F, 0, (byte[])null);
446 synchronized (request) {
447 request.notifyAll();
448 }
449 } else {
450 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
451 request);
452 uiccCard.iccTransmitApduBasicChannel(
453 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
454 iccArgument.p3, iccArgument.data, onCompleted);
455 }
456 break;
457
458 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
459 ar = (AsyncResult) msg.obj;
460 request = (MainThreadRequest) ar.userObj;
461 if (ar.exception == null && ar.result != null) {
462 request.result = ar.result;
463 } else {
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
465 if (ar.result == null) {
466 loge("iccTransmitApduBasicChannel: Empty response");
467 } else if (ar.exception instanceof CommandException) {
468 loge("iccTransmitApduBasicChannel: CommandException: " +
469 ar.exception);
470 } else {
471 loge("iccTransmitApduBasicChannel: Unknown exception");
472 }
473 }
474 synchronized (request) {
475 request.notifyAll();
476 }
477 break;
478
479 case CMD_EXCHANGE_SIM_IO:
480 request = (MainThreadRequest) msg.obj;
481 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800482 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 if (uiccCard == null) {
484 loge("iccExchangeSimIO: No UICC");
485 request.result = new IccIoResult(0x6F, 0, (byte[])null);
486 synchronized (request) {
487 request.notifyAll();
488 }
489 } else {
490 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
491 request);
492 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
493 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
494 iccArgument.data, onCompleted);
495 }
496 break;
497
498 case EVENT_EXCHANGE_SIM_IO_DONE:
499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
503 } else {
504 request.result = new IccIoResult(0x6f, 0, (byte[])null);
505 }
506 synchronized (request) {
507 request.notifyAll();
508 }
509 break;
510
Derek Tan4d5e5c12014-02-04 11:54:58 -0800511 case CMD_SEND_ENVELOPE:
512 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700514 if (uiccCard == null) {
515 loge("sendEnvelopeWithStatus: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
517 synchronized (request) {
518 request.notifyAll();
519 }
520 } else {
521 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
522 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
523 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800524 break;
525
526 case EVENT_SEND_ENVELOPE_DONE:
527 ar = (AsyncResult) msg.obj;
528 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700529 if (ar.exception == null && ar.result != null) {
530 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
533 if (ar.result == null) {
534 loge("sendEnvelopeWithStatus: Empty response");
535 } else if (ar.exception instanceof CommandException) {
536 loge("sendEnvelopeWithStatus: CommandException: " +
537 ar.exception);
538 } else {
539 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
540 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 }
542 synchronized (request) {
543 request.notifyAll();
544 }
545 break;
546
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 case CMD_OPEN_CHANNEL:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800550 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800553 request.result = new IccOpenLogicalChannelResponse(-1,
554 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 synchronized (request) {
556 request.notifyAll();
557 }
558 } else {
559 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800560 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
561 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
565 case EVENT_OPEN_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 int[] result = (int[]) ar.result;
571 int channelId = result[0];
572 byte[] selectResponse = null;
573 if (result.length > 1) {
574 selectResponse = new byte[result.length - 1];
575 for (int i = 1; i < result.length; ++i) {
576 selectResponse[i - 1] = (byte) result[i];
577 }
578 }
579 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.result == null) {
583 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (ar.exception != null) {
586 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
587 }
588
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700590 if (ar.exception instanceof CommandException) {
591 CommandException.Error error =
592 ((CommandException) (ar.exception)).getCommandError();
593 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700595 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(
600 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700602 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 synchronized (request) {
604 request.notifyAll();
605 }
606 break;
607
608 case CMD_CLOSE_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 if (uiccCard == null) {
612 loge("iccCloseLogicalChannel: No UICC");
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 synchronized (request) {
615 request.notifyAll();
616 }
617 } else {
618 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
619 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
620 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
623 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800624 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
625 break;
626
627 case CMD_NV_READ_ITEM:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
630 mPhone.nvReadItem((Integer) request.argument, onCompleted);
631 break;
632
633 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 ar = (AsyncResult) msg.obj;
635 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800636 if (ar.exception == null && ar.result != null) {
637 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800639 request.result = "";
640 if (ar.result == null) {
641 loge("nvReadItem: Empty response");
642 } else if (ar.exception instanceof CommandException) {
643 loge("nvReadItem: CommandException: " +
644 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800646 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 }
648 }
649 synchronized (request) {
650 request.notifyAll();
651 }
652 break;
653
Jake Hambye994d462014-02-03 13:10:13 -0800654 case CMD_NV_WRITE_ITEM:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
657 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
658 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
659 break;
660
661 case EVENT_NV_WRITE_ITEM_DONE:
662 handleNullReturnEvent(msg, "nvWriteItem");
663 break;
664
665 case CMD_NV_WRITE_CDMA_PRL:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
668 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
669 break;
670
671 case EVENT_NV_WRITE_CDMA_PRL_DONE:
672 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
673 break;
674
675 case CMD_NV_RESET_CONFIG:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
678 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
679 break;
680
681 case EVENT_NV_RESET_CONFIG_DONE:
682 handleNullReturnEvent(msg, "nvResetConfig");
683 break;
684
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 case CMD_GET_PREFERRED_NETWORK_TYPE:
686 request = (MainThreadRequest) msg.obj;
687 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700688 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800689 break;
690
691 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
692 ar = (AsyncResult) msg.obj;
693 request = (MainThreadRequest) ar.userObj;
694 if (ar.exception == null && ar.result != null) {
695 request.result = ar.result; // Integer
696 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800697 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 if (ar.result == null) {
699 loge("getPreferredNetworkType: Empty response");
700 } else if (ar.exception instanceof CommandException) {
701 loge("getPreferredNetworkType: CommandException: " +
702 ar.exception);
703 } else {
704 loge("getPreferredNetworkType: Unknown exception");
705 }
706 }
707 synchronized (request) {
708 request.notifyAll();
709 }
710 break;
711
712 case CMD_SET_PREFERRED_NETWORK_TYPE:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
715 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
720 handleNullReturnEvent(msg, "setPreferredNetworkType");
721 break;
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 case CMD_SET_VOICEMAIL_NUMBER:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
726 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800727 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
728 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 break;
730
731 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
732 handleNullReturnEvent(msg, "setVoicemailNumber");
733 break;
734
Stuart Scott54788802015-03-30 13:18:01 -0700735 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
738 request);
739 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
744 break;
745
Shishir Agrawal302c8692015-06-19 13:49:39 -0700746 case CMD_PERFORM_NETWORK_SCAN:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
749 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
750 break;
751
752 case EVENT_PERFORM_NETWORK_SCAN_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 CellNetworkScanResult cellScanResult;
756 if (ar.exception == null && ar.result != null) {
757 cellScanResult = new CellNetworkScanResult(
758 CellNetworkScanResult.STATUS_SUCCESS,
759 (List<OperatorInfo>) ar.result);
760 } else {
761 if (ar.result == null) {
762 loge("getCellNetworkScanResults: Empty response");
763 }
764 if (ar.exception != null) {
765 loge("getCellNetworkScanResults: Exception: " + ar.exception);
766 }
767 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
770 ((CommandException) (ar.exception)).getCommandError();
771 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
773 } else if (error == CommandException.Error.GENERIC_FAILURE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
775 }
776 }
777 cellScanResult = new CellNetworkScanResult(errorCode, null);
778 }
779 request.result = cellScanResult;
780 synchronized (request) {
781 request.notifyAll();
782 }
783 break;
784
785 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
786 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700787 ManualNetworkSelectionArgument selArg =
788 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
790 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700791 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
792 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700793 break;
794
795 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
796 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
797 break;
798
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700799 case CMD_GET_MODEM_ACTIVITY_INFO:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700802 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700803 break;
804
805 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null && ar.result != null) {
809 request.result = ar.result;
810 } else {
811 if (ar.result == null) {
812 loge("queryModemActivityInfo: Empty response");
813 } else if (ar.exception instanceof CommandException) {
814 loge("queryModemActivityInfo: CommandException: " +
815 ar.exception);
816 } else {
817 loge("queryModemActivityInfo: Unknown exception");
818 }
819 }
Amit Mahajand4766222016-01-28 15:28:28 -0800820 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
821 if (request.result == null) {
822 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
823 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700824 synchronized (request) {
825 request.notifyAll();
826 }
827 break;
828
Meng Wang1a7c35a2016-05-05 20:56:15 -0700829 case CMD_SET_ALLOWED_CARRIERS:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
832 mPhone.setAllowedCarriers(
833 (List<CarrierIdentifier>) request.argument,
834 onCompleted);
835 break;
836
837 case EVENT_SET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("setAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("setAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("setAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return -1 on error.
853 if (request.result == null) {
854 request.result = new int[]{-1};
855 }
856 synchronized (request) {
857 request.notifyAll();
858 }
859 break;
860
861 case CMD_GET_ALLOWED_CARRIERS:
862 request = (MainThreadRequest) msg.obj;
863 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
864 mPhone.getAllowedCarriers(onCompleted);
865 break;
866
867 case EVENT_GET_ALLOWED_CARRIERS_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
873 if (ar.result == null) {
874 loge("getAllowedCarriers: Empty response");
875 } else if (ar.exception instanceof CommandException) {
876 loge("getAllowedCarriers: CommandException: " +
877 ar.exception);
878 } else {
879 loge("getAllowedCarriers: Unknown exception");
880 }
881 }
882 // Result cannot be null. Return empty list of CarrierIdentifier.
883 if (request.result == null) {
884 request.result = new ArrayList<CarrierIdentifier>(0);
885 }
886 synchronized (request) {
887 request.notifyAll();
888 }
889 break;
890
Nathan Haroldb3014052017-01-25 15:57:32 -0800891 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 request.result = new IllegalArgumentException(
898 "Failed to retrieve Forbidden Plmns");
899 if (ar.result == null) {
900 loge("getForbiddenPlmns: Empty response");
901 } else {
902 loge("getForbiddenPlmns: Unknown exception");
903 }
904 }
905 synchronized (request) {
906 request.notifyAll();
907 }
908 break;
909
910 case CMD_GET_FORBIDDEN_PLMNS:
911 request = (MainThreadRequest) msg.obj;
912 uiccCard = getUiccCardFromRequest(request);
913 if (uiccCard == null) {
914 loge("getForbiddenPlmns() UiccCard is null");
915 request.result = new IllegalArgumentException(
916 "getForbiddenPlmns() UiccCard is null");
917 synchronized (request) {
918 request.notifyAll();
919 }
920 break;
921 }
922 Integer appType = (Integer) request.argument;
923 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
924 if (uiccApp == null) {
925 loge("getForbiddenPlmns() no app with specified type -- "
926 + appType);
927 request.result = new IllegalArgumentException("Failed to get UICC App");
928 synchronized (request) {
929 request.notifyAll();
930 }
931 break;
932 } else {
933 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
934 + " specified type -- " + appType);
935 }
936 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
937 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
938 onCompleted);
939 break;
940
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941 default:
942 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
943 break;
944 }
945 }
Jake Hambye994d462014-02-03 13:10:13 -0800946
947 private void handleNullReturnEvent(Message msg, String command) {
948 AsyncResult ar = (AsyncResult) msg.obj;
949 MainThreadRequest request = (MainThreadRequest) ar.userObj;
950 if (ar.exception == null) {
951 request.result = true;
952 } else {
953 request.result = false;
954 if (ar.exception instanceof CommandException) {
955 loge(command + ": CommandException: " + ar.exception);
956 } else {
957 loge(command + ": Unknown exception");
958 }
959 }
960 synchronized (request) {
961 request.notifyAll();
962 }
963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700964 }
965
966 /**
967 * Posts the specified command to be executed on the main thread,
968 * waits for the request to complete, and returns the result.
969 * @see #sendRequestAsync
970 */
971 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800972 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700973 }
974
975 /**
976 * Posts the specified command to be executed on the main thread,
977 * waits for the request to complete, and returns the result.
978 * @see #sendRequestAsync
979 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800980 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
982 throw new RuntimeException("This method will deadlock if called from the main thread.");
983 }
984
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800985 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700986 Message msg = mMainThreadHandler.obtainMessage(command, request);
987 msg.sendToTarget();
988
989 // Wait for the request to complete
990 synchronized (request) {
991 while (request.result == null) {
992 try {
993 request.wait();
994 } catch (InterruptedException e) {
995 // Do nothing, go back and wait until the request is complete
996 }
997 }
998 }
999 return request.result;
1000 }
1001
1002 /**
1003 * Asynchronous ("fire and forget") version of sendRequest():
1004 * Posts the specified command to be executed on the main thread, and
1005 * returns immediately.
1006 * @see #sendRequest
1007 */
1008 private void sendRequestAsync(int command) {
1009 mMainThreadHandler.sendEmptyMessage(command);
1010 }
1011
1012 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001013 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1014 * @see {@link #sendRequest(int,Object)}
1015 */
1016 private void sendRequestAsync(int command, Object argument) {
1017 MainThreadRequest request = new MainThreadRequest(argument);
1018 Message msg = mMainThreadHandler.obtainMessage(command, request);
1019 msg.sendToTarget();
1020 }
1021
1022 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001023 * Initialize the singleton PhoneInterfaceManager instance.
1024 * This is only done once, at startup, from PhoneApp.onCreate().
1025 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001026 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027 synchronized (PhoneInterfaceManager.class) {
1028 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001029 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001030 } else {
1031 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1032 }
1033 return sInstance;
1034 }
1035 }
1036
1037 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001038 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001039 mApp = app;
1040 mPhone = phone;
1041 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001042 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1044 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001045 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001046 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001047 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001048 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001049
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 publish();
1051 }
1052
1053 private void publish() {
1054 if (DBG) log("publish: " + this);
1055
1056 ServiceManager.addService("phone", this);
1057 }
1058
Stuart Scott584921c2015-01-15 17:10:34 -08001059 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001060 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1061 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001062 }
1063
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001064 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1065 Phone phone = getPhoneFromRequest(request);
1066 return phone == null ? null :
1067 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1068 }
1069
Wink Saville36469e72014-06-11 15:17:00 -07001070 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001071 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001072 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001073 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 //
1075 // Implementation of the ITelephony interface.
1076 //
1077
1078 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001079 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001080 }
1081
Wink Savilleb564aae2014-10-23 10:18:09 -07001082 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 if (DBG) log("dial: " + number);
1084 // No permission check needed here: This is just a wrapper around the
1085 // ACTION_DIAL intent, which is available to any app since it puts up
1086 // the UI before it does anything.
1087
1088 String url = createTelUrl(number);
1089 if (url == null) {
1090 return;
1091 }
1092
1093 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001094 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1096 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1097 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1098 mApp.startActivity(intent);
1099 }
1100 }
1101
1102 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001103 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001104 }
1105
Wink Savilleb564aae2014-10-23 10:18:09 -07001106 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 if (DBG) log("call: " + number);
1108
1109 // This is just a wrapper around the ACTION_CALL intent, but we still
1110 // need to do a permission check since we're calling startActivity()
1111 // from the context of the phone app.
1112 enforceCallPermission();
1113
1114 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1115 != AppOpsManager.MODE_ALLOWED) {
1116 return;
1117 }
1118
1119 String url = createTelUrl(number);
1120 if (url == null) {
1121 return;
1122 }
1123
Wink Saville08874612014-08-31 19:19:58 -07001124 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001125 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001126 if (slist != null) {
1127 for (SubscriptionInfo subInfoRecord : slist) {
1128 if (subInfoRecord.getSubscriptionId() == subId) {
1129 isValid = true;
1130 break;
1131 }
Wink Saville08874612014-08-31 19:19:58 -07001132 }
1133 }
1134 if (isValid == false) {
1135 return;
1136 }
1137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001139 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1141 mApp.startActivity(intent);
1142 }
1143
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001144 /**
1145 * End a call based on call state
1146 * @return true is a call was ended
1147 */
1148 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001149 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001150 }
1151
1152 /**
1153 * End a call based on the call state of the subId
1154 * @return true is a call was ended
1155 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001156 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001158 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 }
1160
1161 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001162 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001163 }
1164
Wink Savilleb564aae2014-10-23 10:18:09 -07001165 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 if (DBG) log("answerRingingCall...");
1167 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1168 // but that can probably wait till the big TelephonyManager API overhaul.
1169 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1170 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001171 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 }
1173
1174 /**
1175 * Make the actual telephony calls to implement answerRingingCall().
1176 * This should only be called from the main thread of the Phone app.
1177 * @see #answerRingingCall
1178 *
1179 * TODO: it would be nice to return true if we answered the call, or
1180 * false if there wasn't actually a ringing incoming call, or some
1181 * other error occurred. (In other words, pass back the return value
1182 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1183 * But that would require calling this method via sendRequest() rather
1184 * than sendRequestAsync(), and right now we don't actually *need* that
1185 * return value, so let's just return void for now.
1186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001187 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001188 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001190 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1191 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (hasActiveCall && hasHoldingCall) {
1193 // Both lines are in use!
1194 // TODO: provide a flag to let the caller specify what
1195 // policy to use if both lines are in use. (The current
1196 // behavior is hardwired to "answer incoming, end ongoing",
1197 // which is how the CALL button is specced to behave.)
1198 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1199 return;
1200 } else {
1201 // answerCall() will automatically hold the current active
1202 // call, if there is one.
1203 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1204 return;
1205 }
1206 } else {
1207 // No call was ringing.
1208 return;
1209 }
1210 }
1211
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001213 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001215 public void silenceRinger() {
1216 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001219 @Override
1220 public boolean isOffhook(String callingPackage) {
1221 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001222 }
1223
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001224 @Override
1225 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1226 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1227 return false;
1228 }
1229
Sanket Padawe356d7632015-06-22 14:03:32 -07001230 final Phone phone = getPhone(subId);
1231 if (phone != null) {
1232 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1233 } else {
1234 return false;
1235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 }
1237
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001238 @Override
1239 public boolean isRinging(String callingPackage) {
1240 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001241 }
1242
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001243 @Override
1244 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1245 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1246 return false;
1247 }
1248
Sanket Padawe356d7632015-06-22 14:03:32 -07001249 final Phone phone = getPhone(subId);
1250 if (phone != null) {
1251 return (phone.getState() == PhoneConstants.State.RINGING);
1252 } else {
1253 return false;
1254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 }
1256
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001257 @Override
1258 public boolean isIdle(String callingPackage) {
1259 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001260 }
1261
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001262 @Override
1263 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1264 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1265 return false;
1266 }
1267
Sanket Padawe356d7632015-06-22 14:03:32 -07001268 final Phone phone = getPhone(subId);
1269 if (phone != null) {
1270 return (phone.getState() == PhoneConstants.State.IDLE);
1271 } else {
1272 return false;
1273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001277 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
Wink Savilleb564aae2014-10-23 10:18:09 -07001280 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001281 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001282 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1283 }
1284
1285 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001286 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Wink Savilleb564aae2014-10-23 10:18:09 -07001289 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001290 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001291 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1292 }
1293
1294 /** {@hide} */
1295 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001296 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001297 }
1298
Wink Savilleb564aae2014-10-23 10:18:09 -07001299 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001301 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 checkSimPin.start();
1303 return checkSimPin.unlockSim(null, pin);
1304 }
1305
Wink Saville9de0f752013-10-22 19:04:03 -07001306 /** {@hide} */
1307 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001313 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 checkSimPuk.start();
1315 return checkSimPuk.unlockSim(puk, pin);
1316 }
1317
1318 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001319 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 * a synchronous one.
1321 */
1322 private static class UnlockSim extends Thread {
1323
1324 private final IccCard mSimCard;
1325
1326 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001327 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1328 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329
1330 // For replies from SimCard interface
1331 private Handler mHandler;
1332
1333 // For async handler to identify request type
1334 private static final int SUPPLY_PIN_COMPLETE = 100;
1335
1336 public UnlockSim(IccCard simCard) {
1337 mSimCard = simCard;
1338 }
1339
1340 @Override
1341 public void run() {
1342 Looper.prepare();
1343 synchronized (UnlockSim.this) {
1344 mHandler = new Handler() {
1345 @Override
1346 public void handleMessage(Message msg) {
1347 AsyncResult ar = (AsyncResult) msg.obj;
1348 switch (msg.what) {
1349 case SUPPLY_PIN_COMPLETE:
1350 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1351 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001352 mRetryCount = msg.arg1;
1353 if (ar.exception != null) {
1354 if (ar.exception instanceof CommandException &&
1355 ((CommandException)(ar.exception)).getCommandError()
1356 == CommandException.Error.PASSWORD_INCORRECT) {
1357 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1358 } else {
1359 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1360 }
1361 } else {
1362 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 mDone = true;
1365 UnlockSim.this.notifyAll();
1366 }
1367 break;
1368 }
1369 }
1370 };
1371 UnlockSim.this.notifyAll();
1372 }
1373 Looper.loop();
1374 }
1375
1376 /*
1377 * Use PIN or PUK to unlock SIM card
1378 *
1379 * If PUK is null, unlock SIM card with PIN
1380 *
1381 * If PUK is not null, unlock SIM card with PUK and set PIN code
1382 */
Wink Saville9de0f752013-10-22 19:04:03 -07001383 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384
1385 while (mHandler == null) {
1386 try {
1387 wait();
1388 } catch (InterruptedException e) {
1389 Thread.currentThread().interrupt();
1390 }
1391 }
1392 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1393
1394 if (puk == null) {
1395 mSimCard.supplyPin(pin, callback);
1396 } else {
1397 mSimCard.supplyPuk(puk, pin, callback);
1398 }
1399
1400 while (!mDone) {
1401 try {
1402 Log.d(LOG_TAG, "wait for done");
1403 wait();
1404 } catch (InterruptedException e) {
1405 // Restore the interrupted status
1406 Thread.currentThread().interrupt();
1407 }
1408 }
1409 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001410 int[] resultArray = new int[2];
1411 resultArray[0] = mResult;
1412 resultArray[1] = mRetryCount;
1413 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 }
1415 }
1416
1417 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001418 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001419
1420 }
1421
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423 // No permission check needed here: this call is harmless, and it's
1424 // needed for the ServiceState.requestStateUpdate() call (which is
1425 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001426 final Phone phone = getPhone(subId);
1427 if (phone != null) {
1428 phone.updateServiceLocation();
1429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 }
1431
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001432 @Override
1433 public boolean isRadioOn(String callingPackage) {
1434 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001435 }
1436
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001437 @Override
1438 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1439 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1440 return false;
1441 }
1442 return isRadioOnForSubscriber(subId);
1443 }
1444
1445 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001446 final Phone phone = getPhone(subId);
1447 if (phone != null) {
1448 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1449 } else {
1450 return false;
1451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453
1454 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001456
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 }
Wink Saville36469e72014-06-11 15:17:00 -07001458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001461 final Phone phone = getPhone(subId);
1462 if (phone != null) {
1463 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1464 }
Wink Saville36469e72014-06-11 15:17:00 -07001465 }
1466
1467 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001468 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001469 }
1470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001472 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001473 final Phone phone = getPhone(subId);
1474 if (phone == null) {
1475 return false;
1476 }
1477 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001478 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001479 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 return true;
1482 }
Wink Saville36469e72014-06-11 15:17:00 -07001483
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001484 public boolean needMobileRadioShutdown() {
1485 /*
1486 * If any of the Radios are available, it will need to be
1487 * shutdown. So return true if any Radio is available.
1488 */
1489 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1490 Phone phone = PhoneFactory.getPhone(i);
1491 if (phone != null && phone.isRadioAvailable()) return true;
1492 }
1493 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1494 return false;
1495 }
1496
1497 public void shutdownMobileRadios() {
1498 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1499 logv("Shutting down Phone " + i);
1500 shutdownRadioUsingPhoneId(i);
1501 }
1502 }
1503
1504 private void shutdownRadioUsingPhoneId(int phoneId) {
1505 enforceModifyPermission();
1506 Phone phone = PhoneFactory.getPhone(phoneId);
1507 if (phone != null && phone.isRadioAvailable()) {
1508 phone.shutdownRadio();
1509 }
1510 }
1511
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001513 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001514 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1515 if (defaultPhone != null) {
1516 defaultPhone.setRadioPower(turnOn);
1517 return true;
1518 } else {
1519 loge("There's no default phone.");
1520 return false;
1521 }
Wink Saville36469e72014-06-11 15:17:00 -07001522 }
1523
Wink Savilleb564aae2014-10-23 10:18:09 -07001524 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001526 final Phone phone = getPhone(subId);
1527 if (phone != null) {
1528 phone.setRadioPower(turnOn);
1529 return true;
1530 } else {
1531 return false;
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Wink Saville36469e72014-06-11 15:17:00 -07001535 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001536 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 public boolean enableDataConnectivity() {
1538 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001539 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001540 final Phone phone = getPhone(subId);
1541 if (phone != null) {
1542 phone.setDataEnabled(true);
1543 return true;
1544 } else {
1545 return false;
1546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 }
1548
Wink Saville36469e72014-06-11 15:17:00 -07001549 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001550 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 public boolean disableDataConnectivity() {
1552 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001553 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 final Phone phone = getPhone(subId);
1555 if (phone != null) {
1556 phone.setDataEnabled(false);
1557 return true;
1558 } else {
1559 return false;
1560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 }
1562
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001564 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 final Phone phone = getPhone(subId);
1566 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001567 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 } else {
1569 return false;
1570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 }
1572
1573 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001574 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001575 }
1576
pkanwarae03a6b2016-11-06 20:37:09 -08001577 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001578 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001579 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1580 return;
1581 }
1582 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1583 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1584 };
1585
Wink Savilleb564aae2014-10-23 10:18:09 -07001586 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1589 return false;
1590 }
Wink Saville36469e72014-06-11 15:17:00 -07001591 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 }
1593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001595 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001596 }
1597
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001598 public int getCallStateForSlot(int slotIndex) {
1599 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001600 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001601 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
1603
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001606 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001608 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001610 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 }
1613
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001616 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 if (phone != null) {
1618 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1619 } else {
1620 return TelephonyManager.DATA_ACTIVITY_NONE;
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
1624 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001625 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001626 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001627 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001628 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001631 if (DBG_LOC) log("getCellLocation: is active user");
1632 Bundle data = new Bundle();
1633 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1634 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 return null;
1636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001638 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1639 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1640 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001641 }
1642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001644 public String getNetworkCountryIsoForPhone(int phoneId) {
1645 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1646 // registered cell info, so return a NULL country instead.
1647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1650 if (TelephonyManager.NETWORK_TYPE_IWLAN
1651 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1652 return "";
1653 }
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
1656 }
1657 return TelephonyManager.getTelephonyProperty(
1658 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1659 }
1660
1661 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001663 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Sanket Padawe356d7632015-06-22 14:03:32 -07001666 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001667 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 mApp.enforceCallingOrSelfPermission(
1669 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 final Phone phone = getPhone(subId);
1671 if (phone != null) {
1672 phone.enableLocationUpdates();
1673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 }
1675
1676 @Override
1677 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001678 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001679 }
1680
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001682 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 mApp.enforceCallingOrSelfPermission(
1684 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 final Phone phone = getPhone(subId);
1686 if (phone != null) {
1687 phone.disableLocationUpdates();
1688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
1691 @Override
1692 @SuppressWarnings("unchecked")
1693 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001694 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001695 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001696 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
1699 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1700 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1701 return null;
1702 }
Svetoslav64fad262015-04-14 14:35:21 -07001703
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001704 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001706 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001708 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1709 try {
1710 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1711 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1712 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1713 } catch (RuntimeException e) {
1714 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001716 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
1719
1720 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001721 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001722 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001723 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001724 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001727 if (DBG_LOC) log("getAllCellInfo: is active user");
1728 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1729 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1730 for (Phone phone : PhoneFactory.getPhones()) {
1731 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1732 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001734 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001739 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001740 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1741 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743
Shishir Agrawala9f32182016-04-12 12:00:16 -07001744 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001745 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001746 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1747 return null;
1748 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001749 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001750 return phone == null ? null : phone.getImei();
1751 }
1752
1753 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001754 public String getMeidForSlot(int slotIndex, String callingPackage) {
1755 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1756 return null;
1757 }
1758 Phone phone = PhoneFactory.getPhone(slotIndex);
1759 return phone == null ? null : phone.getMeid();
1760 }
1761
1762 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001763 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001764 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1765 return null;
1766 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001767 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001768 return phone == null ? null : phone.getDeviceSvn();
1769 }
1770
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 //
1772 // Internal helper methods.
1773 //
1774
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001775 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1777 *
1778 * @throws SecurityException if the caller does not have the required permission
1779 */
1780 private void enforceModifyPermission() {
1781 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1782 }
1783
1784 /**
Junda Liua2e36012014-07-09 18:30:01 -07001785 * Make sure either system app or the caller has carrier privilege.
1786 *
1787 * @throws SecurityException if the caller does not have the required permission/privilege
1788 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001789 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001790 int permission = mApp.checkCallingOrSelfPermission(
1791 android.Manifest.permission.MODIFY_PHONE_STATE);
1792 if (permission == PackageManager.PERMISSION_GRANTED) {
1793 return;
1794 }
1795
1796 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001797 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001798 }
1799
1800 /**
1801 * Make sure the caller has carrier privilege.
1802 *
1803 * @throws SecurityException if the caller does not have the required permission
1804 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001805 private void enforceCarrierPrivilege(int subId) {
1806 if (getCarrierPrivilegeStatus(subId) !=
1807 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001808 loge("No Carrier Privilege.");
1809 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001810 }
1811 }
1812
1813 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 * Make sure the caller has the CALL_PHONE permission.
1815 *
1816 * @throws SecurityException if the caller does not have the required permission
1817 */
1818 private void enforceCallPermission() {
1819 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1820 }
1821
Stuart Scott8eef64f2015-04-08 15:13:54 -07001822 private void enforceConnectivityInternalPermission() {
1823 mApp.enforceCallingOrSelfPermission(
1824 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1825 "ConnectivityService");
1826 }
1827
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 private String createTelUrl(String number) {
1829 if (TextUtils.isEmpty(number)) {
1830 return null;
1831 }
1832
Jake Hambye994d462014-02-03 13:10:13 -08001833 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 }
1835
Ihab Awadf9e92732013-12-05 18:02:52 -08001836 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1838 }
1839
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001840 private static void logv(String msg) {
1841 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1842 }
1843
Ihab Awadf9e92732013-12-05 18:02:52 -08001844 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1846 }
1847
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001848 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001850 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001851 }
1852
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001854 public int getActivePhoneTypeForSlot(int slotIndex) {
1855 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 if (phone == null) {
1857 return PhoneConstants.PHONE_TYPE_NONE;
1858 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001859 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 /**
1864 * Returns the CDMA ERI icon index to display
1865 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001866 @Override
1867 public int getCdmaEriIconIndex(String callingPackage) {
1868 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001869 }
1870
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001872 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1873 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1874 return -1;
1875 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 final Phone phone = getPhone(subId);
1877 if (phone != null) {
1878 return phone.getCdmaEriIconIndex();
1879 } else {
1880 return -1;
1881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
1884 /**
1885 * Returns the CDMA ERI icon mode,
1886 * 0 - ON
1887 * 1 - FLASHING
1888 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001889 @Override
1890 public int getCdmaEriIconMode(String callingPackage) {
1891 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001895 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1896 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1897 return -1;
1898 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 return phone.getCdmaEriIconMode();
1902 } else {
1903 return -1;
1904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 /**
1908 * Returns the CDMA ERI text,
1909 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001910 @Override
1911 public String getCdmaEriText(String callingPackage) {
1912 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001916 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1917 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1918 return null;
1919 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 final Phone phone = getPhone(subId);
1921 if (phone != null) {
1922 return phone.getCdmaEriText();
1923 } else {
1924 return null;
1925 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 }
1927
1928 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001929 * Returns the CDMA MDN.
1930 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001932 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001933 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 final Phone phone = getPhone(subId);
1935 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1936 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001937 } else {
1938 return null;
1939 }
1940 }
1941
1942 /**
1943 * Returns the CDMA MIN.
1944 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001946 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001947 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1950 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001951 } else {
1952 return null;
1953 }
1954 }
1955
1956 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 * Returns true if CDMA provisioning needs to run.
1958 */
1959 public boolean needsOtaServiceProvisioning() {
1960 return mPhone.needsOtaServiceProvisioning();
1961 }
1962
1963 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001964 * Sets the voice mail number of a given subId.
1965 */
1966 @Override
1967 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001968 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001969 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1970 new Pair<String, String>(alphaTag, number), new Integer(subId));
1971 return success;
1972 }
1973
Ta-wei Yen87c49842016-05-13 21:19:52 -07001974 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001975 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1976 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1977 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1978 if (!TextUtils.equals(callingPackage, systemDialer)) {
1979 throw new SecurityException("caller must be system dialer");
1980 }
1981 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1982 if (phoneAccountHandle == null){
1983 return null;
1984 }
1985 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
1986 }
1987
1988 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08001989 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08001990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1991 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1992 return null;
1993 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08001994 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1995 }
1996
1997 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001998 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1999 VisualVoicemailSmsFilterSettings settings) {
2000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002001 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002002 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2003 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002004 }
2005
2006 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002007 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002009 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002010 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002011 }
2012
2013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002014 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2015 String callingPackage, int subId) {
2016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002017 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002018 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002019 }
2020
2021 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002022 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002023 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002024 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002025 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2026 }
2027
2028 @Override
2029 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2030 String number, int port, String text, PendingIntent sentIntent) {
2031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002032 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002033 enforceSendSmsPermission();
2034 // Make the calls as the phone process.
2035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2038 if (port == 0) {
2039 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2040 sentIntent, null, false);
2041 } else {
2042 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2043 smsManager.sendDataMessageWithSelfPermissions(number, null,
2044 (short) port, data, sentIntent, null);
2045 }
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
2048 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002050 /**
fionaxu0152e512016-11-14 13:36:14 -08002051 * Sets the voice activation state of a given subId.
2052 */
2053 @Override
2054 public void setVoiceActivationState(int subId, int activationState) {
2055 enforceModifyPermissionOrCarrierPrivilege(subId);
2056 final Phone phone = getPhone(subId);
2057 if (phone != null) {
2058 phone.setVoiceActivationState(activationState);
2059 } else {
2060 loge("setVoiceActivationState fails with invalid subId: " + subId);
2061 }
2062 }
2063
2064 /**
2065 * Sets the data activation state of a given subId.
2066 */
2067 @Override
2068 public void setDataActivationState(int subId, int activationState) {
2069 enforceModifyPermissionOrCarrierPrivilege(subId);
2070 final Phone phone = getPhone(subId);
2071 if (phone != null) {
2072 phone.setDataActivationState(activationState);
2073 } else {
2074 loge("setVoiceActivationState fails with invalid subId: " + subId);
2075 }
2076 }
2077
2078 /**
2079 * Returns the voice activation state of a given subId.
2080 */
2081 @Override
2082 public int getVoiceActivationState(int subId, String callingPackage) {
2083 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2084 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2085 }
2086 final Phone phone = getPhone(subId);
2087 if (phone != null) {
2088 return phone.getVoiceActivationState();
2089 } else {
2090 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2091 }
2092 }
2093
2094 /**
2095 * Returns the data activation state of a given subId.
2096 */
2097 @Override
2098 public int getDataActivationState(int subId, String callingPackage) {
2099 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2100 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2101 }
2102 final Phone phone = getPhone(subId);
2103 if (phone != null) {
2104 return phone.getDataActivationState();
2105 } else {
2106 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2107 }
2108 }
2109
2110 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 * Returns the unread count of voicemails
2112 */
2113 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002114 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002115 }
2116
2117 /**
2118 * Returns the unread count of voicemails for a subId
2119 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002120 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002121 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 final Phone phone = getPhone(subId);
2123 if (phone != null) {
2124 return phone.getVoiceMessageCount();
2125 } else {
2126 return 0;
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
2130 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002131 * returns true, if the device is in a state where both voice and data
2132 * are supported simultaneously. This can change based on location or network condition.
2133 */
2134 @Override
2135 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2136 final Phone phone = getPhone(subId);
2137 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2138 }
2139
2140 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002141 * Send the dialer code if called from the current default dialer or the caller has
2142 * carrier privilege.
2143 * @param inputCode The dialer code to send
2144 */
2145 @Override
2146 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2148 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2149 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2150 enforceCarrierPrivilege(getDefaultSubscription());
2151 }
2152 mPhone.sendDialerSpecialCode(inputCode);
2153 }
2154
2155 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002156 * Returns the data network type.
2157 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 *
2159 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2160 */
2161 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002162 public int getNetworkType() {
2163 final Phone phone = getPhone(getDefaultSubscription());
2164 if (phone != null) {
2165 return phone.getServiceState().getDataNetworkType();
2166 } else {
2167 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2168 }
Wink Saville36469e72014-06-11 15:17:00 -07002169 }
2170
2171 /**
2172 * Returns the network type for a subId
2173 */
2174 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002175 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2176 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2177 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2178 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002179
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002181 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 return phone.getServiceState().getDataNetworkType();
2183 } else {
2184 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
2188 /**
2189 * Returns the data network type
2190 */
2191 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 public int getDataNetworkType(String callingPackage) {
2193 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
2196 /**
2197 * Returns the data network type for a subId
2198 */
2199 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2201 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2202 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2203 }
2204
Sanket Padawe356d7632015-06-22 14:03:32 -07002205 final Phone phone = getPhone(subId);
2206 if (phone != null) {
2207 return phone.getServiceState().getDataNetworkType();
2208 } else {
2209 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
2213 /**
Wink Saville36469e72014-06-11 15:17:00 -07002214 * Returns the Voice network type for a subId
2215 */
2216 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002217 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2218 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2220 }
2221
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 final Phone phone = getPhone(subId);
2223 if (phone != null) {
2224 return phone.getServiceState().getVoiceNetworkType();
2225 } else {
2226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
2230 /**
2231 * @return true if a ICC card is present
2232 */
2233 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002234 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002235 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2236 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
2239 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002240 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002241 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002242 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002243 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2244 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002245 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002247 } else {
2248 return false;
2249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
2253 * Return if the current radio is LTE on CDMA. This
2254 * is a tri-state return value as for a period of time
2255 * the mode may be unknown.
2256 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002259 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 @Override
2262 public int getLteOnCdmaMode(String callingPackage) {
2263 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2268 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2269 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2270 }
2271
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 final Phone phone = getPhone(subId);
2273 if (phone == null) {
2274 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2275 } else {
2276 return phone.getLteOnCdmaMode();
2277 }
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
2280 public void setPhone(Phone phone) {
2281 mPhone = phone;
2282 }
2283
2284 /**
2285 * {@hide}
2286 * Returns Default subId, 0 in the case of single standby.
2287 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002288 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002289 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
Shishir Agrawala9f32182016-04-12 12:00:16 -07002292 private int getSlotForDefaultSubscription() {
2293 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2294 }
2295
Wink Savilleb564aae2014-10-23 10:18:09 -07002296 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002297 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002299
2300 /**
2301 * @see android.telephony.TelephonyManager.WifiCallingChoices
2302 */
2303 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002304 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2305 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002306 }
2307
2308 /**
2309 * @see android.telephony.TelephonyManager.WifiCallingChoices
2310 */
2311 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002312 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2313 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2314 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002315 }
2316
Sailesh Nepald1e68152013-12-12 19:08:02 -08002317 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002318 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002319 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002320 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002321
Shishir Agrawal566b7612013-10-28 14:41:00 -07002322 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002323 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2324 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002325 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002326
Derek Tan740e1672017-06-27 14:56:27 -07002327 if (TextUtils.equals(ISDR_AID, aid)) {
2328 // Only allows LPA to open logical channel to ISD-R.
2329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2330 ComponentInfo bestComponent =
2331 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2332 if (bestComponent == null
2333 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2334 loge("The calling package is not allowed to access ISD-R.");
2335 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2336 }
2337 }
2338
2339 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002340 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002341 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002342 if (DBG) log("iccOpenLogicalChannel: " + response);
2343 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002344 }
2345
2346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002347 public boolean iccCloseLogicalChannel(int subId, int channel) {
2348 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002349
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002350 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002351 if (channel < 0) {
2352 return false;
2353 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002354 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002355 if (DBG) log("iccCloseLogicalChannel: " + success);
2356 return success;
2357 }
2358
2359 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002360 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002361 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002362 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363
2364 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002365 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2366 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 " data=" + data);
2368 }
2369
2370 if (channel < 0) {
2371 return "";
2372 }
2373
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002374 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002375 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002376 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2377
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 // Append the returned status code to the end of the response payload.
2379 String s = Integer.toHexString(
2380 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002381 if (response.payload != null) {
2382 s = IccUtils.bytesToHexString(response.payload) + s;
2383 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 return s;
2385 }
Jake Hambye994d462014-02-03 13:10:13 -08002386
Evan Charltonc66da362014-05-16 14:06:40 -07002387 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002389 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002391
2392 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2394 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002395 }
2396
2397 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002398 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002399 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002401 // Append the returned status code to the end of the response payload.
2402 String s = Integer.toHexString(
2403 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002404 if (response.payload != null) {
2405 s = IccUtils.bytesToHexString(response.payload) + s;
2406 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002407 return s;
2408 }
2409
2410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002411 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002412 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002414
2415 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002416 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002417 p1 + " " + p2 + " " + p3 + ":" + filePath);
2418 }
2419
2420 IccIoResult response =
2421 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2423 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002424
2425 if (DBG) {
2426 log("Exchange SIM_IO [R]" + response);
2427 }
2428
2429 byte[] result = null;
2430 int length = 2;
2431 if (response.payload != null) {
2432 length = 2 + response.payload.length;
2433 result = new byte[length];
2434 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2435 } else {
2436 result = new byte[length];
2437 }
2438
2439 result[length - 1] = (byte) response.sw2;
2440 result[length - 2] = (byte) response.sw1;
2441 return result;
2442 }
2443
Nathan Haroldb3014052017-01-25 15:57:32 -08002444 /**
2445 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2446 * on a particular subscription
2447 */
2448 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002449 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2450 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002451 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2452 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2453 return null;
2454 }
2455 Object response = sendRequest(
2456 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2457 if (response instanceof String[]) {
2458 return (String[]) response;
2459 }
2460 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2461 return null;
2462 }
2463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 public String sendEnvelopeWithStatus(int subId, String content) {
2466 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002467
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002468 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002469 if (response.payload == null) {
2470 return "";
2471 }
2472
2473 // Append the returned status code to the end of the response payload.
2474 String s = Integer.toHexString(
2475 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2476 s = IccUtils.bytesToHexString(response.payload) + s;
2477 return s;
2478 }
2479
Jake Hambye994d462014-02-03 13:10:13 -08002480 /**
2481 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2482 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2483 *
2484 * @param itemID the ID of the item to read
2485 * @return the NV item as a String, or null on error.
2486 */
2487 @Override
2488 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002489 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002490 if (DBG) log("nvReadItem: item " + itemID);
2491 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2492 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2493 return value;
2494 }
2495
2496 /**
2497 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2498 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2499 *
2500 * @param itemID the ID of the item to read
2501 * @param itemValue the value to write, as a String
2502 * @return true on success; false on any failure
2503 */
2504 @Override
2505 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002506 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002507 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2508 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2509 new Pair<Integer, String>(itemID, itemValue));
2510 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2511 return success;
2512 }
2513
2514 /**
2515 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2516 * Used for device configuration by some CDMA operators.
2517 *
2518 * @param preferredRoamingList byte array containing the new PRL
2519 * @return true on success; false on any failure
2520 */
2521 @Override
2522 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002524 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2525 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2526 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2527 return success;
2528 }
2529
2530 /**
2531 * Perform the specified type of NV config reset.
2532 * Used for device configuration by some CDMA operators.
2533 *
2534 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2535 * @return true on success; false on any failure
2536 */
2537 @Override
2538 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002539 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002540 if (DBG) log("nvResetConfig: type " + resetType);
2541 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2542 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2543 return success;
2544 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002545
2546 /**
Wink Saville36469e72014-06-11 15:17:00 -07002547 * {@hide}
2548 * Returns Default sim, 0 in the case of single standby.
2549 */
2550 public int getDefaultSim() {
2551 //TODO Need to get it from Telephony Devcontroller
2552 return 0;
2553 }
2554
Svet Ganovb320e182015-04-16 12:30:10 -07002555 public String[] getPcscfAddress(String apnType, String callingPackage) {
2556 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2557 return new String[0];
2558 }
2559
2560
ram87fca6f2014-07-18 18:58:44 +05302561 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Brad Ebinger51f743a2017-01-23 13:50:20 -08002564 /**
2565 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2566 * feature or {@link null} if the service is not available. If an ImsServiceController is
2567 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2568 * feature updates.
2569 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002570 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002571 IImsServiceFeatureListener callback) {
2572 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002573 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002574 callback);
2575 }
2576
Wink Saville36469e72014-06-11 15:17:00 -07002577 public void setImsRegistrationState(boolean registered) {
2578 enforceModifyPermission();
2579 mPhone.setImsRegistrationState(registered);
2580 }
2581
2582 /**
Stuart Scott54788802015-03-30 13:18:01 -07002583 * Set the network selection mode to automatic.
2584 *
2585 */
2586 @Override
2587 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002588 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002589 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2590 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2591 }
2592
2593 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002594 * Set the network selection mode to manual with the selected carrier.
2595 */
2596 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002597 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2598 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002599 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002600 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002601 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2602 persistSelection);
2603 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002604 }
2605
2606 /**
2607 * Scans for available networks.
2608 */
2609 @Override
2610 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002611 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002612 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2613 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2614 CMD_PERFORM_NETWORK_SCAN, null, subId);
2615 return result;
2616 }
2617
2618 /**
yinxub1bed742017-04-17 11:45:04 -07002619 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002620 *
yinxub1bed742017-04-17 11:45:04 -07002621 * @param subId id of the subscription
2622 * @param request contains the radio access networks with bands/channels to scan
2623 * @param messenger callback messenger for scan results or errors
2624 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002625 * @return the id of the requested scan which can be used to stop the scan.
2626 */
2627 @Override
2628 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2629 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002630 enforceModifyPermissionOrCarrierPrivilege(subId);
2631 return mNetworkScanRequestTracker.startNetworkScan(
2632 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002633 }
2634
2635 /**
2636 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002637 *
2638 * @param subId id of the subscription
2639 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002640 */
2641 @Override
2642 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002643 enforceModifyPermissionOrCarrierPrivilege(subId);
2644 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002645 }
2646
2647 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002648 * Get the calculated preferred network type.
2649 * Used for debugging incorrect network type.
2650 *
2651 * @return the preferred network type, defined in RILConstants.java.
2652 */
2653 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002654 public int getCalculatedPreferredNetworkType(String callingPackage) {
2655 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2656 return RILConstants.PREFERRED_NETWORK_MODE;
2657 }
2658
Amit Mahajan43330e02014-11-18 11:54:45 -08002659 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002660 }
2661
2662 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002663 * Get the preferred network type.
2664 * Used for device configuration by some CDMA operators.
2665 *
2666 * @return the preferred network type, defined in RILConstants.java.
2667 */
2668 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002669 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002670 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002671 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002672 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002673 int networkType = (result != null ? result[0] : -1);
2674 if (DBG) log("getPreferredNetworkType: " + networkType);
2675 return networkType;
2676 }
2677
2678 /**
2679 * Set the preferred network type.
2680 * Used for device configuration by some CDMA operators.
2681 *
2682 * @param networkType the preferred network type, defined in RILConstants.java.
2683 * @return true on success; false on any failure.
2684 */
2685 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002686 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002687 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002688 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2689 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002690 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002691 if (success) {
2692 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002693 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002694 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002695 return success;
2696 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002697
2698 /**
Junda Liu475951f2014-11-07 16:45:03 -08002699 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2700 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2701 * tethering.
2702 *
2703 * @return 0: Not required. 1: required. 2: Not set.
2704 * @hide
2705 */
2706 @Override
2707 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002708 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002709 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2710 Settings.Global.TETHER_DUN_REQUIRED, 2);
2711 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2712 // config_tether_apndata.
2713 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2714 dunRequired = 1;
2715 }
2716 return dunRequired;
2717 }
2718
2719 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002720 * Set mobile data enabled
2721 * Used by the user through settings etc to turn on/off mobile data
2722 *
2723 * @param enable {@code true} turn turn data on, else {@code false}
2724 */
2725 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002726 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002727 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002728 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002729 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002730 Phone phone = PhoneFactory.getPhone(phoneId);
2731 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002732 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002733 phone.setDataEnabled(enable);
2734 } else {
2735 loge("setDataEnabled: no phone for subId=" + subId);
2736 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002737 }
2738
2739 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002740 * Get whether mobile data is enabled.
2741 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002742 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002743 *
2744 * @return {@code true} if data is enabled else {@code false}
2745 */
2746 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002747 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002748 try {
2749 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2750 null);
2751 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002752 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002753 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002754 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002755 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002756 Phone phone = PhoneFactory.getPhone(phoneId);
2757 if (phone != null) {
2758 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002759 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002760 return retVal;
2761 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002762 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002763 return false;
2764 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002765 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002766
2767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002768 public int getCarrierPrivilegeStatus(int subId) {
2769 final Phone phone = getPhone(subId);
2770 if (phone == null) {
2771 loge("getCarrierPrivilegeStatus: Invalid subId");
2772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2773 }
2774 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002775 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002776 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002777 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2778 }
2779 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002780 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002781 }
Junda Liu29340342014-07-10 15:23:27 -07002782
2783 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002784 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002785 if (TextUtils.isEmpty(pkgName))
2786 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002787 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002788 if (card == null) {
2789 loge("checkCarrierPrivilegesForPackage: No UICC");
2790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2791 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002792 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2793 }
2794
2795 @Override
2796 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002797 if (TextUtils.isEmpty(pkgName))
2798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002799 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2801 UiccCard card = UiccController.getInstance().getUiccCard(i);
2802 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002803 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002804 continue;
2805 }
2806
2807 result = card.getCarrierPrivilegeStatus(
2808 mPhone.getContext().getPackageManager(), pkgName);
2809 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2810 break;
2811 }
2812 }
2813
2814 return result;
Junda Liu29340342014-07-10 15:23:27 -07002815 }
Derek Tan89e89d42014-07-08 17:00:10 -07002816
2817 @Override
Junda Liue64de782015-04-16 17:19:16 -07002818 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2819 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2820 loge("phoneId " + phoneId + " is not valid.");
2821 return null;
2822 }
2823 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002824 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002825 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002826 return null ;
2827 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002828 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002829 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002830 }
2831
Amith Yamasani6e118872016-02-19 12:53:51 -08002832 @Override
2833 public List<String> getPackagesWithCarrierPrivileges() {
2834 PackageManager pm = mPhone.getContext().getPackageManager();
2835 List<String> privilegedPackages = new ArrayList<>();
2836 List<PackageInfo> packages = null;
2837 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2838 UiccCard card = UiccController.getInstance().getUiccCard(i);
2839 if (card == null) {
2840 // No UICC in that slot.
2841 continue;
2842 }
2843 if (card.hasCarrierPrivilegeRules()) {
2844 if (packages == null) {
2845 // Only check packages in user 0 for now
2846 packages = pm.getInstalledPackagesAsUser(
2847 PackageManager.MATCH_DISABLED_COMPONENTS
2848 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2849 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2850 }
2851 for (int p = packages.size() - 1; p >= 0; p--) {
2852 PackageInfo pkgInfo = packages.get(p);
2853 if (pkgInfo != null && pkgInfo.packageName != null
2854 && card.getCarrierPrivilegeStatus(pkgInfo)
2855 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2856 privilegedPackages.add(pkgInfo.packageName);
2857 }
2858 }
2859 }
2860 }
2861 return privilegedPackages;
2862 }
2863
Wink Savilleb564aae2014-10-23 10:18:09 -07002864 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 final Phone phone = getPhone(subId);
2866 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002867 if (card == null) {
2868 loge("getIccId: No UICC");
2869 return null;
2870 }
2871 String iccId = card.getIccId();
2872 if (TextUtils.isEmpty(iccId)) {
2873 loge("getIccId: ICC ID is null or empty.");
2874 return null;
2875 }
2876 return iccId;
2877 }
2878
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002879 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002880 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2881 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002882 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002883
Jeff Sharkey85190e62014-12-05 09:40:12 -08002884 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002885 final Phone phone = getPhone(subId);
2886 if (phone == null) {
2887 return false;
2888 }
2889 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002890
2891 if (DBG_MERGE) {
2892 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2893 + subscriberId + " to " + number);
2894 }
2895
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002896 if (TextUtils.isEmpty(iccId)) {
2897 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002898 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002899
Jeff Sharkey85190e62014-12-05 09:40:12 -08002900 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2901
2902 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002903 if (alphaTag == null) {
2904 editor.remove(alphaTagPrefKey);
2905 } else {
2906 editor.putString(alphaTagPrefKey, alphaTag);
2907 }
2908
Jeff Sharkey85190e62014-12-05 09:40:12 -08002909 // Record both the line number and IMSI for this ICCID, since we need to
2910 // track all merged IMSIs based on line number
2911 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2912 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002913 if (number == null) {
2914 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002915 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002916 } else {
2917 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002918 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002919 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002920
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002921 editor.commit();
2922 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002923 }
2924
2925 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002926 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002927 // This is open to apps with WRITE_SMS.
2928 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002929 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002930 return null;
2931 }
Derek Tan97ebb422014-09-05 16:55:38 -07002932
2933 String iccId = getIccId(subId);
2934 if (iccId != null) {
2935 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002936 if (DBG_MERGE) {
2937 log("getLine1NumberForDisplay returning " +
2938 mTelephonySharedPreferences.getString(numberPrefKey, null));
2939 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002940 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002941 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002942 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002943 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002944 }
2945
2946 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002947 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2948 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2949 return null;
2950 }
Derek Tan97ebb422014-09-05 16:55:38 -07002951
2952 String iccId = getIccId(subId);
2953 if (iccId != null) {
2954 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002955 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002956 }
Derek Tan97ebb422014-09-05 16:55:38 -07002957 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002958 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002959
2960 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002961 public String[] getMergedSubscriberIds(String callingPackage) {
2962 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2963 return null;
2964 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002965 final Context context = mPhone.getContext();
2966 final TelephonyManager tele = TelephonyManager.from(context);
2967 final SubscriptionManager sub = SubscriptionManager.from(context);
2968
2969 // Figure out what subscribers are currently active
2970 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002971 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2972 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 final int[] subIds = sub.getActiveSubscriptionIdList();
2976 for (int subId : subIds) {
2977 activeSubscriberIds.add(tele.getSubscriberId(subId));
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002981 }
2982
2983 // First pass, find a number override for an active subscriber
2984 String mergeNumber = null;
2985 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2986 for (String key : prefs.keySet()) {
2987 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2988 final String subscriberId = (String) prefs.get(key);
2989 if (activeSubscriberIds.contains(subscriberId)) {
2990 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2991 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2992 mergeNumber = (String) prefs.get(numberKey);
2993 if (DBG_MERGE) {
2994 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2995 + " for active subscriber " + subscriberId);
2996 }
2997 if (!TextUtils.isEmpty(mergeNumber)) {
2998 break;
2999 }
3000 }
3001 }
3002 }
3003
3004 // Shortcut when no active merged subscribers
3005 if (TextUtils.isEmpty(mergeNumber)) {
3006 return null;
3007 }
3008
3009 // Second pass, find all subscribers under that line override
3010 final ArraySet<String> result = new ArraySet<>();
3011 for (String key : prefs.keySet()) {
3012 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3013 final String number = (String) prefs.get(key);
3014 if (mergeNumber.equals(number)) {
3015 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3016 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3017 final String subscriberId = (String) prefs.get(subscriberKey);
3018 if (!TextUtils.isEmpty(subscriberId)) {
3019 result.add(subscriberId);
3020 }
3021 }
3022 }
3023 }
3024
3025 final String[] resultArray = result.toArray(new String[result.size()]);
3026 Arrays.sort(resultArray);
3027 if (DBG_MERGE) {
3028 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3029 }
3030 return resultArray;
3031 }
3032
3033 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003034 public boolean setOperatorBrandOverride(int subId, String brand) {
3035 enforceCarrierPrivilege(subId);
3036 final Phone phone = getPhone(subId);
3037 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003038 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003039
3040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003041 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003042 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3043 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003044 enforceCarrierPrivilege(subId);
3045 final Phone phone = getPhone(subId);
3046 if (phone == null) {
3047 return false;
3048 }
3049 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003050 cdmaNonRoamingList);
3051 }
3052
3053 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003054 public void setRadioCapability(RadioAccessFamily[] rafs) {
3055 try {
3056 ProxyController.getInstance().setRadioCapability(rafs);
3057 } catch (RuntimeException e) {
3058 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3059 }
3060 }
3061
3062 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003063 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3064 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3065 return RadioAccessFamily.RAF_UNKNOWN;
3066 }
3067
Wink Saville5d475dd2014-10-17 15:00:58 -07003068 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3069 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003070
3071 @Override
3072 public void enableVideoCalling(boolean enable) {
3073 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003074 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003075 }
3076
3077 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003078 public boolean isVideoCallingEnabled(String callingPackage) {
3079 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3080 return false;
3081 }
3082
Andrew Lee77527ac2014-10-21 16:57:39 -07003083 // Check the user preference and the system-level IMS setting. Even if the user has
3084 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3085 // In the long run, we may instead need to check if there exists a connection service
3086 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003087 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3088 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003089 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003090 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003091
Andrew Leea1239f22015-03-02 17:44:07 -08003092 @Override
3093 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003094 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003095 }
3096
3097 @Override
3098 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003099 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003100 }
3101
Andrew Lee9431b832015-03-09 18:46:45 -07003102 @Override
3103 public boolean isTtyModeSupported() {
3104 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3105 TelephonyManager telephonyManager =
3106 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003107 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003108 }
3109
3110 @Override
3111 public boolean isHearingAidCompatibilitySupported() {
3112 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3113 }
3114
Sanket Padawe7310cc72015-01-14 09:53:20 -08003115 /**
3116 * Returns the unique device ID of phone, for example, the IMEI for
3117 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3118 *
3119 * <p>Requires Permission:
3120 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3121 */
3122 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003123 public String getDeviceId(String callingPackage) {
3124 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3125 return null;
3126 }
3127
Sanket Padawe7310cc72015-01-14 09:53:20 -08003128 final Phone phone = PhoneFactory.getPhone(0);
3129 if (phone != null) {
3130 return phone.getDeviceId();
3131 } else {
3132 return null;
3133 }
3134 }
3135
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003136 /*
3137 * {@hide}
3138 * Returns the IMS Registration Status
3139 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003140 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003141 public boolean isImsRegistered() {
3142 return mPhone.isImsRegistered();
3143 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003144
Ping Sunc67b7c22016-03-02 19:16:45 +08003145 /**
3146 * {@hide}
3147 * Returns the IMS Registration Status on a particular subid
3148 *
3149 * @param subId
3150 */
3151 public boolean isImsRegisteredForSubscriber(int subId) {
3152 Phone phone = getPhone(subId);
3153 if (phone != null) {
3154 return phone.isImsRegistered();
3155 } else {
3156 return false;
3157 }
3158 }
3159
Santos Cordon7a1885b2015-02-03 11:15:19 -08003160 @Override
3161 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3162 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3163 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003164
Nathan Haroldc55097a2015-03-11 18:14:50 -07003165 /*
3166 * {@hide}
3167 * Returns the IMS Registration Status
3168 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003169 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003170 return mPhone.isWifiCallingEnabled();
3171 }
3172
3173 /*
3174 * {@hide}
3175 * Returns the IMS Registration Status
3176 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003177 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003178 return mPhone.isVolteEnabled();
3179 }
Svet Ganovb320e182015-04-16 12:30:10 -07003180
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003181 /*
3182 * {@hide} Returns the IMS Registration Status
3183 */
3184 public boolean isVideoTelephonyAvailable() {
3185 return mPhone.isVideoEnabled();
3186 }
3187
Svet Ganovb320e182015-04-16 12:30:10 -07003188 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003189 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003190 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003191 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3192
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003193 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003194 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003195 } catch (SecurityException e) {
3196 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3197 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003198 }
Svet Ganovb320e182015-04-16 12:30:10 -07003199
3200 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3201 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3202 return false;
3203 }
3204
3205 return true;
3206 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003207
Makoto Onukifee69342015-06-29 14:44:50 -07003208 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003209 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003210 */
3211 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003212 // Default SMS app can always read it.
3213 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3214 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3215 return true;
3216 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003217
Makoto Onukie4072d12015-08-03 15:12:23 -07003218 try {
3219 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003220 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003221 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003222 // Can be read with READ_SMS too.
3223 try {
3224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3225 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3226 if (opCode != AppOpsManager.OP_NONE) {
3227 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3228 == AppOpsManager.MODE_ALLOWED;
3229 } else {
3230 return true;
3231 }
3232 } catch (SecurityException readSmsSecurityException) {
3233 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003234 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003235 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003236 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003237 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003238 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003239 if (opCode != AppOpsManager.OP_NONE) {
3240 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3241 == AppOpsManager.MODE_ALLOWED;
3242 } else {
3243 return true;
3244 }
3245 } catch (SecurityException readPhoneNumberSecurityException) {
3246 }
3247
3248 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3249 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3250 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003251 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003252 }
3253
Stuart Scott8eef64f2015-04-08 15:13:54 -07003254 @Override
3255 public void factoryReset(int subId) {
3256 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003257 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3258 return;
3259 }
3260
Svet Ganovcc087f82015-05-12 20:35:54 -07003261 final long identity = Binder.clearCallingIdentity();
3262 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003263 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3264 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003265 // Enable data
3266 setDataEnabled(subId, true);
3267 // Set network selection mode to automatic
3268 setNetworkSelectionModeAutomatic(subId);
3269 // Set preferred mobile network type to the best available
3270 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3271 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003272 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003273 // Remove IMSI encryption keys from Carrier DB.
3274 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003275 }
3276 } finally {
3277 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003278 }
3279 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003280
3281 @Override
3282 public String getLocaleFromDefaultSim() {
3283 // We query all subscriptions instead of just the active ones, because
3284 // this might be called early on in the provisioning flow when the
3285 // subscriptions potentially aren't active yet.
3286 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3287 if (slist == null || slist.isEmpty()) {
3288 return null;
3289 }
3290
3291 // This function may be called very early, say, from the setup wizard, at
3292 // which point we won't have a default subscription set. If that's the case
3293 // we just choose the first, which will be valid in "most cases".
3294 final int defaultSubId = getDefaultSubscription();
3295 SubscriptionInfo info = null;
3296 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3297 info = slist.get(0);
3298 } else {
3299 for (SubscriptionInfo item : slist) {
3300 if (item.getSubscriptionId() == defaultSubId) {
3301 info = item;
3302 break;
3303 }
3304 }
3305
3306 if (info == null) {
3307 return null;
3308 }
3309 }
3310
3311 // Try and fetch the locale from the carrier properties or from the SIM language
3312 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003313 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003314 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003315 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003316 if (defaultPhone != null) {
3317 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3318 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003319 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003320 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3321 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003322 } else {
3323 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003324 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003325 }
3326 }
3327
Narayan Kamath011676f2015-07-29 12:04:08 +01003328 // The SIM language preferences only store a language (e.g. fr = French), not an
3329 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3330 // the SIM and carrier preferences does not include a country we add the country
3331 // determined from the SIM MCC to provide an exact locale.
3332 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003333 if (mccLocale != null) {
3334 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3335 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003336 }
3337
Tony Hill183b2de2015-06-24 14:53:58 +01003338 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003339 return null;
3340 }
3341
3342 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 return mSubscriptionController.getAllSubInfoList(
3346 mPhone.getContext().getOpPackageName());
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
3352 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 return mSubscriptionController.getActiveSubscriptionInfoList(
3356 mPhone.getContext().getOpPackageName());
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
3359 }
3360 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003361
3362 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003363 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3364 * representing the state of the modem.
3365 *
3366 * NOTE: This clears the modem state, so there should only every be one caller.
3367 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003368 */
3369 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003370 public void requestModemActivityInfo(ResultReceiver result) {
3371 enforceModifyPermission();
3372
3373 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3374 Bundle bundle = new Bundle();
3375 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3376 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003377 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003378
3379 /**
3380 * {@hide}
3381 * Returns the service state information on specified subscription.
3382 */
3383 @Override
3384 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3385
3386 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3387 return null;
3388 }
3389
3390 final Phone phone = getPhone(subId);
3391 if (phone == null) {
3392 return null;
3393 }
3394
3395 return phone.getServiceState();
3396 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003397
3398 /**
3399 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3400 *
3401 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3402 * voicemail ringtone.
3403 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3404 * PhoneAccount.
3405 */
3406 @Override
3407 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003408 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003409 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003410 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003411 }
3412
fionaxu7ed723d2017-05-30 18:58:54 -07003413 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003414 }
3415
3416 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003417 * Sets the per-account voicemail ringtone.
3418 *
3419 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3420 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3421 *
3422 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3423 * voicemail ringtone.
3424 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3425 * PhoneAccount.
3426 */
3427 @Override
3428 public void setVoicemailRingtoneUri(String callingPackage,
3429 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3431 if (!TextUtils.equals(callingPackage,
3432 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3433 enforceModifyPermissionOrCarrierPrivilege(
3434 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3435 }
3436 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3437 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003438 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003439 }
fionaxu7ed723d2017-05-30 18:58:54 -07003440 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003441 }
3442
3443 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003444 * Returns whether vibration is set for voicemail notification in Phone settings.
3445 *
3446 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3447 * voicemail vibration setting.
3448 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3449 */
3450 @Override
3451 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003452 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003453 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003454 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003455 }
3456
fionaxu7ed723d2017-05-30 18:58:54 -07003457 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003458 }
3459
Youhan Wange64578a2016-05-02 15:32:42 -07003460 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003461 * Sets the per-account voicemail vibration.
3462 *
3463 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3464 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3465 *
3466 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3467 * voicemail vibration setting.
3468 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3469 * specific PhoneAccount.
3470 */
3471 @Override
3472 public void setVoicemailVibrationEnabled(String callingPackage,
3473 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3475 if (!TextUtils.equals(callingPackage,
3476 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3477 enforceModifyPermissionOrCarrierPrivilege(
3478 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3479 }
3480
3481 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3482 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003483 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003484 }
fionaxu7ed723d2017-05-30 18:58:54 -07003485 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003486 }
3487
3488 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003489 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3490 *
3491 * @throws SecurityException if the caller does not have the required permission
3492 */
3493 private void enforceReadPrivilegedPermission() {
3494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3495 null);
3496 }
3497
3498 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003499 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3500 * permission.
3501 *
3502 * @throws SecurityException if the caller does not have the required permission
3503 */
3504 private void enforceSendSmsPermission() {
3505 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3506 }
3507
3508 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003509 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003510 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003511 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003512 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003513 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003514 ComponentName componentName =
3515 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3516 if(componentName == null) {
3517 throw new SecurityException("Caller not current active visual voicemail package[null]");
3518 }
3519 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003520 if (!callingPackage.equals(vvmPackage)) {
3521 throw new SecurityException("Caller not current active visual voicemail package[" +
3522 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 }
3524 }
3525
3526 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003527 * Return the application ID for the app type.
3528 *
3529 * @param subId the subscription ID that this request applies to.
3530 * @param appType the uicc app type.
3531 * @return Application ID for specificied app type, or null if no uicc.
3532 */
3533 @Override
3534 public String getAidForAppType(int subId, int appType) {
3535 enforceReadPrivilegedPermission();
3536 Phone phone = getPhone(subId);
3537 if (phone == null) {
3538 return null;
3539 }
3540 String aid = null;
3541 try {
3542 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3543 .getApplicationByType(appType).getAid();
3544 } catch (Exception e) {
3545 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3546 }
3547 return aid;
3548 }
3549
Youhan Wang4001d252016-05-11 10:29:41 -07003550 /**
3551 * Return the Electronic Serial Number.
3552 *
3553 * @param subId the subscription ID that this request applies to.
3554 * @return ESN or null if error.
3555 */
3556 @Override
3557 public String getEsn(int subId) {
3558 enforceReadPrivilegedPermission();
3559 Phone phone = getPhone(subId);
3560 if (phone == null) {
3561 return null;
3562 }
3563 String esn = null;
3564 try {
3565 esn = phone.getEsn();
3566 } catch (Exception e) {
3567 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3568 }
3569 return esn;
3570 }
3571
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003572 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003573 * Return the Preferred Roaming List Version.
3574 *
3575 * @param subId the subscription ID that this request applies to.
3576 * @return PRLVersion or null if error.
3577 */
3578 @Override
3579 public String getCdmaPrlVersion(int subId) {
3580 enforceReadPrivilegedPermission();
3581 Phone phone = getPhone(subId);
3582 if (phone == null) {
3583 return null;
3584 }
3585 String cdmaPrlVersion = null;
3586 try {
3587 cdmaPrlVersion = phone.getCdmaPrlVersion();
3588 } catch (Exception e) {
3589 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3590 }
3591 return cdmaPrlVersion;
3592 }
3593
3594 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003595 * Get snapshot of Telephony histograms
3596 * @return List of Telephony histograms
3597 * @hide
3598 */
3599 @Override
3600 public List<TelephonyHistogram> getTelephonyHistograms() {
3601 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3602 return RIL.getTelephonyRILTimingHistograms();
3603 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003604
3605 /**
3606 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003607 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003608 * Require system privileges. In the future we may add this to carrier APIs.
3609 *
3610 * @return The number of carriers set successfully, should match length of carriers
3611 */
3612 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003613 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003614 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003615
Meng Wang9b7c4e92017-02-17 11:41:27 -08003616 if (carriers == null) {
3617 throw new NullPointerException("carriers cannot be null");
3618 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003619
3620 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003621 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3622 return retVal[0];
3623 }
3624
3625 /**
3626 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003627 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003628 * Require system privileges. In the future we may add this to carrier APIs.
3629 *
3630 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3631 * means all carriers are allowed.
3632 */
3633 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003634 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003635 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003636 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003637 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3638 }
3639
fionaxu59545b42016-05-25 15:53:37 -07003640 /**
3641 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3642 * @param subId the subscription ID that this action applies to.
3643 * @param enabled control enable or disable metered apns.
3644 * {@hide}
3645 */
3646 @Override
3647 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3648 enforceModifyPermission();
3649 final Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3652 return;
3653 }
3654 try {
3655 phone.carrierActionSetMeteredApnsEnabled(enabled);
3656 } catch (Exception e) {
3657 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3658 }
3659 }
3660
3661 /**
3662 * Action set from carrier signalling broadcast receivers to enable/disable radio
3663 * @param subId the subscription ID that this action applies to.
3664 * @param enabled control enable or disable radio.
3665 * {@hide}
3666 */
3667 @Override
3668 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3669 enforceModifyPermission();
3670 final Phone phone = getPhone(subId);
3671 if (phone == null) {
3672 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3673 return;
3674 }
3675 try {
3676 phone.carrierActionSetRadioEnabled(enabled);
3677 } catch (Exception e) {
3678 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3679 }
3680 }
3681
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003682 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003683 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3684 * network status based on which carrier apps could apply actions accordingly,
3685 * enable/disable default url handler for example.
3686 *
3687 * @param subId the subscription ID that this action applies to.
3688 * @param report control start/stop reporting the default network status.
3689 * {@hide}
3690 */
3691 @Override
3692 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3693 enforceModifyPermission();
3694 final Phone phone = getPhone(subId);
3695 if (phone == null) {
3696 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3697 return;
3698 }
3699 try {
3700 phone.carrierActionReportDefaultNetworkStatus(report);
3701 } catch (Exception e) {
3702 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3703 }
3704 }
3705
3706 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003707 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3708 * bug report is being generated.
3709 */
3710 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003711 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003712 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3713 != PackageManager.PERMISSION_GRANTED) {
3714 writer.println("Permission Denial: can't dump Phone from pid="
3715 + Binder.getCallingPid()
3716 + ", uid=" + Binder.getCallingUid()
3717 + "without permission "
3718 + android.Manifest.permission.DUMP);
3719 return;
3720 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003721 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003722 }
Jack Yueb89b242016-06-22 13:27:47 -07003723
3724 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003725 * Get aggregated video call data usage since boot.
3726 *
3727 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3728 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003729 * {@hide}
3730 */
3731 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003732 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3734 null);
3735
Jack Yu84291ec2017-05-26 16:07:50 -07003736 // NetworkStatsService keeps tracking the active network interface and identity. It
3737 // records the delta with the corresponding network identity. We just return the total video
3738 // call data usage snapshot since boot.
3739 Phone phone = getPhone(subId);
3740 if (phone != null) {
3741 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003742 }
Jack Yu84291ec2017-05-26 16:07:50 -07003743 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003744 }
Jack Yu75ab2952016-07-08 14:29:33 -07003745
3746 /**
3747 * Policy control of data connection. Usually used when data limit is passed.
3748 * @param enabled True if enabling the data, otherwise disabling.
3749 * @param subId Subscription index
3750 * {@hide}
3751 */
3752 @Override
3753 public void setPolicyDataEnabled(boolean enabled, int subId) {
3754 enforceModifyPermission();
3755 Phone phone = getPhone(subId);
3756 if (phone != null) {
3757 phone.setPolicyDataEnabled(enabled);
3758 }
3759 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003760
3761 /**
3762 * Get Client request stats
3763 * @return List of Client Request Stats
3764 * @hide
3765 */
3766 @Override
3767 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3768 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3769 return null;
3770 }
3771
3772 Phone phone = getPhone(subId);
3773 if (phone != null) {
3774 return phone.getClientRequestStats();
3775 }
3776
3777 return null;
3778 }
3779
3780 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3781 if (workSource != null) {
3782 return workSource;
3783 }
3784
3785 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3786 workSource = new WorkSource(uid, packageName);
3787 return workSource;
3788 }
Jack Yueb4124c2017-02-16 15:32:43 -08003789
3790 /**
Grace Chen70990072017-03-24 17:21:30 -07003791 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003792 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003793 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003794 * @param state State of SIM (power down, power up, pass through)
3795 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3796 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3797 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003798 *
3799 **/
3800 @Override
Grace Chen70990072017-03-24 17:21:30 -07003801 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003802 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003803 Phone phone = PhoneFactory.getPhone(slotIndex);
3804
Jack Yueb4124c2017-02-16 15:32:43 -08003805 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003806 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003807 }
3808 }
Shuo Qiandd210312017-04-12 22:11:33 +00003809
Tyler Gunn65d45c22017-06-05 11:22:26 -07003810 private boolean isUssdApiAllowed(int subId) {
3811 CarrierConfigManager configManager =
3812 (CarrierConfigManager) mPhone.getContext().getSystemService(
3813 Context.CARRIER_CONFIG_SERVICE);
3814 if (configManager == null) {
3815 return false;
3816 }
3817 PersistableBundle pb = configManager.getConfigForSubId(subId);
3818 if (pb == null) {
3819 return false;
3820 }
3821 return pb.getBoolean(
3822 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3823 }
3824
Shuo Qiandd210312017-04-12 22:11:33 +00003825 /**
3826 * Check if phone is in emergency callback mode
3827 * @return true if phone is in emergency callback mode
3828 * @param subId sub id
3829 */
3830 public boolean getEmergencyCallbackMode(int subId) {
3831 final Phone phone = getPhone(subId);
3832 if (phone != null) {
3833 return phone.isInEcm();
3834 } else {
3835 return false;
3836 }
3837 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003838
3839 /**
3840 * Get the current signal strength information for the given subscription.
3841 * Because this information is not updated when the device is in a low power state
3842 * it should not be relied-upon to be current.
3843 * @param subId Subscription index
3844 * @return the most recent cached signal strength info from the modem
3845 */
3846 @Override
3847 public SignalStrength getSignalStrength(int subId) {
3848 Phone p = getPhone(subId);
3849 if (p == null) {
3850 return null;
3851 }
3852
3853 return p.getSignalStrength();
3854 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855}