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