blob: ea57c8104714e557a69f6192986b98312e91b280 [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;
Shishir Agrawal302c8692015-06-19 13:49:39 -070082import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070083import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080086import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010087import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070088import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080091import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070093import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070094import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070095import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070096import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080097import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -070098import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -070099import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700100import com.android.internal.telephony.uicc.IccIoResult;
101import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800102import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700103import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800104import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700106import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800107import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700108import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800109import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700110import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700111import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700113import java.io.FileDescriptor;
114import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800118import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100119import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121
122/**
123 * Implementation of the ITelephony interface.
124 */
Santos Cordon117fee72014-05-16 17:56:12 -0700125public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 private static final String LOG_TAG = "PhoneInterfaceManager";
127 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
128 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130
131 // Message codes used with mMainThreadHandler
132 private static final int CMD_HANDLE_PIN_MMI = 1;
133 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
134 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
135 private static final int CMD_ANSWER_RINGING_CALL = 4;
136 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700137 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
138 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139 private static final int CMD_OPEN_CHANNEL = 9;
140 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
141 private static final int CMD_CLOSE_CHANNEL = 11;
142 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800143 private static final int CMD_NV_READ_ITEM = 13;
144 private static final int EVENT_NV_READ_ITEM_DONE = 14;
145 private static final int CMD_NV_WRITE_ITEM = 15;
146 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
147 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
148 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
149 private static final int CMD_NV_RESET_CONFIG = 19;
150 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800151 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
152 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
153 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
154 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800155 private static final int CMD_SEND_ENVELOPE = 25;
156 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700157 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
158 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
159 private static final int CMD_EXCHANGE_SIM_IO = 31;
160 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800161 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
162 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700163 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
164 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700165 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
166 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700167 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
168 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
169 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
170 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700171 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
172 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
173 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
174 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700175 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800176 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
177 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 /** The singleton instance. */
180 private static PhoneInterfaceManager sInstance;
181
Wink Saville3ab207e2014-11-20 13:07:20 -0800182 private PhoneGlobals mApp;
183 private Phone mPhone;
184 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700185 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800186 private AppOpsManager mAppOps;
187 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800188 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
Derek Tan97ebb422014-09-05 16:55:38 -0700191 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
192 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700194
Derek Tan740e1672017-06-27 14:56:27 -0700195 // The AID of ISD-R.
196 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
197
yinxub1bed742017-04-17 11:45:04 -0700198 private NetworkScanRequestTracker mNetworkScanRequestTracker;
199
Derek Tan89e89d42014-07-08 17:00:10 -0700200 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 * A request object to use for transmitting data to an ICC.
202 */
203 private static final class IccAPDUArgument {
204 public int channel, cla, command, p1, p2, p3;
205 public String data;
206
207 public IccAPDUArgument(int channel, int cla, int command,
208 int p1, int p2, int p3, String data) {
209 this.channel = channel;
210 this.cla = cla;
211 this.command = command;
212 this.p1 = p1;
213 this.p2 = p2;
214 this.p3 = p3;
215 this.data = data;
216 }
217 }
218
219 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700220 * A request object to use for transmitting data to an ICC.
221 */
222 private static final class ManualNetworkSelectionArgument {
223 public OperatorInfo operatorInfo;
224 public boolean persistSelection;
225
226 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
227 this.operatorInfo = operatorInfo;
228 this.persistSelection = persistSelection;
229 }
230 }
231
232 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
234 * request after sending. The main thread will notify the request when it is complete.
235 */
236 private static final class MainThreadRequest {
237 /** The argument to use for the request */
238 public Object argument;
239 /** The result of the request that is run on the main thread */
240 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800241 // The subscriber id that this request applies to. Defaults to
242 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
243 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245 public MainThreadRequest(Object argument) {
246 this.argument = argument;
247 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800248
249 public MainThreadRequest(Object argument, Integer subId) {
250 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800251 if (subId != null) {
252 this.subId = subId;
253 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 }
256
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800257 private static final class IncomingThirdPartyCallArgs {
258 public final ComponentName component;
259 public final String callId;
260 public final String callerDisplayName;
261
262 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
263 String callerDisplayName) {
264 this.component = component;
265 this.callId = callId;
266 this.callerDisplayName = callerDisplayName;
267 }
268 }
269
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 /**
271 * A handler that processes messages on the main thread in the phone process. Since many
272 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
273 * inbound binder threads to the main thread in the phone process. The Binder thread
274 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
275 * on, which will be notified when the operation completes and will contain the result of the
276 * request.
277 *
278 * <p>If a MainThreadRequest object is provided in the msg.obj field,
279 * note that request.result must be set to something non-null for the calling thread to
280 * unblock.
281 */
282 private final class MainThreadHandler extends Handler {
283 @Override
284 public void handleMessage(Message msg) {
285 MainThreadRequest request;
286 Message onCompleted;
287 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800288 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700289 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
291 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700292 case CMD_HANDLE_USSD_REQUEST: {
293 request = (MainThreadRequest) msg.obj;
294 final Phone phone = getPhoneFromRequest(request);
295 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
296 String ussdRequest = ussdObject.first;
297 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700298
299 if (!isUssdApiAllowed(request.subId)) {
300 // Carrier does not support use of this API, return failure.
301 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
302 UssdResponse response = new UssdResponse(ussdRequest, null);
303 Bundle returnData = new Bundle();
304 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
305 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
306
307 request.result = true;
308 synchronized (request) {
309 request.notifyAll();
310 }
311 return;
312 }
313
Tyler Gunn52dcf772017-04-26 11:30:31 -0700314 try {
315 request.result = phone != null ?
316 phone.handleUssdRequest(ussdRequest, wrappedCallback)
317 : false;
318 } catch (CallStateException cse) {
319 request.result = false;
320 }
pkanwar32d516d2016-10-14 19:37:38 -0700321 // Wake up the requesting thread
322 synchronized (request) {
323 request.notifyAll();
324 }
325 break;
326 }
327
Yorke Lee716f67e2015-06-17 15:39:16 -0700328 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700330 final Phone phone = getPhoneFromRequest(request);
331 request.result = phone != null ?
332 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
333 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 // Wake up the requesting thread
335 synchronized (request) {
336 request.notifyAll();
337 }
338 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700340
341 case CMD_HANDLE_NEIGHBORING_CELL:
342 request = (MainThreadRequest) msg.obj;
343 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
344 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700345 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 break;
347
348 case EVENT_NEIGHBORING_CELL_DONE:
349 ar = (AsyncResult) msg.obj;
350 request = (MainThreadRequest) ar.userObj;
351 if (ar.exception == null && ar.result != null) {
352 request.result = ar.result;
353 } else {
354 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800355 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 }
357 // Wake up the requesting thread
358 synchronized (request) {
359 request.notifyAll();
360 }
361 break;
362
363 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700364 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800365 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700366 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 break;
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 case CMD_END_CALL:
370 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800371 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700372 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700373 Phone phone = getPhone(end_subId);
374 if (phone == null) {
375 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
376 break;
377 }
378 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
380 // CDMA: If the user presses the Power button we treat it as
381 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700382 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
384 // GSM: End the call as per the Phone state
385 hungUp = PhoneUtils.hangup(mCM);
386 } else {
387 throw new IllegalStateException("Unexpected phone type: " + phoneType);
388 }
389 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
390 request.result = hungUp;
391 // Wake up the requesting thread
392 synchronized (request) {
393 request.notifyAll();
394 }
395 break;
396
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700397 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700398 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800400 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700401 if (uiccCard == null) {
402 loge("iccTransmitApduLogicalChannel: No UICC");
403 request.result = new IccIoResult(0x6F, 0, (byte[])null);
404 synchronized (request) {
405 request.notifyAll();
406 }
407 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700408 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
409 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700410 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 iccArgument.channel, iccArgument.cla, iccArgument.command,
412 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 break;
416
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 ar = (AsyncResult) msg.obj;
419 request = (MainThreadRequest) ar.userObj;
420 if (ar.exception == null && ar.result != null) {
421 request.result = ar.result;
422 } else {
423 request.result = new IccIoResult(0x6F, 0, (byte[])null);
424 if (ar.result == null) {
425 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800426 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800428 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 } else {
430 loge("iccTransmitApduLogicalChannel: Unknown exception");
431 }
432 }
433 synchronized (request) {
434 request.notifyAll();
435 }
436 break;
437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
439 request = (MainThreadRequest) msg.obj;
440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 if (uiccCard == null) {
443 loge("iccTransmitApduBasicChannel: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
445 synchronized (request) {
446 request.notifyAll();
447 }
448 } else {
449 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
450 request);
451 uiccCard.iccTransmitApduBasicChannel(
452 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
453 iccArgument.p3, iccArgument.data, onCompleted);
454 }
455 break;
456
457 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
458 ar = (AsyncResult) msg.obj;
459 request = (MainThreadRequest) ar.userObj;
460 if (ar.exception == null && ar.result != null) {
461 request.result = ar.result;
462 } else {
463 request.result = new IccIoResult(0x6F, 0, (byte[])null);
464 if (ar.result == null) {
465 loge("iccTransmitApduBasicChannel: Empty response");
466 } else if (ar.exception instanceof CommandException) {
467 loge("iccTransmitApduBasicChannel: CommandException: " +
468 ar.exception);
469 } else {
470 loge("iccTransmitApduBasicChannel: Unknown exception");
471 }
472 }
473 synchronized (request) {
474 request.notifyAll();
475 }
476 break;
477
478 case CMD_EXCHANGE_SIM_IO:
479 request = (MainThreadRequest) msg.obj;
480 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800481 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 if (uiccCard == null) {
483 loge("iccExchangeSimIO: No UICC");
484 request.result = new IccIoResult(0x6F, 0, (byte[])null);
485 synchronized (request) {
486 request.notifyAll();
487 }
488 } else {
489 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
490 request);
491 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
492 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
493 iccArgument.data, onCompleted);
494 }
495 break;
496
497 case EVENT_EXCHANGE_SIM_IO_DONE:
498 ar = (AsyncResult) msg.obj;
499 request = (MainThreadRequest) ar.userObj;
500 if (ar.exception == null && ar.result != null) {
501 request.result = ar.result;
502 } else {
503 request.result = new IccIoResult(0x6f, 0, (byte[])null);
504 }
505 synchronized (request) {
506 request.notifyAll();
507 }
508 break;
509
Derek Tan4d5e5c12014-02-04 11:54:58 -0800510 case CMD_SEND_ENVELOPE:
511 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800512 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 if (uiccCard == null) {
514 loge("sendEnvelopeWithStatus: No UICC");
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
516 synchronized (request) {
517 request.notifyAll();
518 }
519 } else {
520 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
521 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
522 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 break;
524
525 case EVENT_SEND_ENVELOPE_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 if (ar.result == null) {
533 loge("sendEnvelopeWithStatus: Empty response");
534 } else if (ar.exception instanceof CommandException) {
535 loge("sendEnvelopeWithStatus: CommandException: " +
536 ar.exception);
537 } else {
538 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 }
541 synchronized (request) {
542 request.notifyAll();
543 }
544 break;
545
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 case CMD_OPEN_CHANNEL:
547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800549 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800552 request.result = new IccOpenLogicalChannelResponse(-1,
553 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 synchronized (request) {
555 request.notifyAll();
556 }
557 } else {
558 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800559 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
560 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
564 case EVENT_OPEN_CHANNEL_DONE:
565 ar = (AsyncResult) msg.obj;
566 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 int[] result = (int[]) ar.result;
570 int channelId = result[0];
571 byte[] selectResponse = null;
572 if (result.length > 1) {
573 selectResponse = new byte[result.length - 1];
574 for (int i = 1; i < result.length; ++i) {
575 selectResponse[i - 1] = (byte) result[i];
576 }
577 }
578 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700579 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.result == null) {
582 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 if (ar.exception != null) {
585 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
586 }
587
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700589 if (ar.exception instanceof CommandException) {
590 CommandException.Error error =
591 ((CommandException) (ar.exception)).getCommandError();
592 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700594 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(
599 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700601 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 synchronized (request) {
603 request.notifyAll();
604 }
605 break;
606
607 case CMD_CLOSE_CHANNEL:
608 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800609 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 if (uiccCard == null) {
611 loge("iccCloseLogicalChannel: No UICC");
612 request.result = new IccIoResult(0x6F, 0, (byte[])null);
613 synchronized (request) {
614 request.notifyAll();
615 }
616 } else {
617 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
618 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
619 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800623 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
624 break;
625
626 case CMD_NV_READ_ITEM:
627 request = (MainThreadRequest) msg.obj;
628 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
629 mPhone.nvReadItem((Integer) request.argument, onCompleted);
630 break;
631
632 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 ar = (AsyncResult) msg.obj;
634 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800635 if (ar.exception == null && ar.result != null) {
636 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800638 request.result = "";
639 if (ar.result == null) {
640 loge("nvReadItem: Empty response");
641 } else if (ar.exception instanceof CommandException) {
642 loge("nvReadItem: CommandException: " +
643 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
647 }
648 synchronized (request) {
649 request.notifyAll();
650 }
651 break;
652
Jake Hambye994d462014-02-03 13:10:13 -0800653 case CMD_NV_WRITE_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
656 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
657 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
658 break;
659
660 case EVENT_NV_WRITE_ITEM_DONE:
661 handleNullReturnEvent(msg, "nvWriteItem");
662 break;
663
664 case CMD_NV_WRITE_CDMA_PRL:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
667 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
668 break;
669
670 case EVENT_NV_WRITE_CDMA_PRL_DONE:
671 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
672 break;
673
674 case CMD_NV_RESET_CONFIG:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
677 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
678 break;
679
680 case EVENT_NV_RESET_CONFIG_DONE:
681 handleNullReturnEvent(msg, "nvResetConfig");
682 break;
683
Jake Hamby7c27be32014-03-03 13:25:59 -0800684 case CMD_GET_PREFERRED_NETWORK_TYPE:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700687 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 break;
689
690 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result; // Integer
695 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800696 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 if (ar.result == null) {
698 loge("getPreferredNetworkType: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("getPreferredNetworkType: CommandException: " +
701 ar.exception);
702 } else {
703 loge("getPreferredNetworkType: Unknown exception");
704 }
705 }
706 synchronized (request) {
707 request.notifyAll();
708 }
709 break;
710
711 case CMD_SET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
714 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700715 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
719 handleNullReturnEvent(msg, "setPreferredNetworkType");
720 break;
721
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800722 case CMD_SET_VOICEMAIL_NUMBER:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
725 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800726 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
727 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800728 break;
729
730 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
731 handleNullReturnEvent(msg, "setVoicemailNumber");
732 break;
733
Stuart Scott54788802015-03-30 13:18:01 -0700734 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
737 request);
738 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
739 break;
740
741 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
742 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
743 break;
744
Shishir Agrawal302c8692015-06-19 13:49:39 -0700745 case CMD_PERFORM_NETWORK_SCAN:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
748 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
749 break;
750
751 case EVENT_PERFORM_NETWORK_SCAN_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
754 CellNetworkScanResult cellScanResult;
755 if (ar.exception == null && ar.result != null) {
756 cellScanResult = new CellNetworkScanResult(
757 CellNetworkScanResult.STATUS_SUCCESS,
758 (List<OperatorInfo>) ar.result);
759 } else {
760 if (ar.result == null) {
761 loge("getCellNetworkScanResults: Empty response");
762 }
763 if (ar.exception != null) {
764 loge("getCellNetworkScanResults: Exception: " + ar.exception);
765 }
766 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
767 if (ar.exception instanceof CommandException) {
768 CommandException.Error error =
769 ((CommandException) (ar.exception)).getCommandError();
770 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
771 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
772 } else if (error == CommandException.Error.GENERIC_FAILURE) {
773 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
774 }
775 }
776 cellScanResult = new CellNetworkScanResult(errorCode, null);
777 }
778 request.result = cellScanResult;
779 synchronized (request) {
780 request.notifyAll();
781 }
782 break;
783
784 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
785 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700786 ManualNetworkSelectionArgument selArg =
787 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
789 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700790 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
791 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700792 break;
793
794 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
795 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
796 break;
797
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700798 case CMD_GET_MODEM_ACTIVITY_INFO:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700801 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700802 break;
803
804 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null && ar.result != null) {
808 request.result = ar.result;
809 } else {
810 if (ar.result == null) {
811 loge("queryModemActivityInfo: Empty response");
812 } else if (ar.exception instanceof CommandException) {
813 loge("queryModemActivityInfo: CommandException: " +
814 ar.exception);
815 } else {
816 loge("queryModemActivityInfo: Unknown exception");
817 }
818 }
Amit Mahajand4766222016-01-28 15:28:28 -0800819 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
820 if (request.result == null) {
821 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
822 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 synchronized (request) {
824 request.notifyAll();
825 }
826 break;
827
Meng Wang1a7c35a2016-05-05 20:56:15 -0700828 case CMD_SET_ALLOWED_CARRIERS:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
831 mPhone.setAllowedCarriers(
832 (List<CarrierIdentifier>) request.argument,
833 onCompleted);
834 break;
835
836 case EVENT_SET_ALLOWED_CARRIERS_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 if (ar.result == null) {
843 loge("setAllowedCarriers: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("setAllowedCarriers: CommandException: " +
846 ar.exception);
847 } else {
848 loge("setAllowedCarriers: Unknown exception");
849 }
850 }
851 // Result cannot be null. Return -1 on error.
852 if (request.result == null) {
853 request.result = new int[]{-1};
854 }
855 synchronized (request) {
856 request.notifyAll();
857 }
858 break;
859
860 case CMD_GET_ALLOWED_CARRIERS:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
863 mPhone.getAllowedCarriers(onCompleted);
864 break;
865
866 case EVENT_GET_ALLOWED_CARRIERS_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
872 if (ar.result == null) {
873 loge("getAllowedCarriers: Empty response");
874 } else if (ar.exception instanceof CommandException) {
875 loge("getAllowedCarriers: CommandException: " +
876 ar.exception);
877 } else {
878 loge("getAllowedCarriers: Unknown exception");
879 }
880 }
881 // Result cannot be null. Return empty list of CarrierIdentifier.
882 if (request.result == null) {
883 request.result = new ArrayList<CarrierIdentifier>(0);
884 }
885 synchronized (request) {
886 request.notifyAll();
887 }
888 break;
889
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result;
895 } else {
896 request.result = new IllegalArgumentException(
897 "Failed to retrieve Forbidden Plmns");
898 if (ar.result == null) {
899 loge("getForbiddenPlmns: Empty response");
900 } else {
901 loge("getForbiddenPlmns: Unknown exception");
902 }
903 }
904 synchronized (request) {
905 request.notifyAll();
906 }
907 break;
908
909 case CMD_GET_FORBIDDEN_PLMNS:
910 request = (MainThreadRequest) msg.obj;
911 uiccCard = getUiccCardFromRequest(request);
912 if (uiccCard == null) {
913 loge("getForbiddenPlmns() UiccCard is null");
914 request.result = new IllegalArgumentException(
915 "getForbiddenPlmns() UiccCard is null");
916 synchronized (request) {
917 request.notifyAll();
918 }
919 break;
920 }
921 Integer appType = (Integer) request.argument;
922 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
923 if (uiccApp == null) {
924 loge("getForbiddenPlmns() no app with specified type -- "
925 + appType);
926 request.result = new IllegalArgumentException("Failed to get UICC App");
927 synchronized (request) {
928 request.notifyAll();
929 }
930 break;
931 } else {
932 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
933 + " specified type -- " + appType);
934 }
935 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
936 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
937 onCompleted);
938 break;
939
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700940 default:
941 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
942 break;
943 }
944 }
Jake Hambye994d462014-02-03 13:10:13 -0800945
946 private void handleNullReturnEvent(Message msg, String command) {
947 AsyncResult ar = (AsyncResult) msg.obj;
948 MainThreadRequest request = (MainThreadRequest) ar.userObj;
949 if (ar.exception == null) {
950 request.result = true;
951 } else {
952 request.result = false;
953 if (ar.exception instanceof CommandException) {
954 loge(command + ": CommandException: " + ar.exception);
955 } else {
956 loge(command + ": Unknown exception");
957 }
958 }
959 synchronized (request) {
960 request.notifyAll();
961 }
962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 }
964
965 /**
966 * Posts the specified command to be executed on the main thread,
967 * waits for the request to complete, and returns the result.
968 * @see #sendRequestAsync
969 */
970 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800971 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700972 }
973
974 /**
975 * Posts the specified command to be executed on the main thread,
976 * waits for the request to complete, and returns the result.
977 * @see #sendRequestAsync
978 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800979 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700980 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
981 throw new RuntimeException("This method will deadlock if called from the main thread.");
982 }
983
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800984 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700985 Message msg = mMainThreadHandler.obtainMessage(command, request);
986 msg.sendToTarget();
987
988 // Wait for the request to complete
989 synchronized (request) {
990 while (request.result == null) {
991 try {
992 request.wait();
993 } catch (InterruptedException e) {
994 // Do nothing, go back and wait until the request is complete
995 }
996 }
997 }
998 return request.result;
999 }
1000
1001 /**
1002 * Asynchronous ("fire and forget") version of sendRequest():
1003 * Posts the specified command to be executed on the main thread, and
1004 * returns immediately.
1005 * @see #sendRequest
1006 */
1007 private void sendRequestAsync(int command) {
1008 mMainThreadHandler.sendEmptyMessage(command);
1009 }
1010
1011 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001012 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1013 * @see {@link #sendRequest(int,Object)}
1014 */
1015 private void sendRequestAsync(int command, Object argument) {
1016 MainThreadRequest request = new MainThreadRequest(argument);
1017 Message msg = mMainThreadHandler.obtainMessage(command, request);
1018 msg.sendToTarget();
1019 }
1020
1021 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001022 * Initialize the singleton PhoneInterfaceManager instance.
1023 * This is only done once, at startup, from PhoneApp.onCreate().
1024 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001025 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 synchronized (PhoneInterfaceManager.class) {
1027 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001028 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001029 } else {
1030 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1031 }
1032 return sInstance;
1033 }
1034 }
1035
1036 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001037 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038 mApp = app;
1039 mPhone = phone;
1040 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001041 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1043 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001044 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001045 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001046 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001047 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001049 publish();
1050 }
1051
1052 private void publish() {
1053 if (DBG) log("publish: " + this);
1054
1055 ServiceManager.addService("phone", this);
1056 }
1057
Stuart Scott584921c2015-01-15 17:10:34 -08001058 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001059 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1060 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001061 }
1062
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001063 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1064 Phone phone = getPhoneFromRequest(request);
1065 return phone == null ? null :
1066 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1067 }
1068
Wink Saville36469e72014-06-11 15:17:00 -07001069 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001070 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001071 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 //
1074 // Implementation of the ITelephony interface.
1075 //
1076
1077 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001078 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001079 }
1080
Wink Savilleb564aae2014-10-23 10:18:09 -07001081 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 if (DBG) log("dial: " + number);
1083 // No permission check needed here: This is just a wrapper around the
1084 // ACTION_DIAL intent, which is available to any app since it puts up
1085 // the UI before it does anything.
1086
1087 String url = createTelUrl(number);
1088 if (url == null) {
1089 return;
1090 }
1091
1092 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001093 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1095 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1096 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1097 mApp.startActivity(intent);
1098 }
1099 }
1100
1101 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001102 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
1104
Wink Savilleb564aae2014-10-23 10:18:09 -07001105 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 if (DBG) log("call: " + number);
1107
1108 // This is just a wrapper around the ACTION_CALL intent, but we still
1109 // need to do a permission check since we're calling startActivity()
1110 // from the context of the phone app.
1111 enforceCallPermission();
1112
1113 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1114 != AppOpsManager.MODE_ALLOWED) {
1115 return;
1116 }
1117
1118 String url = createTelUrl(number);
1119 if (url == null) {
1120 return;
1121 }
1122
Wink Saville08874612014-08-31 19:19:58 -07001123 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001124 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001125 if (slist != null) {
1126 for (SubscriptionInfo subInfoRecord : slist) {
1127 if (subInfoRecord.getSubscriptionId() == subId) {
1128 isValid = true;
1129 break;
1130 }
Wink Saville08874612014-08-31 19:19:58 -07001131 }
1132 }
1133 if (isValid == false) {
1134 return;
1135 }
1136
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001138 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1140 mApp.startActivity(intent);
1141 }
1142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 /**
1144 * End a call based on call state
1145 * @return true is a call was ended
1146 */
1147 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001148 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001149 }
1150
1151 /**
1152 * End a call based on the call state of the subId
1153 * @return true is a call was ended
1154 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001155 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001156 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001157 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158 }
1159
1160 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001161 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001162 }
1163
Wink Savilleb564aae2014-10-23 10:18:09 -07001164 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 if (DBG) log("answerRingingCall...");
1166 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1167 // but that can probably wait till the big TelephonyManager API overhaul.
1168 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1169 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001170 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 }
1172
1173 /**
1174 * Make the actual telephony calls to implement answerRingingCall().
1175 * This should only be called from the main thread of the Phone app.
1176 * @see #answerRingingCall
1177 *
1178 * TODO: it would be nice to return true if we answered the call, or
1179 * false if there wasn't actually a ringing incoming call, or some
1180 * other error occurred. (In other words, pass back the return value
1181 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1182 * But that would require calling this method via sendRequest() rather
1183 * than sendRequestAsync(), and right now we don't actually *need* that
1184 * return value, so let's just return void for now.
1185 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001186 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001187 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001189 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1190 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 if (hasActiveCall && hasHoldingCall) {
1192 // Both lines are in use!
1193 // TODO: provide a flag to let the caller specify what
1194 // policy to use if both lines are in use. (The current
1195 // behavior is hardwired to "answer incoming, end ongoing",
1196 // which is how the CALL button is specced to behave.)
1197 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1198 return;
1199 } else {
1200 // answerCall() will automatically hold the current active
1201 // call, if there is one.
1202 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1203 return;
1204 }
1205 } else {
1206 // No call was ringing.
1207 return;
1208 }
1209 }
1210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001212 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001214 public void silenceRinger() {
1215 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001218 @Override
1219 public boolean isOffhook(String callingPackage) {
1220 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001221 }
1222
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001223 @Override
1224 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1225 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1226 return false;
1227 }
1228
Sanket Padawe356d7632015-06-22 14:03:32 -07001229 final Phone phone = getPhone(subId);
1230 if (phone != null) {
1231 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1232 } else {
1233 return false;
1234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 }
1236
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001237 @Override
1238 public boolean isRinging(String callingPackage) {
1239 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001240 }
1241
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001242 @Override
1243 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1244 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1245 return false;
1246 }
1247
Sanket Padawe356d7632015-06-22 14:03:32 -07001248 final Phone phone = getPhone(subId);
1249 if (phone != null) {
1250 return (phone.getState() == PhoneConstants.State.RINGING);
1251 } else {
1252 return false;
1253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 }
1255
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001256 @Override
1257 public boolean isIdle(String callingPackage) {
1258 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001259 }
1260
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 @Override
1262 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1263 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1264 return false;
1265 }
1266
Sanket Padawe356d7632015-06-22 14:03:32 -07001267 final Phone phone = getPhone(subId);
1268 if (phone != null) {
1269 return (phone.getState() == PhoneConstants.State.IDLE);
1270 } else {
1271 return false;
1272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 }
1274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001276 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001280 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001281 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1282 }
1283
1284 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001285 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Wink Savilleb564aae2014-10-23 10:18:09 -07001288 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001290 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1291 }
1292
1293 /** {@hide} */
1294 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001295 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001296 }
1297
Wink Savilleb564aae2014-10-23 10:18:09 -07001298 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001300 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 checkSimPin.start();
1302 return checkSimPin.unlockSim(null, pin);
1303 }
1304
Wink Saville9de0f752013-10-22 19:04:03 -07001305 /** {@hide} */
1306 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001307 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Wink Savilleb564aae2014-10-23 10:18:09 -07001310 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001312 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 checkSimPuk.start();
1314 return checkSimPuk.unlockSim(puk, pin);
1315 }
1316
1317 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001318 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 * a synchronous one.
1320 */
1321 private static class UnlockSim extends Thread {
1322
1323 private final IccCard mSimCard;
1324
1325 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001326 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1327 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328
1329 // For replies from SimCard interface
1330 private Handler mHandler;
1331
1332 // For async handler to identify request type
1333 private static final int SUPPLY_PIN_COMPLETE = 100;
1334
1335 public UnlockSim(IccCard simCard) {
1336 mSimCard = simCard;
1337 }
1338
1339 @Override
1340 public void run() {
1341 Looper.prepare();
1342 synchronized (UnlockSim.this) {
1343 mHandler = new Handler() {
1344 @Override
1345 public void handleMessage(Message msg) {
1346 AsyncResult ar = (AsyncResult) msg.obj;
1347 switch (msg.what) {
1348 case SUPPLY_PIN_COMPLETE:
1349 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1350 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001351 mRetryCount = msg.arg1;
1352 if (ar.exception != null) {
1353 if (ar.exception instanceof CommandException &&
1354 ((CommandException)(ar.exception)).getCommandError()
1355 == CommandException.Error.PASSWORD_INCORRECT) {
1356 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1357 } else {
1358 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1359 }
1360 } else {
1361 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 mDone = true;
1364 UnlockSim.this.notifyAll();
1365 }
1366 break;
1367 }
1368 }
1369 };
1370 UnlockSim.this.notifyAll();
1371 }
1372 Looper.loop();
1373 }
1374
1375 /*
1376 * Use PIN or PUK to unlock SIM card
1377 *
1378 * If PUK is null, unlock SIM card with PIN
1379 *
1380 * If PUK is not null, unlock SIM card with PUK and set PIN code
1381 */
Wink Saville9de0f752013-10-22 19:04:03 -07001382 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383
1384 while (mHandler == null) {
1385 try {
1386 wait();
1387 } catch (InterruptedException e) {
1388 Thread.currentThread().interrupt();
1389 }
1390 }
1391 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1392
1393 if (puk == null) {
1394 mSimCard.supplyPin(pin, callback);
1395 } else {
1396 mSimCard.supplyPuk(puk, pin, callback);
1397 }
1398
1399 while (!mDone) {
1400 try {
1401 Log.d(LOG_TAG, "wait for done");
1402 wait();
1403 } catch (InterruptedException e) {
1404 // Restore the interrupted status
1405 Thread.currentThread().interrupt();
1406 }
1407 }
1408 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001409 int[] resultArray = new int[2];
1410 resultArray[0] = mResult;
1411 resultArray[1] = mRetryCount;
1412 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 }
1414 }
1415
1416 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001417 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001418
1419 }
1420
Wink Savilleb564aae2014-10-23 10:18:09 -07001421 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 // No permission check needed here: this call is harmless, and it's
1423 // needed for the ServiceState.requestStateUpdate() call (which is
1424 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001425 final Phone phone = getPhone(subId);
1426 if (phone != null) {
1427 phone.updateServiceLocation();
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 }
1430
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001431 @Override
1432 public boolean isRadioOn(String callingPackage) {
1433 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001434 }
1435
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001436 @Override
1437 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1438 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1439 return false;
1440 }
1441 return isRadioOnForSubscriber(subId);
1442 }
1443
1444 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001445 final Phone phone = getPhone(subId);
1446 if (phone != null) {
1447 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1448 } else {
1449 return false;
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452
1453 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
Wink Saville36469e72014-06-11 15:17:00 -07001457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001460 final Phone phone = getPhone(subId);
1461 if (phone != null) {
1462 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1463 }
Wink Saville36469e72014-06-11 15:17:00 -07001464 }
1465
1466 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001468 }
1469
Wink Savilleb564aae2014-10-23 10:18:09 -07001470 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001471 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001472 final Phone phone = getPhone(subId);
1473 if (phone == null) {
1474 return false;
1475 }
1476 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001477 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001478 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480 return true;
1481 }
Wink Saville36469e72014-06-11 15:17:00 -07001482
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001483 public boolean needMobileRadioShutdown() {
1484 /*
1485 * If any of the Radios are available, it will need to be
1486 * shutdown. So return true if any Radio is available.
1487 */
1488 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1489 Phone phone = PhoneFactory.getPhone(i);
1490 if (phone != null && phone.isRadioAvailable()) return true;
1491 }
1492 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1493 return false;
1494 }
1495
1496 public void shutdownMobileRadios() {
1497 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1498 logv("Shutting down Phone " + i);
1499 shutdownRadioUsingPhoneId(i);
1500 }
1501 }
1502
1503 private void shutdownRadioUsingPhoneId(int phoneId) {
1504 enforceModifyPermission();
1505 Phone phone = PhoneFactory.getPhone(phoneId);
1506 if (phone != null && phone.isRadioAvailable()) {
1507 phone.shutdownRadio();
1508 }
1509 }
1510
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001512 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001513 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1514 if (defaultPhone != null) {
1515 defaultPhone.setRadioPower(turnOn);
1516 return true;
1517 } else {
1518 loge("There's no default phone.");
1519 return false;
1520 }
Wink Saville36469e72014-06-11 15:17:00 -07001521 }
1522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 final Phone phone = getPhone(subId);
1526 if (phone != null) {
1527 phone.setRadioPower(turnOn);
1528 return true;
1529 } else {
1530 return false;
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Wink Saville36469e72014-06-11 15:17:00 -07001534 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001535 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 public boolean enableDataConnectivity() {
1537 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001538 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001539 final Phone phone = getPhone(subId);
1540 if (phone != null) {
1541 phone.setDataEnabled(true);
1542 return true;
1543 } else {
1544 return false;
1545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 }
1547
Wink Saville36469e72014-06-11 15:17:00 -07001548 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001549 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 public boolean disableDataConnectivity() {
1551 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001552 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001553 final Phone phone = getPhone(subId);
1554 if (phone != null) {
1555 phone.setDataEnabled(false);
1556 return true;
1557 } else {
1558 return false;
1559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
1561
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001563 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 final Phone phone = getPhone(subId);
1565 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001566 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 } else {
1568 return false;
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
1572 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001573 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001574 }
1575
pkanwarae03a6b2016-11-06 20:37:09 -08001576 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001577 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001578 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1579 return;
1580 }
1581 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1582 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1583 };
1584
Wink Savilleb564aae2014-10-23 10:18:09 -07001585 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1588 return false;
1589 }
Wink Saville36469e72014-06-11 15:17:00 -07001590 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001594 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001595 }
1596
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001597 public int getCallStateForSlot(int slotIndex) {
1598 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001599 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001600 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001605 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001607 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001609 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001615 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 if (phone != null) {
1617 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1618 } else {
1619 return TelephonyManager.DATA_ACTIVITY_NONE;
1620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
1623 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001624 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001625 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001626 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001627 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 }
1629
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001630 if (DBG_LOC) log("getCellLocation: is active user");
1631 Bundle data = new Bundle();
1632 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1633 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 return null;
1635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001637 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1638 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1639 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001640 }
1641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001643 public String getNetworkCountryIsoForPhone(int phoneId) {
1644 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1645 // registered cell info, so return a NULL country instead.
1646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1649 if (TelephonyManager.NETWORK_TYPE_IWLAN
1650 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1651 return "";
1652 }
1653 } finally {
1654 Binder.restoreCallingIdentity(identity);
1655 }
1656 return TelephonyManager.getTelephonyProperty(
1657 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1658 }
1659
1660 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001662 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001663 }
1664
Sanket Padawe356d7632015-06-22 14:03:32 -07001665 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001666 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 mApp.enforceCallingOrSelfPermission(
1668 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.enableLocationUpdates();
1672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
1675 @Override
1676 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001677 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001681 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 mApp.enforceCallingOrSelfPermission(
1683 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 phone.disableLocationUpdates();
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
1690 @Override
1691 @SuppressWarnings("unchecked")
1692 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001693 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001694 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001695 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
1697
1698 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1699 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1700 return null;
1701 }
Svetoslav64fad262015-04-14 14:35:21 -07001702
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001703 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001705 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001707 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1708 try {
1709 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1710 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1711 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1712 } catch (RuntimeException e) {
1713 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001715 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 }
1717
1718
1719 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001720 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001721 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001722 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001723 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001726 if (DBG_LOC) log("getAllCellInfo: is active user");
1727 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1728 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1729 for (Phone phone : PhoneFactory.getPhones()) {
1730 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1731 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001733 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001736 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001738 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001739 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1740 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
Shishir Agrawala9f32182016-04-12 12:00:16 -07001743 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001744 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001745 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1746 return null;
1747 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001748 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001749 return phone == null ? null : phone.getImei();
1750 }
1751
1752 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001753 public String getMeidForSlot(int slotIndex, String callingPackage) {
1754 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1755 return null;
1756 }
1757 Phone phone = PhoneFactory.getPhone(slotIndex);
1758 return phone == null ? null : phone.getMeid();
1759 }
1760
1761 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001762 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001763 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1764 return null;
1765 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001766 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001767 return phone == null ? null : phone.getDeviceSvn();
1768 }
1769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 //
1771 // Internal helper methods.
1772 //
1773
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001774 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1776 *
1777 * @throws SecurityException if the caller does not have the required permission
1778 */
1779 private void enforceModifyPermission() {
1780 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1781 }
1782
1783 /**
Junda Liua2e36012014-07-09 18:30:01 -07001784 * Make sure either system app or the caller has carrier privilege.
1785 *
1786 * @throws SecurityException if the caller does not have the required permission/privilege
1787 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001788 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001789 int permission = mApp.checkCallingOrSelfPermission(
1790 android.Manifest.permission.MODIFY_PHONE_STATE);
1791 if (permission == PackageManager.PERMISSION_GRANTED) {
1792 return;
1793 }
1794
1795 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001796 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001797 }
1798
1799 /**
1800 * Make sure the caller has carrier privilege.
1801 *
1802 * @throws SecurityException if the caller does not have the required permission
1803 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001804 private void enforceCarrierPrivilege(int subId) {
1805 if (getCarrierPrivilegeStatus(subId) !=
1806 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001807 loge("No Carrier Privilege.");
1808 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001809 }
1810 }
1811
1812 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 * Make sure the caller has the CALL_PHONE permission.
1814 *
1815 * @throws SecurityException if the caller does not have the required permission
1816 */
1817 private void enforceCallPermission() {
1818 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1819 }
1820
Stuart Scott8eef64f2015-04-08 15:13:54 -07001821 private void enforceConnectivityInternalPermission() {
1822 mApp.enforceCallingOrSelfPermission(
1823 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1824 "ConnectivityService");
1825 }
1826
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 private String createTelUrl(String number) {
1828 if (TextUtils.isEmpty(number)) {
1829 return null;
1830 }
1831
Jake Hambye994d462014-02-03 13:10:13 -08001832 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Ihab Awadf9e92732013-12-05 18:02:52 -08001835 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1837 }
1838
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001839 private static void logv(String msg) {
1840 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1841 }
1842
Ihab Awadf9e92732013-12-05 18:02:52 -08001843 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1845 }
1846
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001847 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001849 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001850 }
1851
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001853 public int getActivePhoneTypeForSlot(int slotIndex) {
1854 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 if (phone == null) {
1856 return PhoneConstants.PHONE_TYPE_NONE;
1857 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001858 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
1862 /**
1863 * Returns the CDMA ERI icon index to display
1864 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001865 @Override
1866 public int getCdmaEriIconIndex(String callingPackage) {
1867 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001871 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1872 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1873 return -1;
1874 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 return phone.getCdmaEriIconIndex();
1878 } else {
1879 return -1;
1880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
1883 /**
1884 * Returns the CDMA ERI icon mode,
1885 * 0 - ON
1886 * 1 - FLASHING
1887 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001888 @Override
1889 public int getCdmaEriIconMode(String callingPackage) {
1890 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001891 }
1892
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001894 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1895 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1896 return -1;
1897 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
1900 return phone.getCdmaEriIconMode();
1901 } else {
1902 return -1;
1903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906 /**
1907 * Returns the CDMA ERI text,
1908 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001909 @Override
1910 public String getCdmaEriText(String callingPackage) {
1911 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1916 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1917 return null;
1918 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 final Phone phone = getPhone(subId);
1920 if (phone != null) {
1921 return phone.getCdmaEriText();
1922 } else {
1923 return null;
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
1927 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001928 * Returns the CDMA MDN.
1929 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001931 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001932 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 final Phone phone = getPhone(subId);
1934 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1935 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001936 } else {
1937 return null;
1938 }
1939 }
1940
1941 /**
1942 * Returns the CDMA MIN.
1943 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001945 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001946 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 final Phone phone = getPhone(subId);
1948 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1949 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001950 } else {
1951 return null;
1952 }
1953 }
1954
1955 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 * Returns true if CDMA provisioning needs to run.
1957 */
1958 public boolean needsOtaServiceProvisioning() {
1959 return mPhone.needsOtaServiceProvisioning();
1960 }
1961
1962 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001963 * Sets the voice mail number of a given subId.
1964 */
1965 @Override
1966 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001967 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001968 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1969 new Pair<String, String>(alphaTag, number), new Integer(subId));
1970 return success;
1971 }
1972
Ta-wei Yen87c49842016-05-13 21:19:52 -07001973 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001974 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1976 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1977 if (!TextUtils.equals(callingPackage, systemDialer)) {
1978 throw new SecurityException("caller must be system dialer");
1979 }
1980 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1981 if (phoneAccountHandle == null){
1982 return null;
1983 }
1984 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
1985 }
1986
1987 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08001988 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08001989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1990 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1991 return null;
1992 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08001993 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1994 }
1995
1996 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001997 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1998 VisualVoicemailSmsFilterSettings settings) {
1999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002000 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002001 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2002 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002003 }
2004
2005 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002006 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2007 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002008 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002009 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002010 }
2011
2012 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002013 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2014 String callingPackage, int subId) {
2015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002017 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002018 }
2019
2020 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002021 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002022 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002024 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2025 }
2026
2027 @Override
2028 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2029 String number, int port, String text, PendingIntent sentIntent) {
2030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002031 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002032 enforceSendSmsPermission();
2033 // Make the calls as the phone process.
2034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2037 if (port == 0) {
2038 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2039 sentIntent, null, false);
2040 } else {
2041 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2042 smsManager.sendDataMessageWithSelfPermissions(number, null,
2043 (short) port, data, sentIntent, null);
2044 }
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002048 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002049 /**
fionaxu0152e512016-11-14 13:36:14 -08002050 * Sets the voice activation state of a given subId.
2051 */
2052 @Override
2053 public void setVoiceActivationState(int subId, int activationState) {
2054 enforceModifyPermissionOrCarrierPrivilege(subId);
2055 final Phone phone = getPhone(subId);
2056 if (phone != null) {
2057 phone.setVoiceActivationState(activationState);
2058 } else {
2059 loge("setVoiceActivationState fails with invalid subId: " + subId);
2060 }
2061 }
2062
2063 /**
2064 * Sets the data activation state of a given subId.
2065 */
2066 @Override
2067 public void setDataActivationState(int subId, int activationState) {
2068 enforceModifyPermissionOrCarrierPrivilege(subId);
2069 final Phone phone = getPhone(subId);
2070 if (phone != null) {
2071 phone.setDataActivationState(activationState);
2072 } else {
2073 loge("setVoiceActivationState fails with invalid subId: " + subId);
2074 }
2075 }
2076
2077 /**
2078 * Returns the voice activation state of a given subId.
2079 */
2080 @Override
2081 public int getVoiceActivationState(int subId, String callingPackage) {
2082 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2083 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2084 }
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 return phone.getVoiceActivationState();
2088 } else {
2089 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2090 }
2091 }
2092
2093 /**
2094 * Returns the data activation state of a given subId.
2095 */
2096 @Override
2097 public int getDataActivationState(int subId, String callingPackage) {
2098 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2099 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2100 }
2101 final Phone phone = getPhone(subId);
2102 if (phone != null) {
2103 return phone.getDataActivationState();
2104 } else {
2105 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2106 }
2107 }
2108
2109 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 * Returns the unread count of voicemails
2111 */
2112 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002113 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002114 }
2115
2116 /**
2117 * Returns the unread count of voicemails for a subId
2118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002120 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002121 final Phone phone = getPhone(subId);
2122 if (phone != null) {
2123 return phone.getVoiceMessageCount();
2124 } else {
2125 return 0;
2126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
2129 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002130 * returns true, if the device is in a state where both voice and data
2131 * are supported simultaneously. This can change based on location or network condition.
2132 */
2133 @Override
2134 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2135 final Phone phone = getPhone(subId);
2136 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2137 }
2138
2139 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002140 * Send the dialer code if called from the current default dialer or the caller has
2141 * carrier privilege.
2142 * @param inputCode The dialer code to send
2143 */
2144 @Override
2145 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2146 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2147 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2148 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2149 enforceCarrierPrivilege(getDefaultSubscription());
2150 }
2151 mPhone.sendDialerSpecialCode(inputCode);
2152 }
2153
2154 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002155 * Returns the data network type.
2156 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 *
2158 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2159 */
2160 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002161 public int getNetworkType() {
2162 final Phone phone = getPhone(getDefaultSubscription());
2163 if (phone != null) {
2164 return phone.getServiceState().getDataNetworkType();
2165 } else {
2166 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2167 }
Wink Saville36469e72014-06-11 15:17:00 -07002168 }
2169
2170 /**
2171 * Returns the network type for a subId
2172 */
2173 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002174 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2175 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2176 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2177 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002178
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002180 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 return phone.getServiceState().getDataNetworkType();
2182 } else {
2183 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
2187 /**
2188 * Returns the data network type
2189 */
2190 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002191 public int getDataNetworkType(String callingPackage) {
2192 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002193 }
2194
2195 /**
2196 * Returns the data network type for a subId
2197 */
2198 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2200 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2201 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2202 }
2203
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 return phone.getServiceState().getDataNetworkType();
2207 } else {
2208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
2212 /**
Wink Saville36469e72014-06-11 15:17:00 -07002213 * Returns the Voice network type for a subId
2214 */
2215 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002216 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2217 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 final Phone phone = getPhone(subId);
2222 if (phone != null) {
2223 return phone.getServiceState().getVoiceNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
2230 * @return true if a ICC card is present
2231 */
2232 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002233 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002234 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2235 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
2238 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002239 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002240 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2243 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002244 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002245 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002246 } else {
2247 return false;
2248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
2251 /**
2252 * Return if the current radio is LTE on CDMA. This
2253 * is a tri-state return value as for a period of time
2254 * the mode may be unknown.
2255 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002258 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002260 @Override
2261 public int getLteOnCdmaMode(String callingPackage) {
2262 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002263 }
2264
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2267 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2268 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2269 }
2270
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 final Phone phone = getPhone(subId);
2272 if (phone == null) {
2273 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2274 } else {
2275 return phone.getLteOnCdmaMode();
2276 }
Wink Saville36469e72014-06-11 15:17:00 -07002277 }
2278
2279 public void setPhone(Phone phone) {
2280 mPhone = phone;
2281 }
2282
2283 /**
2284 * {@hide}
2285 * Returns Default subId, 0 in the case of single standby.
2286 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002287 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002288 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002289 }
2290
Shishir Agrawala9f32182016-04-12 12:00:16 -07002291 private int getSlotForDefaultSubscription() {
2292 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2293 }
2294
Wink Savilleb564aae2014-10-23 10:18:09 -07002295 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002296 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002298
2299 /**
2300 * @see android.telephony.TelephonyManager.WifiCallingChoices
2301 */
2302 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002303 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2304 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002305 }
2306
2307 /**
2308 * @see android.telephony.TelephonyManager.WifiCallingChoices
2309 */
2310 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002311 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2312 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2313 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002314 }
2315
Sailesh Nepald1e68152013-12-12 19:08:02 -08002316 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002317 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002318 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002319 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002320
Shishir Agrawal566b7612013-10-28 14:41:00 -07002321 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002322 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2323 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002324 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002325
Derek Tan740e1672017-06-27 14:56:27 -07002326 if (TextUtils.equals(ISDR_AID, aid)) {
2327 // Only allows LPA to open logical channel to ISD-R.
2328 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2329 ComponentInfo bestComponent =
2330 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2331 if (bestComponent == null
2332 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2333 loge("The calling package is not allowed to access ISD-R.");
2334 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2335 }
2336 }
2337
2338 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002339 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002340 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002341 if (DBG) log("iccOpenLogicalChannel: " + response);
2342 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002343 }
2344
2345 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002346 public boolean iccCloseLogicalChannel(int subId, int channel) {
2347 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002348
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002349 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002350 if (channel < 0) {
2351 return false;
2352 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002353 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002354 if (DBG) log("iccCloseLogicalChannel: " + success);
2355 return success;
2356 }
2357
2358 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002359 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002360 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002361 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002362
2363 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002364 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2365 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002366 " data=" + data);
2367 }
2368
2369 if (channel < 0) {
2370 return "";
2371 }
2372
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002373 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002374 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2376
Shishir Agrawal566b7612013-10-28 14:41:00 -07002377 // Append the returned status code to the end of the response payload.
2378 String s = Integer.toHexString(
2379 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002380 if (response.payload != null) {
2381 s = IccUtils.bytesToHexString(response.payload) + s;
2382 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383 return s;
2384 }
Jake Hambye994d462014-02-03 13:10:13 -08002385
Evan Charltonc66da362014-05-16 14:06:40 -07002386 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002388 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002390
2391 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2393 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002394 }
2395
2396 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002397 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002398 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2399
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002400 // Append the returned status code to the end of the response payload.
2401 String s = Integer.toHexString(
2402 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002403 if (response.payload != null) {
2404 s = IccUtils.bytesToHexString(response.payload) + s;
2405 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002406 return s;
2407 }
2408
2409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002411 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002413
2414 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002415 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002416 p1 + " " + p2 + " " + p3 + ":" + filePath);
2417 }
2418
2419 IccIoResult response =
2420 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002421 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2422 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002423
2424 if (DBG) {
2425 log("Exchange SIM_IO [R]" + response);
2426 }
2427
2428 byte[] result = null;
2429 int length = 2;
2430 if (response.payload != null) {
2431 length = 2 + response.payload.length;
2432 result = new byte[length];
2433 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2434 } else {
2435 result = new byte[length];
2436 }
2437
2438 result[length - 1] = (byte) response.sw2;
2439 result[length - 2] = (byte) response.sw1;
2440 return result;
2441 }
2442
Nathan Haroldb3014052017-01-25 15:57:32 -08002443 /**
2444 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2445 * on a particular subscription
2446 */
2447 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002448 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2449 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002450 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2451 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2452 return null;
2453 }
2454 Object response = sendRequest(
2455 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2456 if (response instanceof String[]) {
2457 return (String[]) response;
2458 }
2459 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2460 return null;
2461 }
2462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 public String sendEnvelopeWithStatus(int subId, String content) {
2465 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002466
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002468 if (response.payload == null) {
2469 return "";
2470 }
2471
2472 // Append the returned status code to the end of the response payload.
2473 String s = Integer.toHexString(
2474 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2475 s = IccUtils.bytesToHexString(response.payload) + s;
2476 return s;
2477 }
2478
Jake Hambye994d462014-02-03 13:10:13 -08002479 /**
2480 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2481 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2482 *
2483 * @param itemID the ID of the item to read
2484 * @return the NV item as a String, or null on error.
2485 */
2486 @Override
2487 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002488 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002489 if (DBG) log("nvReadItem: item " + itemID);
2490 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2491 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2492 return value;
2493 }
2494
2495 /**
2496 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2497 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2498 *
2499 * @param itemID the ID of the item to read
2500 * @param itemValue the value to write, as a String
2501 * @return true on success; false on any failure
2502 */
2503 @Override
2504 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002505 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002506 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2507 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2508 new Pair<Integer, String>(itemID, itemValue));
2509 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2510 return success;
2511 }
2512
2513 /**
2514 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2515 * Used for device configuration by some CDMA operators.
2516 *
2517 * @param preferredRoamingList byte array containing the new PRL
2518 * @return true on success; false on any failure
2519 */
2520 @Override
2521 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002523 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2524 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2525 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2526 return success;
2527 }
2528
2529 /**
2530 * Perform the specified type of NV config reset.
2531 * Used for device configuration by some CDMA operators.
2532 *
2533 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2534 * @return true on success; false on any failure
2535 */
2536 @Override
2537 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002538 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002539 if (DBG) log("nvResetConfig: type " + resetType);
2540 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2541 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2542 return success;
2543 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002544
2545 /**
Wink Saville36469e72014-06-11 15:17:00 -07002546 * {@hide}
2547 * Returns Default sim, 0 in the case of single standby.
2548 */
2549 public int getDefaultSim() {
2550 //TODO Need to get it from Telephony Devcontroller
2551 return 0;
2552 }
2553
Svet Ganovb320e182015-04-16 12:30:10 -07002554 public String[] getPcscfAddress(String apnType, String callingPackage) {
2555 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2556 return new String[0];
2557 }
2558
2559
ram87fca6f2014-07-18 18:58:44 +05302560 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Brad Ebinger51f743a2017-01-23 13:50:20 -08002563 /**
2564 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2565 * feature or {@link null} if the service is not available. If an ImsServiceController is
2566 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2567 * feature updates.
2568 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002569 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002570 IImsServiceFeatureListener callback) {
2571 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002572 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002573 callback);
2574 }
2575
Wink Saville36469e72014-06-11 15:17:00 -07002576 public void setImsRegistrationState(boolean registered) {
2577 enforceModifyPermission();
2578 mPhone.setImsRegistrationState(registered);
2579 }
2580
2581 /**
Stuart Scott54788802015-03-30 13:18:01 -07002582 * Set the network selection mode to automatic.
2583 *
2584 */
2585 @Override
2586 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002587 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002588 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2589 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2590 }
2591
2592 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002593 * Set the network selection mode to manual with the selected carrier.
2594 */
2595 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002596 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2597 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002598 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002599 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002600 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2601 persistSelection);
2602 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002603 }
2604
2605 /**
2606 * Scans for available networks.
2607 */
2608 @Override
2609 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002610 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002611 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2612 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2613 CMD_PERFORM_NETWORK_SCAN, null, subId);
2614 return result;
2615 }
2616
2617 /**
yinxub1bed742017-04-17 11:45:04 -07002618 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002619 *
yinxub1bed742017-04-17 11:45:04 -07002620 * @param subId id of the subscription
2621 * @param request contains the radio access networks with bands/channels to scan
2622 * @param messenger callback messenger for scan results or errors
2623 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002624 * @return the id of the requested scan which can be used to stop the scan.
2625 */
2626 @Override
2627 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2628 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002629 enforceModifyPermissionOrCarrierPrivilege(subId);
2630 return mNetworkScanRequestTracker.startNetworkScan(
2631 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002632 }
2633
2634 /**
2635 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002636 *
2637 * @param subId id of the subscription
2638 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002639 */
2640 @Override
2641 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002642 enforceModifyPermissionOrCarrierPrivilege(subId);
2643 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002644 }
2645
2646 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002647 * Get the calculated preferred network type.
2648 * Used for debugging incorrect network type.
2649 *
2650 * @return the preferred network type, defined in RILConstants.java.
2651 */
2652 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002653 public int getCalculatedPreferredNetworkType(String callingPackage) {
2654 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2655 return RILConstants.PREFERRED_NETWORK_MODE;
2656 }
2657
Amit Mahajan43330e02014-11-18 11:54:45 -08002658 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002659 }
2660
2661 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002662 * Get the preferred network type.
2663 * Used for device configuration by some CDMA operators.
2664 *
2665 * @return the preferred network type, defined in RILConstants.java.
2666 */
2667 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002668 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002669 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002670 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002671 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002672 int networkType = (result != null ? result[0] : -1);
2673 if (DBG) log("getPreferredNetworkType: " + networkType);
2674 return networkType;
2675 }
2676
2677 /**
2678 * Set the preferred network type.
2679 * Used for device configuration by some CDMA operators.
2680 *
2681 * @param networkType the preferred network type, defined in RILConstants.java.
2682 * @return true on success; false on any failure.
2683 */
2684 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002685 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002686 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002687 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2688 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002689 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002690 if (success) {
2691 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002692 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002693 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002694 return success;
2695 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002696
2697 /**
Junda Liu475951f2014-11-07 16:45:03 -08002698 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2699 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2700 * tethering.
2701 *
2702 * @return 0: Not required. 1: required. 2: Not set.
2703 * @hide
2704 */
2705 @Override
2706 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002707 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002708 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2709 Settings.Global.TETHER_DUN_REQUIRED, 2);
2710 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2711 // config_tether_apndata.
2712 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2713 dunRequired = 1;
2714 }
2715 return dunRequired;
2716 }
2717
2718 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002719 * Set mobile data enabled
2720 * Used by the user through settings etc to turn on/off mobile data
2721 *
2722 * @param enable {@code true} turn turn data on, else {@code false}
2723 */
2724 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002725 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002726 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002727 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002728 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002729 Phone phone = PhoneFactory.getPhone(phoneId);
2730 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002731 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002732 phone.setDataEnabled(enable);
2733 } else {
2734 loge("setDataEnabled: no phone for subId=" + subId);
2735 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002736 }
2737
2738 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002739 * Get whether mobile data is enabled.
2740 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002741 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002742 *
2743 * @return {@code true} if data is enabled else {@code false}
2744 */
2745 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002746 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002747 try {
2748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2749 null);
2750 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002751 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002752 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002753 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002754 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002755 Phone phone = PhoneFactory.getPhone(phoneId);
2756 if (phone != null) {
2757 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002758 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002759 return retVal;
2760 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002761 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002762 return false;
2763 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002764 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002765
2766 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002767 public int getCarrierPrivilegeStatus(int subId) {
2768 final Phone phone = getPhone(subId);
2769 if (phone == null) {
2770 loge("getCarrierPrivilegeStatus: Invalid subId");
2771 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2772 }
2773 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002774 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002775 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2777 }
2778 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002779 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002780 }
Junda Liu29340342014-07-10 15:23:27 -07002781
2782 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002783 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002784 if (TextUtils.isEmpty(pkgName))
2785 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002786 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002787 if (card == null) {
2788 loge("checkCarrierPrivilegesForPackage: No UICC");
2789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2790 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002791 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2792 }
2793
2794 @Override
2795 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002796 if (TextUtils.isEmpty(pkgName))
2797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002798 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2800 UiccCard card = UiccController.getInstance().getUiccCard(i);
2801 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002802 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002803 continue;
2804 }
2805
2806 result = card.getCarrierPrivilegeStatus(
2807 mPhone.getContext().getPackageManager(), pkgName);
2808 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2809 break;
2810 }
2811 }
2812
2813 return result;
Junda Liu29340342014-07-10 15:23:27 -07002814 }
Derek Tan89e89d42014-07-08 17:00:10 -07002815
2816 @Override
Junda Liue64de782015-04-16 17:19:16 -07002817 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2818 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2819 loge("phoneId " + phoneId + " is not valid.");
2820 return null;
2821 }
2822 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002823 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002824 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002825 return null ;
2826 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002827 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002828 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002829 }
2830
Amith Yamasani6e118872016-02-19 12:53:51 -08002831 @Override
2832 public List<String> getPackagesWithCarrierPrivileges() {
2833 PackageManager pm = mPhone.getContext().getPackageManager();
2834 List<String> privilegedPackages = new ArrayList<>();
2835 List<PackageInfo> packages = null;
2836 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2837 UiccCard card = UiccController.getInstance().getUiccCard(i);
2838 if (card == null) {
2839 // No UICC in that slot.
2840 continue;
2841 }
2842 if (card.hasCarrierPrivilegeRules()) {
2843 if (packages == null) {
2844 // Only check packages in user 0 for now
2845 packages = pm.getInstalledPackagesAsUser(
2846 PackageManager.MATCH_DISABLED_COMPONENTS
2847 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2848 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2849 }
2850 for (int p = packages.size() - 1; p >= 0; p--) {
2851 PackageInfo pkgInfo = packages.get(p);
2852 if (pkgInfo != null && pkgInfo.packageName != null
2853 && card.getCarrierPrivilegeStatus(pkgInfo)
2854 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2855 privilegedPackages.add(pkgInfo.packageName);
2856 }
2857 }
2858 }
2859 }
2860 return privilegedPackages;
2861 }
2862
Wink Savilleb564aae2014-10-23 10:18:09 -07002863 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002864 final Phone phone = getPhone(subId);
2865 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002866 if (card == null) {
2867 loge("getIccId: No UICC");
2868 return null;
2869 }
2870 String iccId = card.getIccId();
2871 if (TextUtils.isEmpty(iccId)) {
2872 loge("getIccId: ICC ID is null or empty.");
2873 return null;
2874 }
2875 return iccId;
2876 }
2877
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002878 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002879 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2880 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002881 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002882
Jeff Sharkey85190e62014-12-05 09:40:12 -08002883 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002884 final Phone phone = getPhone(subId);
2885 if (phone == null) {
2886 return false;
2887 }
2888 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002889
2890 if (DBG_MERGE) {
2891 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2892 + subscriberId + " to " + number);
2893 }
2894
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002895 if (TextUtils.isEmpty(iccId)) {
2896 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002897 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002898
Jeff Sharkey85190e62014-12-05 09:40:12 -08002899 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2900
2901 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002902 if (alphaTag == null) {
2903 editor.remove(alphaTagPrefKey);
2904 } else {
2905 editor.putString(alphaTagPrefKey, alphaTag);
2906 }
2907
Jeff Sharkey85190e62014-12-05 09:40:12 -08002908 // Record both the line number and IMSI for this ICCID, since we need to
2909 // track all merged IMSIs based on line number
2910 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2911 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002912 if (number == null) {
2913 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002914 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002915 } else {
2916 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002917 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002918 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002919
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002920 editor.commit();
2921 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002922 }
2923
2924 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002925 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002926 // This is open to apps with WRITE_SMS.
2927 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002928 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002929 return null;
2930 }
Derek Tan97ebb422014-09-05 16:55:38 -07002931
2932 String iccId = getIccId(subId);
2933 if (iccId != null) {
2934 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002935 if (DBG_MERGE) {
2936 log("getLine1NumberForDisplay returning " +
2937 mTelephonySharedPreferences.getString(numberPrefKey, null));
2938 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002939 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002940 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002941 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002942 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002943 }
2944
2945 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002946 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2947 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2948 return null;
2949 }
Derek Tan97ebb422014-09-05 16:55:38 -07002950
2951 String iccId = getIccId(subId);
2952 if (iccId != null) {
2953 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002954 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002955 }
Derek Tan97ebb422014-09-05 16:55:38 -07002956 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002957 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002958
2959 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002960 public String[] getMergedSubscriberIds(String callingPackage) {
2961 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2962 return null;
2963 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002964 final Context context = mPhone.getContext();
2965 final TelephonyManager tele = TelephonyManager.from(context);
2966 final SubscriptionManager sub = SubscriptionManager.from(context);
2967
2968 // Figure out what subscribers are currently active
2969 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002970 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2971 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 final int[] subIds = sub.getActiveSubscriptionIdList();
2975 for (int subId : subIds) {
2976 activeSubscriberIds.add(tele.getSubscriberId(subId));
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002980 }
2981
2982 // First pass, find a number override for an active subscriber
2983 String mergeNumber = null;
2984 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2985 for (String key : prefs.keySet()) {
2986 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2987 final String subscriberId = (String) prefs.get(key);
2988 if (activeSubscriberIds.contains(subscriberId)) {
2989 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2990 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2991 mergeNumber = (String) prefs.get(numberKey);
2992 if (DBG_MERGE) {
2993 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2994 + " for active subscriber " + subscriberId);
2995 }
2996 if (!TextUtils.isEmpty(mergeNumber)) {
2997 break;
2998 }
2999 }
3000 }
3001 }
3002
3003 // Shortcut when no active merged subscribers
3004 if (TextUtils.isEmpty(mergeNumber)) {
3005 return null;
3006 }
3007
3008 // Second pass, find all subscribers under that line override
3009 final ArraySet<String> result = new ArraySet<>();
3010 for (String key : prefs.keySet()) {
3011 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3012 final String number = (String) prefs.get(key);
3013 if (mergeNumber.equals(number)) {
3014 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3015 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3016 final String subscriberId = (String) prefs.get(subscriberKey);
3017 if (!TextUtils.isEmpty(subscriberId)) {
3018 result.add(subscriberId);
3019 }
3020 }
3021 }
3022 }
3023
3024 final String[] resultArray = result.toArray(new String[result.size()]);
3025 Arrays.sort(resultArray);
3026 if (DBG_MERGE) {
3027 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3028 }
3029 return resultArray;
3030 }
3031
3032 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003033 public boolean setOperatorBrandOverride(int subId, String brand) {
3034 enforceCarrierPrivilege(subId);
3035 final Phone phone = getPhone(subId);
3036 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003037 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003038
3039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003040 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003041 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3042 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003043 enforceCarrierPrivilege(subId);
3044 final Phone phone = getPhone(subId);
3045 if (phone == null) {
3046 return false;
3047 }
3048 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003049 cdmaNonRoamingList);
3050 }
3051
3052 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003053 public void setRadioCapability(RadioAccessFamily[] rafs) {
3054 try {
3055 ProxyController.getInstance().setRadioCapability(rafs);
3056 } catch (RuntimeException e) {
3057 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3058 }
3059 }
3060
3061 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003062 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3063 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3064 return RadioAccessFamily.RAF_UNKNOWN;
3065 }
3066
Wink Saville5d475dd2014-10-17 15:00:58 -07003067 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3068 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003069
3070 @Override
3071 public void enableVideoCalling(boolean enable) {
3072 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003073 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003074 }
3075
3076 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003077 public boolean isVideoCallingEnabled(String callingPackage) {
3078 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3079 return false;
3080 }
3081
Andrew Lee77527ac2014-10-21 16:57:39 -07003082 // Check the user preference and the system-level IMS setting. Even if the user has
3083 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3084 // In the long run, we may instead need to check if there exists a connection service
3085 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003086 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3087 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003088 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003089 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003090
Andrew Leea1239f22015-03-02 17:44:07 -08003091 @Override
3092 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003093 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003094 }
3095
3096 @Override
3097 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003098 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003099 }
3100
Andrew Lee9431b832015-03-09 18:46:45 -07003101 @Override
3102 public boolean isTtyModeSupported() {
3103 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3104 TelephonyManager telephonyManager =
3105 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003106 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003107 }
3108
3109 @Override
3110 public boolean isHearingAidCompatibilitySupported() {
3111 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3112 }
3113
Sanket Padawe7310cc72015-01-14 09:53:20 -08003114 /**
3115 * Returns the unique device ID of phone, for example, the IMEI for
3116 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3117 *
3118 * <p>Requires Permission:
3119 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3120 */
3121 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003122 public String getDeviceId(String callingPackage) {
3123 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3124 return null;
3125 }
3126
Sanket Padawe7310cc72015-01-14 09:53:20 -08003127 final Phone phone = PhoneFactory.getPhone(0);
3128 if (phone != null) {
3129 return phone.getDeviceId();
3130 } else {
3131 return null;
3132 }
3133 }
3134
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003135 /*
3136 * {@hide}
3137 * Returns the IMS Registration Status
3138 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003139 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003140 public boolean isImsRegistered() {
3141 return mPhone.isImsRegistered();
3142 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003143
Ping Sunc67b7c22016-03-02 19:16:45 +08003144 /**
3145 * {@hide}
3146 * Returns the IMS Registration Status on a particular subid
3147 *
3148 * @param subId
3149 */
3150 public boolean isImsRegisteredForSubscriber(int subId) {
3151 Phone phone = getPhone(subId);
3152 if (phone != null) {
3153 return phone.isImsRegistered();
3154 } else {
3155 return false;
3156 }
3157 }
3158
Santos Cordon7a1885b2015-02-03 11:15:19 -08003159 @Override
3160 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3161 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3162 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003163
Nathan Haroldc55097a2015-03-11 18:14:50 -07003164 /*
3165 * {@hide}
3166 * Returns the IMS Registration Status
3167 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003168 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003169 return mPhone.isWifiCallingEnabled();
3170 }
3171
3172 /*
3173 * {@hide}
3174 * Returns the IMS Registration Status
3175 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003176 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003177 return mPhone.isVolteEnabled();
3178 }
Svet Ganovb320e182015-04-16 12:30:10 -07003179
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003180 /*
3181 * {@hide} Returns the IMS Registration Status
3182 */
3183 public boolean isVideoTelephonyAvailable() {
3184 return mPhone.isVideoEnabled();
3185 }
3186
Svet Ganovb320e182015-04-16 12:30:10 -07003187 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003188 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003189 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003190 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3191
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003192 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003193 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003194 } catch (SecurityException e) {
3195 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3196 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003197 }
Svet Ganovb320e182015-04-16 12:30:10 -07003198
3199 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3200 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3201 return false;
3202 }
3203
3204 return true;
3205 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003206
Makoto Onukifee69342015-06-29 14:44:50 -07003207 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003208 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003209 */
3210 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003211 // Default SMS app can always read it.
3212 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3213 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3214 return true;
3215 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003216
Makoto Onukie4072d12015-08-03 15:12:23 -07003217 try {
3218 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003219 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003220 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003221 // Can be read with READ_SMS too.
3222 try {
3223 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3224 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3225 if (opCode != AppOpsManager.OP_NONE) {
3226 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3227 == AppOpsManager.MODE_ALLOWED;
3228 } else {
3229 return true;
3230 }
3231 } catch (SecurityException readSmsSecurityException) {
3232 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003233 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003234 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003235 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003236 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003237 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003238 if (opCode != AppOpsManager.OP_NONE) {
3239 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3240 == AppOpsManager.MODE_ALLOWED;
3241 } else {
3242 return true;
3243 }
3244 } catch (SecurityException readPhoneNumberSecurityException) {
3245 }
3246
3247 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3248 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3249 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003250 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003251 }
3252
Stuart Scott8eef64f2015-04-08 15:13:54 -07003253 @Override
3254 public void factoryReset(int subId) {
3255 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003256 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3257 return;
3258 }
3259
Svet Ganovcc087f82015-05-12 20:35:54 -07003260 final long identity = Binder.clearCallingIdentity();
3261 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003262 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3263 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003264 // Enable data
3265 setDataEnabled(subId, true);
3266 // Set network selection mode to automatic
3267 setNetworkSelectionModeAutomatic(subId);
3268 // Set preferred mobile network type to the best available
3269 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3270 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003271 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003272 }
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003275 }
3276 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003277
3278 @Override
3279 public String getLocaleFromDefaultSim() {
3280 // We query all subscriptions instead of just the active ones, because
3281 // this might be called early on in the provisioning flow when the
3282 // subscriptions potentially aren't active yet.
3283 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3284 if (slist == null || slist.isEmpty()) {
3285 return null;
3286 }
3287
3288 // This function may be called very early, say, from the setup wizard, at
3289 // which point we won't have a default subscription set. If that's the case
3290 // we just choose the first, which will be valid in "most cases".
3291 final int defaultSubId = getDefaultSubscription();
3292 SubscriptionInfo info = null;
3293 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3294 info = slist.get(0);
3295 } else {
3296 for (SubscriptionInfo item : slist) {
3297 if (item.getSubscriptionId() == defaultSubId) {
3298 info = item;
3299 break;
3300 }
3301 }
3302
3303 if (info == null) {
3304 return null;
3305 }
3306 }
3307
3308 // Try and fetch the locale from the carrier properties or from the SIM language
3309 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003310 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003311 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003312 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003313 if (defaultPhone != null) {
3314 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3315 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003316 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003317 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3318 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003319 } else {
3320 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003321 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003322 }
3323 }
3324
Narayan Kamath011676f2015-07-29 12:04:08 +01003325 // The SIM language preferences only store a language (e.g. fr = French), not an
3326 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3327 // the SIM and carrier preferences does not include a country we add the country
3328 // determined from the SIM MCC to provide an exact locale.
3329 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003330 if (mccLocale != null) {
3331 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3332 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003333 }
3334
Tony Hill183b2de2015-06-24 14:53:58 +01003335 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003336 return null;
3337 }
3338
3339 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 return mSubscriptionController.getAllSubInfoList(
3343 mPhone.getContext().getOpPackageName());
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
3347 }
3348
3349 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 return mSubscriptionController.getActiveSubscriptionInfoList(
3353 mPhone.getContext().getOpPackageName());
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
3356 }
3357 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003358
3359 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003360 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3361 * representing the state of the modem.
3362 *
3363 * NOTE: This clears the modem state, so there should only every be one caller.
3364 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003365 */
3366 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003367 public void requestModemActivityInfo(ResultReceiver result) {
3368 enforceModifyPermission();
3369
3370 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3371 Bundle bundle = new Bundle();
3372 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3373 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003374 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003375
3376 /**
3377 * {@hide}
3378 * Returns the service state information on specified subscription.
3379 */
3380 @Override
3381 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3382
3383 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3384 return null;
3385 }
3386
3387 final Phone phone = getPhone(subId);
3388 if (phone == null) {
3389 return null;
3390 }
3391
3392 return phone.getServiceState();
3393 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003394
3395 /**
3396 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3397 *
3398 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3399 * voicemail ringtone.
3400 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3401 * PhoneAccount.
3402 */
3403 @Override
3404 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003405 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003406 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003407 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003408 }
3409
fionaxu7ed723d2017-05-30 18:58:54 -07003410 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003411 }
3412
3413 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003414 * Sets the per-account voicemail ringtone.
3415 *
3416 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3417 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3418 *
3419 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3420 * voicemail ringtone.
3421 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3422 * PhoneAccount.
3423 */
3424 @Override
3425 public void setVoicemailRingtoneUri(String callingPackage,
3426 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3427 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3428 if (!TextUtils.equals(callingPackage,
3429 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3430 enforceModifyPermissionOrCarrierPrivilege(
3431 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3432 }
3433 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3434 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003435 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003436 }
fionaxu7ed723d2017-05-30 18:58:54 -07003437 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003438 }
3439
3440 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003441 * Returns whether vibration is set for voicemail notification in Phone settings.
3442 *
3443 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3444 * voicemail vibration setting.
3445 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3446 */
3447 @Override
3448 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003449 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003450 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003451 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003452 }
3453
fionaxu7ed723d2017-05-30 18:58:54 -07003454 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003455 }
3456
Youhan Wange64578a2016-05-02 15:32:42 -07003457 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003458 * Sets the per-account voicemail vibration.
3459 *
3460 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3461 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3462 *
3463 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3464 * voicemail vibration setting.
3465 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3466 * specific PhoneAccount.
3467 */
3468 @Override
3469 public void setVoicemailVibrationEnabled(String callingPackage,
3470 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3472 if (!TextUtils.equals(callingPackage,
3473 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3474 enforceModifyPermissionOrCarrierPrivilege(
3475 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3476 }
3477
3478 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3479 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003480 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003481 }
fionaxu7ed723d2017-05-30 18:58:54 -07003482 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003483 }
3484
3485 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003486 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3487 *
3488 * @throws SecurityException if the caller does not have the required permission
3489 */
3490 private void enforceReadPrivilegedPermission() {
3491 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3492 null);
3493 }
3494
3495 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003496 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3497 * permission.
3498 *
3499 * @throws SecurityException if the caller does not have the required permission
3500 */
3501 private void enforceSendSmsPermission() {
3502 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3503 }
3504
3505 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003506 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003507 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003508 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003509 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003510 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003511 ComponentName componentName =
3512 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3513 if(componentName == null) {
3514 throw new SecurityException("Caller not current active visual voicemail package[null]");
3515 }
3516 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003517 if (!callingPackage.equals(vvmPackage)) {
3518 throw new SecurityException("Caller not current active visual voicemail package[" +
3519 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003520 }
3521 }
3522
3523 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003524 * Return the application ID for the app type.
3525 *
3526 * @param subId the subscription ID that this request applies to.
3527 * @param appType the uicc app type.
3528 * @return Application ID for specificied app type, or null if no uicc.
3529 */
3530 @Override
3531 public String getAidForAppType(int subId, int appType) {
3532 enforceReadPrivilegedPermission();
3533 Phone phone = getPhone(subId);
3534 if (phone == null) {
3535 return null;
3536 }
3537 String aid = null;
3538 try {
3539 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3540 .getApplicationByType(appType).getAid();
3541 } catch (Exception e) {
3542 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3543 }
3544 return aid;
3545 }
3546
Youhan Wang4001d252016-05-11 10:29:41 -07003547 /**
3548 * Return the Electronic Serial Number.
3549 *
3550 * @param subId the subscription ID that this request applies to.
3551 * @return ESN or null if error.
3552 */
3553 @Override
3554 public String getEsn(int subId) {
3555 enforceReadPrivilegedPermission();
3556 Phone phone = getPhone(subId);
3557 if (phone == null) {
3558 return null;
3559 }
3560 String esn = null;
3561 try {
3562 esn = phone.getEsn();
3563 } catch (Exception e) {
3564 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3565 }
3566 return esn;
3567 }
3568
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003569 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003570 * Return the Preferred Roaming List Version.
3571 *
3572 * @param subId the subscription ID that this request applies to.
3573 * @return PRLVersion or null if error.
3574 */
3575 @Override
3576 public String getCdmaPrlVersion(int subId) {
3577 enforceReadPrivilegedPermission();
3578 Phone phone = getPhone(subId);
3579 if (phone == null) {
3580 return null;
3581 }
3582 String cdmaPrlVersion = null;
3583 try {
3584 cdmaPrlVersion = phone.getCdmaPrlVersion();
3585 } catch (Exception e) {
3586 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3587 }
3588 return cdmaPrlVersion;
3589 }
3590
3591 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003592 * Get snapshot of Telephony histograms
3593 * @return List of Telephony histograms
3594 * @hide
3595 */
3596 @Override
3597 public List<TelephonyHistogram> getTelephonyHistograms() {
3598 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3599 return RIL.getTelephonyRILTimingHistograms();
3600 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003601
3602 /**
3603 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003604 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003605 * Require system privileges. In the future we may add this to carrier APIs.
3606 *
3607 * @return The number of carriers set successfully, should match length of carriers
3608 */
3609 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003610 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003611 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003612
Meng Wang9b7c4e92017-02-17 11:41:27 -08003613 if (carriers == null) {
3614 throw new NullPointerException("carriers cannot be null");
3615 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003616
3617 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003618 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3619 return retVal[0];
3620 }
3621
3622 /**
3623 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003624 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003625 * Require system privileges. In the future we may add this to carrier APIs.
3626 *
3627 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3628 * means all carriers are allowed.
3629 */
3630 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003631 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003632 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003633 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003634 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3635 }
3636
fionaxu59545b42016-05-25 15:53:37 -07003637 /**
3638 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3639 * @param subId the subscription ID that this action applies to.
3640 * @param enabled control enable or disable metered apns.
3641 * {@hide}
3642 */
3643 @Override
3644 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3645 enforceModifyPermission();
3646 final Phone phone = getPhone(subId);
3647 if (phone == null) {
3648 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3649 return;
3650 }
3651 try {
3652 phone.carrierActionSetMeteredApnsEnabled(enabled);
3653 } catch (Exception e) {
3654 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3655 }
3656 }
3657
3658 /**
3659 * Action set from carrier signalling broadcast receivers to enable/disable radio
3660 * @param subId the subscription ID that this action applies to.
3661 * @param enabled control enable or disable radio.
3662 * {@hide}
3663 */
3664 @Override
3665 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3666 enforceModifyPermission();
3667 final Phone phone = getPhone(subId);
3668 if (phone == null) {
3669 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3670 return;
3671 }
3672 try {
3673 phone.carrierActionSetRadioEnabled(enabled);
3674 } catch (Exception e) {
3675 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3676 }
3677 }
3678
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003679 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003680 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3681 * network status based on which carrier apps could apply actions accordingly,
3682 * enable/disable default url handler for example.
3683 *
3684 * @param subId the subscription ID that this action applies to.
3685 * @param report control start/stop reporting the default network status.
3686 * {@hide}
3687 */
3688 @Override
3689 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3690 enforceModifyPermission();
3691 final Phone phone = getPhone(subId);
3692 if (phone == null) {
3693 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3694 return;
3695 }
3696 try {
3697 phone.carrierActionReportDefaultNetworkStatus(report);
3698 } catch (Exception e) {
3699 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3700 }
3701 }
3702
3703 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003704 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3705 * bug report is being generated.
3706 */
3707 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003708 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003709 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3710 != PackageManager.PERMISSION_GRANTED) {
3711 writer.println("Permission Denial: can't dump Phone from pid="
3712 + Binder.getCallingPid()
3713 + ", uid=" + Binder.getCallingUid()
3714 + "without permission "
3715 + android.Manifest.permission.DUMP);
3716 return;
3717 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003718 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003719 }
Jack Yueb89b242016-06-22 13:27:47 -07003720
3721 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003722 * Get aggregated video call data usage since boot.
3723 *
3724 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3725 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003726 * {@hide}
3727 */
3728 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003729 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3731 null);
3732
Jack Yu84291ec2017-05-26 16:07:50 -07003733 // NetworkStatsService keeps tracking the active network interface and identity. It
3734 // records the delta with the corresponding network identity. We just return the total video
3735 // call data usage snapshot since boot.
3736 Phone phone = getPhone(subId);
3737 if (phone != null) {
3738 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003739 }
Jack Yu84291ec2017-05-26 16:07:50 -07003740 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003741 }
Jack Yu75ab2952016-07-08 14:29:33 -07003742
3743 /**
3744 * Policy control of data connection. Usually used when data limit is passed.
3745 * @param enabled True if enabling the data, otherwise disabling.
3746 * @param subId Subscription index
3747 * {@hide}
3748 */
3749 @Override
3750 public void setPolicyDataEnabled(boolean enabled, int subId) {
3751 enforceModifyPermission();
3752 Phone phone = getPhone(subId);
3753 if (phone != null) {
3754 phone.setPolicyDataEnabled(enabled);
3755 }
3756 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003757
3758 /**
3759 * Get Client request stats
3760 * @return List of Client Request Stats
3761 * @hide
3762 */
3763 @Override
3764 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3765 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3766 return null;
3767 }
3768
3769 Phone phone = getPhone(subId);
3770 if (phone != null) {
3771 return phone.getClientRequestStats();
3772 }
3773
3774 return null;
3775 }
3776
3777 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3778 if (workSource != null) {
3779 return workSource;
3780 }
3781
3782 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3783 workSource = new WorkSource(uid, packageName);
3784 return workSource;
3785 }
Jack Yueb4124c2017-02-16 15:32:43 -08003786
3787 /**
Grace Chen70990072017-03-24 17:21:30 -07003788 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003789 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003790 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003791 * @param state State of SIM (power down, power up, pass through)
3792 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3793 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3794 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003795 *
3796 **/
3797 @Override
Grace Chen70990072017-03-24 17:21:30 -07003798 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003799 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003800 Phone phone = PhoneFactory.getPhone(slotIndex);
3801
Jack Yueb4124c2017-02-16 15:32:43 -08003802 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003803 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003804 }
3805 }
Shuo Qiandd210312017-04-12 22:11:33 +00003806
Tyler Gunn65d45c22017-06-05 11:22:26 -07003807 private boolean isUssdApiAllowed(int subId) {
3808 CarrierConfigManager configManager =
3809 (CarrierConfigManager) mPhone.getContext().getSystemService(
3810 Context.CARRIER_CONFIG_SERVICE);
3811 if (configManager == null) {
3812 return false;
3813 }
3814 PersistableBundle pb = configManager.getConfigForSubId(subId);
3815 if (pb == null) {
3816 return false;
3817 }
3818 return pb.getBoolean(
3819 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3820 }
3821
Shuo Qiandd210312017-04-12 22:11:33 +00003822 /**
3823 * Check if phone is in emergency callback mode
3824 * @return true if phone is in emergency callback mode
3825 * @param subId sub id
3826 */
3827 public boolean getEmergencyCallbackMode(int subId) {
3828 final Phone phone = getPhone(subId);
3829 if (phone != null) {
3830 return phone.isInEcm();
3831 } else {
3832 return false;
3833 }
3834 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003835
3836 /**
3837 * Get the current signal strength information for the given subscription.
3838 * Because this information is not updated when the device is in a low power state
3839 * it should not be relied-upon to be current.
3840 * @param subId Subscription index
3841 * @return the most recent cached signal strength info from the modem
3842 */
3843 @Override
3844 public SignalStrength getSignalStrength(int subId) {
3845 Phone p = getPhone(subId);
3846 if (p == null) {
3847 return null;
3848 }
3849
3850 return p.getSignalStrength();
3851 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003852}