blob: d7055801a3398d4d85ff181955f496e4c33e4ecf [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
fionaxuf32acdf2017-11-27 22:51:16 -08001771 @Override
1772 public int getSubscriptionCarrierId(int subId) {
1773 final Phone phone = getPhone(subId);
1774 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1775 }
1776
1777 @Override
1778 public String getSubscriptionCarrierName(int subId) {
1779 final Phone phone = getPhone(subId);
1780 return phone == null ? null : phone.getCarrierName();
1781 }
1782
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 //
1784 // Internal helper methods.
1785 //
1786
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001787 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1789 *
1790 * @throws SecurityException if the caller does not have the required permission
1791 */
1792 private void enforceModifyPermission() {
1793 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1794 }
1795
1796 /**
Junda Liua2e36012014-07-09 18:30:01 -07001797 * Make sure either system app or the caller has carrier privilege.
1798 *
1799 * @throws SecurityException if the caller does not have the required permission/privilege
1800 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001801 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001802 int permission = mApp.checkCallingOrSelfPermission(
1803 android.Manifest.permission.MODIFY_PHONE_STATE);
1804 if (permission == PackageManager.PERMISSION_GRANTED) {
1805 return;
1806 }
1807
1808 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001809 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001810 }
1811
1812 /**
1813 * Make sure the caller has carrier privilege.
1814 *
1815 * @throws SecurityException if the caller does not have the required permission
1816 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001817 private void enforceCarrierPrivilege(int subId) {
1818 if (getCarrierPrivilegeStatus(subId) !=
1819 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001820 loge("No Carrier Privilege.");
1821 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001822 }
1823 }
1824
1825 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 * Make sure the caller has the CALL_PHONE permission.
1827 *
1828 * @throws SecurityException if the caller does not have the required permission
1829 */
1830 private void enforceCallPermission() {
1831 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1832 }
1833
Stuart Scott8eef64f2015-04-08 15:13:54 -07001834 private void enforceConnectivityInternalPermission() {
1835 mApp.enforceCallingOrSelfPermission(
1836 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1837 "ConnectivityService");
1838 }
1839
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 private String createTelUrl(String number) {
1841 if (TextUtils.isEmpty(number)) {
1842 return null;
1843 }
1844
Jake Hambye994d462014-02-03 13:10:13 -08001845 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
1847
Ihab Awadf9e92732013-12-05 18:02:52 -08001848 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1850 }
1851
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001852 private static void logv(String msg) {
1853 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1854 }
1855
Ihab Awadf9e92732013-12-05 18:02:52 -08001856 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1858 }
1859
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001860 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001862 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001863 }
1864
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001866 public int getActivePhoneTypeForSlot(int slotIndex) {
1867 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 if (phone == null) {
1869 return PhoneConstants.PHONE_TYPE_NONE;
1870 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001871 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
1875 /**
1876 * Returns the CDMA ERI icon index to display
1877 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001878 @Override
1879 public int getCdmaEriIconIndex(String callingPackage) {
1880 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001881 }
1882
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001884 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1885 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1886 return -1;
1887 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 final Phone phone = getPhone(subId);
1889 if (phone != null) {
1890 return phone.getCdmaEriIconIndex();
1891 } else {
1892 return -1;
1893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
1896 /**
1897 * Returns the CDMA ERI icon mode,
1898 * 0 - ON
1899 * 1 - FLASHING
1900 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 @Override
1902 public int getCdmaEriIconMode(String callingPackage) {
1903 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1908 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1909 return -1;
1910 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
1913 return phone.getCdmaEriIconMode();
1914 } else {
1915 return -1;
1916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 /**
1920 * Returns the CDMA ERI text,
1921 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001922 @Override
1923 public String getCdmaEriText(String callingPackage) {
1924 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001928 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1929 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1930 return null;
1931 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001932 final Phone phone = getPhone(subId);
1933 if (phone != null) {
1934 return phone.getCdmaEriText();
1935 } else {
1936 return null;
1937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
1940 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001941 * Returns the CDMA MDN.
1942 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001944 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001945 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 final Phone phone = getPhone(subId);
1947 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1948 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001949 } else {
1950 return null;
1951 }
1952 }
1953
1954 /**
1955 * Returns the CDMA MIN.
1956 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001958 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001959 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 final Phone phone = getPhone(subId);
1961 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1962 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001963 } else {
1964 return null;
1965 }
1966 }
1967
1968 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 * Returns true if CDMA provisioning needs to run.
1970 */
1971 public boolean needsOtaServiceProvisioning() {
1972 return mPhone.needsOtaServiceProvisioning();
1973 }
1974
1975 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001976 * Sets the voice mail number of a given subId.
1977 */
1978 @Override
1979 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001980 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001981 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1982 new Pair<String, String>(alphaTag, number), new Integer(subId));
1983 return success;
1984 }
1985
Ta-wei Yen87c49842016-05-13 21:19:52 -07001986 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001987 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1989 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1990 if (!TextUtils.equals(callingPackage, systemDialer)) {
1991 throw new SecurityException("caller must be system dialer");
1992 }
1993 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1994 if (phoneAccountHandle == null){
1995 return null;
1996 }
1997 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
1998 }
1999
2000 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002001 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2003 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2004 return null;
2005 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002006 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2007 }
2008
2009 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002010 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2011 VisualVoicemailSmsFilterSettings settings) {
2012 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002013 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002014 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2015 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 }
2017
2018 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002019 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002021 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002022 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 }
2024
2025 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002026 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2027 String callingPackage, int subId) {
2028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002029 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002030 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002031 }
2032
2033 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002034 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002035 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002036 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002037 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2038 }
2039
2040 @Override
2041 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2042 String number, int port, String text, PendingIntent sentIntent) {
2043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002044 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002045 enforceSendSmsPermission();
2046 // Make the calls as the phone process.
2047 final long identity = Binder.clearCallingIdentity();
2048 try {
2049 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2050 if (port == 0) {
2051 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2052 sentIntent, null, false);
2053 } else {
2054 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2055 smsManager.sendDataMessageWithSelfPermissions(number, null,
2056 (short) port, data, sentIntent, null);
2057 }
2058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002061 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002062 /**
fionaxu0152e512016-11-14 13:36:14 -08002063 * Sets the voice activation state of a given subId.
2064 */
2065 @Override
2066 public void setVoiceActivationState(int subId, int activationState) {
2067 enforceModifyPermissionOrCarrierPrivilege(subId);
2068 final Phone phone = getPhone(subId);
2069 if (phone != null) {
2070 phone.setVoiceActivationState(activationState);
2071 } else {
2072 loge("setVoiceActivationState fails with invalid subId: " + subId);
2073 }
2074 }
2075
2076 /**
2077 * Sets the data activation state of a given subId.
2078 */
2079 @Override
2080 public void setDataActivationState(int subId, int activationState) {
2081 enforceModifyPermissionOrCarrierPrivilege(subId);
2082 final Phone phone = getPhone(subId);
2083 if (phone != null) {
2084 phone.setDataActivationState(activationState);
2085 } else {
2086 loge("setVoiceActivationState fails with invalid subId: " + subId);
2087 }
2088 }
2089
2090 /**
2091 * Returns the voice activation state of a given subId.
2092 */
2093 @Override
2094 public int getVoiceActivationState(int subId, String callingPackage) {
2095 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2096 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2097 }
2098 final Phone phone = getPhone(subId);
2099 if (phone != null) {
2100 return phone.getVoiceActivationState();
2101 } else {
2102 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2103 }
2104 }
2105
2106 /**
2107 * Returns the data activation state of a given subId.
2108 */
2109 @Override
2110 public int getDataActivationState(int subId, String callingPackage) {
2111 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2112 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2113 }
2114 final Phone phone = getPhone(subId);
2115 if (phone != null) {
2116 return phone.getDataActivationState();
2117 } else {
2118 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2119 }
2120 }
2121
2122 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 * Returns the unread count of voicemails
2124 */
2125 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002126 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002127 }
2128
2129 /**
2130 * Returns the unread count of voicemails for a subId
2131 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 final Phone phone = getPhone(subId);
2135 if (phone != null) {
2136 return phone.getVoiceMessageCount();
2137 } else {
2138 return 0;
2139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 }
2141
2142 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002143 * returns true, if the device is in a state where both voice and data
2144 * are supported simultaneously. This can change based on location or network condition.
2145 */
2146 @Override
2147 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2148 final Phone phone = getPhone(subId);
2149 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2150 }
2151
2152 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002153 * Send the dialer code if called from the current default dialer or the caller has
2154 * carrier privilege.
2155 * @param inputCode The dialer code to send
2156 */
2157 @Override
2158 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2160 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2161 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2162 enforceCarrierPrivilege(getDefaultSubscription());
2163 }
2164 mPhone.sendDialerSpecialCode(inputCode);
2165 }
2166
2167 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002168 * Returns the data network type.
2169 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 *
2171 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2172 */
2173 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002174 public int getNetworkType() {
2175 final Phone phone = getPhone(getDefaultSubscription());
2176 if (phone != null) {
2177 return phone.getServiceState().getDataNetworkType();
2178 } else {
2179 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2180 }
Wink Saville36469e72014-06-11 15:17:00 -07002181 }
2182
2183 /**
2184 * Returns the network type for a subId
2185 */
2186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2188 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2189 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2190 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002191
Sanket Padawe356d7632015-06-22 14:03:32 -07002192 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 return phone.getServiceState().getDataNetworkType();
2195 } else {
2196 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
2200 /**
2201 * Returns the data network type
2202 */
2203 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002204 public int getDataNetworkType(String callingPackage) {
2205 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002206 }
2207
2208 /**
2209 * Returns the data network type for a subId
2210 */
2211 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002212 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2213 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2214 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2215 }
2216
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 final Phone phone = getPhone(subId);
2218 if (phone != null) {
2219 return phone.getServiceState().getDataNetworkType();
2220 } else {
2221 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224
2225 /**
Wink Saville36469e72014-06-11 15:17:00 -07002226 * Returns the Voice network type for a subId
2227 */
2228 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002229 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2230 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2231 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2232 }
2233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 final Phone phone = getPhone(subId);
2235 if (phone != null) {
2236 return phone.getServiceState().getVoiceNetworkType();
2237 } else {
2238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
2243 * @return true if a ICC card is present
2244 */
2245 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002246 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002247 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2248 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002249 }
2250
2251 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002252 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002253 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002255 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2256 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002257 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002259 } else {
2260 return false;
2261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
2264 /**
2265 * Return if the current radio is LTE on CDMA. This
2266 * is a tri-state return value as for a period of time
2267 * the mode may be unknown.
2268 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002271 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 @Override
2274 public int getLteOnCdmaMode(String callingPackage) {
2275 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002279 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2280 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2281 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2282 }
2283
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 final Phone phone = getPhone(subId);
2285 if (phone == null) {
2286 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2287 } else {
2288 return phone.getLteOnCdmaMode();
2289 }
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
2292 public void setPhone(Phone phone) {
2293 mPhone = phone;
2294 }
2295
2296 /**
2297 * {@hide}
2298 * Returns Default subId, 0 in the case of single standby.
2299 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002300 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002301 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002302 }
2303
Shishir Agrawala9f32182016-04-12 12:00:16 -07002304 private int getSlotForDefaultSubscription() {
2305 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2306 }
2307
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002309 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002311
2312 /**
2313 * @see android.telephony.TelephonyManager.WifiCallingChoices
2314 */
2315 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002316 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2317 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002318 }
2319
2320 /**
2321 * @see android.telephony.TelephonyManager.WifiCallingChoices
2322 */
2323 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002324 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2325 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2326 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002327 }
2328
Sailesh Nepald1e68152013-12-12 19:08:02 -08002329 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002330 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002331 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002332 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002333
Shishir Agrawal566b7612013-10-28 14:41:00 -07002334 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002335 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2336 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002337 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002338
Derek Tan740e1672017-06-27 14:56:27 -07002339 if (TextUtils.equals(ISDR_AID, aid)) {
2340 // Only allows LPA to open logical channel to ISD-R.
2341 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2342 ComponentInfo bestComponent =
2343 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2344 if (bestComponent == null
2345 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2346 loge("The calling package is not allowed to access ISD-R.");
2347 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2348 }
2349 }
2350
2351 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002352 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002353 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002354 if (DBG) log("iccOpenLogicalChannel: " + response);
2355 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002356 }
2357
2358 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002359 public boolean iccCloseLogicalChannel(int subId, int channel) {
2360 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002362 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363 if (channel < 0) {
2364 return false;
2365 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002366 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 if (DBG) log("iccCloseLogicalChannel: " + success);
2368 return success;
2369 }
2370
2371 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002373 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002374 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375
2376 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002377 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2378 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002379 " data=" + data);
2380 }
2381
2382 if (channel < 0) {
2383 return "";
2384 }
2385
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002386 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002388 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2389
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390 // Append the returned status code to the end of the response payload.
2391 String s = Integer.toHexString(
2392 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002393 if (response.payload != null) {
2394 s = IccUtils.bytesToHexString(response.payload) + s;
2395 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396 return s;
2397 }
Jake Hambye994d462014-02-03 13:10:13 -08002398
Evan Charltonc66da362014-05-16 14:06:40 -07002399 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002401 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403
2404 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2406 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002407 }
2408
2409 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002411 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002413 // Append the returned status code to the end of the response payload.
2414 String s = Integer.toHexString(
2415 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002416 if (response.payload != null) {
2417 s = IccUtils.bytesToHexString(response.payload) + s;
2418 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002419 return s;
2420 }
2421
2422 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002423 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002424 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426
2427 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002428 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002429 p1 + " " + p2 + " " + p3 + ":" + filePath);
2430 }
2431
2432 IccIoResult response =
2433 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2435 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002436
2437 if (DBG) {
2438 log("Exchange SIM_IO [R]" + response);
2439 }
2440
2441 byte[] result = null;
2442 int length = 2;
2443 if (response.payload != null) {
2444 length = 2 + response.payload.length;
2445 result = new byte[length];
2446 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2447 } else {
2448 result = new byte[length];
2449 }
2450
2451 result[length - 1] = (byte) response.sw2;
2452 result[length - 2] = (byte) response.sw1;
2453 return result;
2454 }
2455
Nathan Haroldb3014052017-01-25 15:57:32 -08002456 /**
2457 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2458 * on a particular subscription
2459 */
2460 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002461 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2462 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002463 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2464 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2465 return null;
2466 }
2467 Object response = sendRequest(
2468 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2469 if (response instanceof String[]) {
2470 return (String[]) response;
2471 }
2472 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2473 return null;
2474 }
2475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 public String sendEnvelopeWithStatus(int subId, String content) {
2478 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002479
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002481 if (response.payload == null) {
2482 return "";
2483 }
2484
2485 // Append the returned status code to the end of the response payload.
2486 String s = Integer.toHexString(
2487 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2488 s = IccUtils.bytesToHexString(response.payload) + s;
2489 return s;
2490 }
2491
Jake Hambye994d462014-02-03 13:10:13 -08002492 /**
2493 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2494 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2495 *
2496 * @param itemID the ID of the item to read
2497 * @return the NV item as a String, or null on error.
2498 */
2499 @Override
2500 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002501 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002502 if (DBG) log("nvReadItem: item " + itemID);
2503 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2504 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2505 return value;
2506 }
2507
2508 /**
2509 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2510 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2511 *
2512 * @param itemID the ID of the item to read
2513 * @param itemValue the value to write, as a String
2514 * @return true on success; false on any failure
2515 */
2516 @Override
2517 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002519 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2520 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2521 new Pair<Integer, String>(itemID, itemValue));
2522 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2523 return success;
2524 }
2525
2526 /**
2527 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2528 * Used for device configuration by some CDMA operators.
2529 *
2530 * @param preferredRoamingList byte array containing the new PRL
2531 * @return true on success; false on any failure
2532 */
2533 @Override
2534 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002535 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002536 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2537 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2538 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2539 return success;
2540 }
2541
2542 /**
2543 * Perform the specified type of NV config reset.
2544 * Used for device configuration by some CDMA operators.
2545 *
2546 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2547 * @return true on success; false on any failure
2548 */
2549 @Override
2550 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002551 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002552 if (DBG) log("nvResetConfig: type " + resetType);
2553 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2554 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2555 return success;
2556 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002557
2558 /**
Wink Saville36469e72014-06-11 15:17:00 -07002559 * {@hide}
2560 * Returns Default sim, 0 in the case of single standby.
2561 */
2562 public int getDefaultSim() {
2563 //TODO Need to get it from Telephony Devcontroller
2564 return 0;
2565 }
2566
Svet Ganovb320e182015-04-16 12:30:10 -07002567 public String[] getPcscfAddress(String apnType, String callingPackage) {
2568 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2569 return new String[0];
2570 }
2571
2572
ram87fca6f2014-07-18 18:58:44 +05302573 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002574 }
2575
Brad Ebinger51f743a2017-01-23 13:50:20 -08002576 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002577 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2578 * feature or {@link null} if the service is not available. If the feature is available, the
2579 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002580 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002581 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2582 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002583 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002584 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2585 }
2586
2587 /**
2588 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
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 IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2594 IImsServiceFeatureCallback callback) {
2595 enforceModifyPermission();
2596 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2597 }
2598
2599 /**
2600 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2601 * feature during emergency calling or {@link null} if the service is not available. If the
2602 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2603 * listener for feature updates.
2604 */
2605 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2606 enforceModifyPermission();
2607 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002608 }
2609
Wink Saville36469e72014-06-11 15:17:00 -07002610 public void setImsRegistrationState(boolean registered) {
2611 enforceModifyPermission();
2612 mPhone.setImsRegistrationState(registered);
2613 }
2614
2615 /**
Stuart Scott54788802015-03-30 13:18:01 -07002616 * Set the network selection mode to automatic.
2617 *
2618 */
2619 @Override
2620 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002621 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002622 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2623 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2624 }
2625
2626 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002627 * Set the network selection mode to manual with the selected carrier.
2628 */
2629 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002630 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002631 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002632 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002633 OperatorInfo operator = new OperatorInfo(
2634 /* operatorAlphaLong */ "",
2635 /* operatorAlphaShort */ "",
2636 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002637 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002638 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2639 persistSelection);
2640 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002641 }
2642
2643 /**
2644 * Scans for available networks.
2645 */
2646 @Override
2647 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002648 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002649 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2650 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2651 CMD_PERFORM_NETWORK_SCAN, null, subId);
2652 return result;
2653 }
2654
2655 /**
yinxub1bed742017-04-17 11:45:04 -07002656 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002657 *
yinxub1bed742017-04-17 11:45:04 -07002658 * @param subId id of the subscription
2659 * @param request contains the radio access networks with bands/channels to scan
2660 * @param messenger callback messenger for scan results or errors
2661 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002662 * @return the id of the requested scan which can be used to stop the scan.
2663 */
2664 @Override
2665 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2666 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002667 enforceModifyPermissionOrCarrierPrivilege(subId);
2668 return mNetworkScanRequestTracker.startNetworkScan(
2669 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002670 }
2671
2672 /**
2673 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002674 *
2675 * @param subId id of the subscription
2676 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002677 */
2678 @Override
2679 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002680 enforceModifyPermissionOrCarrierPrivilege(subId);
2681 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002682 }
2683
2684 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002685 * Get the calculated preferred network type.
2686 * Used for debugging incorrect network type.
2687 *
2688 * @return the preferred network type, defined in RILConstants.java.
2689 */
2690 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002691 public int getCalculatedPreferredNetworkType(String callingPackage) {
2692 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2693 return RILConstants.PREFERRED_NETWORK_MODE;
2694 }
2695
Amit Mahajan43330e02014-11-18 11:54:45 -08002696 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002697 }
2698
2699 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002700 * Get the preferred network type.
2701 * Used for device configuration by some CDMA operators.
2702 *
2703 * @return the preferred network type, defined in RILConstants.java.
2704 */
2705 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002706 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002707 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002708 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002709 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002710 int networkType = (result != null ? result[0] : -1);
2711 if (DBG) log("getPreferredNetworkType: " + networkType);
2712 return networkType;
2713 }
2714
2715 /**
2716 * Set the preferred network type.
2717 * Used for device configuration by some CDMA operators.
2718 *
2719 * @param networkType the preferred network type, defined in RILConstants.java.
2720 * @return true on success; false on any failure.
2721 */
2722 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002723 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002724 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002725 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2726 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002727 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002728 if (success) {
2729 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002730 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002731 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002732 return success;
2733 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002734
2735 /**
Junda Liu475951f2014-11-07 16:45:03 -08002736 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2737 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2738 * tethering.
2739 *
2740 * @return 0: Not required. 1: required. 2: Not set.
2741 * @hide
2742 */
2743 @Override
2744 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002745 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002746 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2747 Settings.Global.TETHER_DUN_REQUIRED, 2);
2748 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2749 // config_tether_apndata.
2750 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2751 dunRequired = 1;
2752 }
2753 return dunRequired;
2754 }
2755
2756 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002757 * Set mobile data enabled
2758 * Used by the user through settings etc to turn on/off mobile data
2759 *
2760 * @param enable {@code true} turn turn data on, else {@code false}
2761 */
2762 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002763 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002764 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002765 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002766 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002767 Phone phone = PhoneFactory.getPhone(phoneId);
2768 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002769 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2770 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002771 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002772 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002773 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002774 }
2775
2776 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002777 * Get the user enabled state of Mobile Data.
2778 *
2779 * TODO: remove and use isUserDataEnabled.
2780 * This can't be removed now because some vendor codes
2781 * calls through ITelephony directly while they should
2782 * use TelephonyManager.
2783 *
2784 * @return true on enabled
2785 */
2786 @Override
2787 public boolean getDataEnabled(int subId) {
2788 return isUserDataEnabled(subId);
2789 }
2790
2791 /**
2792 * Get whether mobile data is enabled per user setting.
2793 *
2794 * There are other factors deciding whether mobile data is actually enabled, but they are
2795 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002796 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002797 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002798 *
2799 * @return {@code true} if data is enabled else {@code false}
2800 */
2801 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002802 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002803 try {
2804 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2805 null);
2806 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002807 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002808 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002809 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002810 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002811 Phone phone = PhoneFactory.getPhone(phoneId);
2812 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002813 boolean retVal = phone.isUserDataEnabled();
2814 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002815 return retVal;
2816 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002817 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2818 return false;
2819 }
2820 }
2821
2822 /**
2823 * Get whether mobile data is enabled.
2824 *
2825 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2826 * whether mobile data is actually enabled.
2827 *
2828 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2829 *
2830 * @return {@code true} if data is enabled else {@code false}
2831 */
2832 @Override
2833 public boolean isDataEnabled(int subId) {
2834 try {
2835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2836 null);
2837 } catch (Exception e) {
2838 enforceModifyPermissionOrCarrierPrivilege(subId);
2839 }
2840 int phoneId = mSubscriptionController.getPhoneId(subId);
2841 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2842 Phone phone = PhoneFactory.getPhone(phoneId);
2843 if (phone != null) {
2844 boolean retVal = phone.isDataEnabled();
2845 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2846 return retVal;
2847 } else {
2848 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002849 return false;
2850 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002851 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002852
2853 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002854 public int getCarrierPrivilegeStatus(int subId) {
2855 final Phone phone = getPhone(subId);
2856 if (phone == null) {
2857 loge("getCarrierPrivilegeStatus: Invalid subId");
2858 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2859 }
2860 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002861 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002862 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002863 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2864 }
2865 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002866 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002867 }
Junda Liu29340342014-07-10 15:23:27 -07002868
2869 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002870 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002871 if (TextUtils.isEmpty(pkgName))
2872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002873 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002874 if (card == null) {
2875 loge("checkCarrierPrivilegesForPackage: No UICC");
2876 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2877 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002878 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2879 }
2880
2881 @Override
2882 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002883 if (TextUtils.isEmpty(pkgName))
2884 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002885 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2886 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2887 UiccCard card = UiccController.getInstance().getUiccCard(i);
2888 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002889 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002890 continue;
2891 }
2892
2893 result = card.getCarrierPrivilegeStatus(
2894 mPhone.getContext().getPackageManager(), pkgName);
2895 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2896 break;
2897 }
2898 }
2899
2900 return result;
Junda Liu29340342014-07-10 15:23:27 -07002901 }
Derek Tan89e89d42014-07-08 17:00:10 -07002902
2903 @Override
Junda Liue64de782015-04-16 17:19:16 -07002904 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2905 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2906 loge("phoneId " + phoneId + " is not valid.");
2907 return null;
2908 }
2909 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002910 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002911 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002912 return null ;
2913 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002914 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002915 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002916 }
2917
Amith Yamasani6e118872016-02-19 12:53:51 -08002918 @Override
2919 public List<String> getPackagesWithCarrierPrivileges() {
2920 PackageManager pm = mPhone.getContext().getPackageManager();
2921 List<String> privilegedPackages = new ArrayList<>();
2922 List<PackageInfo> packages = null;
2923 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2924 UiccCard card = UiccController.getInstance().getUiccCard(i);
2925 if (card == null) {
2926 // No UICC in that slot.
2927 continue;
2928 }
2929 if (card.hasCarrierPrivilegeRules()) {
2930 if (packages == null) {
2931 // Only check packages in user 0 for now
2932 packages = pm.getInstalledPackagesAsUser(
2933 PackageManager.MATCH_DISABLED_COMPONENTS
2934 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2935 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2936 }
2937 for (int p = packages.size() - 1; p >= 0; p--) {
2938 PackageInfo pkgInfo = packages.get(p);
2939 if (pkgInfo != null && pkgInfo.packageName != null
2940 && card.getCarrierPrivilegeStatus(pkgInfo)
2941 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2942 privilegedPackages.add(pkgInfo.packageName);
2943 }
2944 }
2945 }
2946 }
2947 return privilegedPackages;
2948 }
2949
Wink Savilleb564aae2014-10-23 10:18:09 -07002950 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 final Phone phone = getPhone(subId);
2952 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002953 if (card == null) {
2954 loge("getIccId: No UICC");
2955 return null;
2956 }
2957 String iccId = card.getIccId();
2958 if (TextUtils.isEmpty(iccId)) {
2959 loge("getIccId: ICC ID is null or empty.");
2960 return null;
2961 }
2962 return iccId;
2963 }
2964
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002965 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002966 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2967 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002968 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002969
Jeff Sharkey85190e62014-12-05 09:40:12 -08002970 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002971 final Phone phone = getPhone(subId);
2972 if (phone == null) {
2973 return false;
2974 }
2975 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002976
2977 if (DBG_MERGE) {
2978 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2979 + subscriberId + " to " + number);
2980 }
2981
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002982 if (TextUtils.isEmpty(iccId)) {
2983 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002984 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002985
Jeff Sharkey85190e62014-12-05 09:40:12 -08002986 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2987
2988 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002989 if (alphaTag == null) {
2990 editor.remove(alphaTagPrefKey);
2991 } else {
2992 editor.putString(alphaTagPrefKey, alphaTag);
2993 }
2994
Jeff Sharkey85190e62014-12-05 09:40:12 -08002995 // Record both the line number and IMSI for this ICCID, since we need to
2996 // track all merged IMSIs based on line number
2997 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2998 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002999 if (number == null) {
3000 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003001 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003002 } else {
3003 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003004 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003005 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003006
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003007 editor.commit();
3008 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003009 }
3010
3011 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003012 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003013 // This is open to apps with WRITE_SMS.
3014 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003015 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003016 return null;
3017 }
Derek Tan97ebb422014-09-05 16:55:38 -07003018
3019 String iccId = getIccId(subId);
3020 if (iccId != null) {
3021 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003022 if (DBG_MERGE) {
3023 log("getLine1NumberForDisplay returning " +
3024 mTelephonySharedPreferences.getString(numberPrefKey, null));
3025 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003026 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003027 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003028 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003029 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003030 }
3031
3032 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003033 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3034 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3035 return null;
3036 }
Derek Tan97ebb422014-09-05 16:55:38 -07003037
3038 String iccId = getIccId(subId);
3039 if (iccId != null) {
3040 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003041 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003042 }
Derek Tan97ebb422014-09-05 16:55:38 -07003043 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003044 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003045
3046 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003047 public String[] getMergedSubscriberIds(String callingPackage) {
3048 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3049 return null;
3050 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003051 final Context context = mPhone.getContext();
3052 final TelephonyManager tele = TelephonyManager.from(context);
3053 final SubscriptionManager sub = SubscriptionManager.from(context);
3054
3055 // Figure out what subscribers are currently active
3056 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003057 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3058 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 final int[] subIds = sub.getActiveSubscriptionIdList();
3062 for (int subId : subIds) {
3063 activeSubscriberIds.add(tele.getSubscriberId(subId));
3064 }
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003067 }
3068
3069 // First pass, find a number override for an active subscriber
3070 String mergeNumber = null;
3071 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3072 for (String key : prefs.keySet()) {
3073 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3074 final String subscriberId = (String) prefs.get(key);
3075 if (activeSubscriberIds.contains(subscriberId)) {
3076 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3077 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3078 mergeNumber = (String) prefs.get(numberKey);
3079 if (DBG_MERGE) {
3080 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3081 + " for active subscriber " + subscriberId);
3082 }
3083 if (!TextUtils.isEmpty(mergeNumber)) {
3084 break;
3085 }
3086 }
3087 }
3088 }
3089
3090 // Shortcut when no active merged subscribers
3091 if (TextUtils.isEmpty(mergeNumber)) {
3092 return null;
3093 }
3094
3095 // Second pass, find all subscribers under that line override
3096 final ArraySet<String> result = new ArraySet<>();
3097 for (String key : prefs.keySet()) {
3098 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3099 final String number = (String) prefs.get(key);
3100 if (mergeNumber.equals(number)) {
3101 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3102 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3103 final String subscriberId = (String) prefs.get(subscriberKey);
3104 if (!TextUtils.isEmpty(subscriberId)) {
3105 result.add(subscriberId);
3106 }
3107 }
3108 }
3109 }
3110
3111 final String[] resultArray = result.toArray(new String[result.size()]);
3112 Arrays.sort(resultArray);
3113 if (DBG_MERGE) {
3114 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3115 }
3116 return resultArray;
3117 }
3118
3119 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003120 public boolean setOperatorBrandOverride(int subId, String brand) {
3121 enforceCarrierPrivilege(subId);
3122 final Phone phone = getPhone(subId);
3123 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003124 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003125
3126 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003127 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003128 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3129 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003130 enforceCarrierPrivilege(subId);
3131 final Phone phone = getPhone(subId);
3132 if (phone == null) {
3133 return false;
3134 }
3135 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003136 cdmaNonRoamingList);
3137 }
3138
3139 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003140 public void setRadioCapability(RadioAccessFamily[] rafs) {
3141 try {
3142 ProxyController.getInstance().setRadioCapability(rafs);
3143 } catch (RuntimeException e) {
3144 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3145 }
3146 }
3147
3148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003149 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3150 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3151 return RadioAccessFamily.RAF_UNKNOWN;
3152 }
3153
Wink Saville5d475dd2014-10-17 15:00:58 -07003154 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3155 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003156
3157 @Override
3158 public void enableVideoCalling(boolean enable) {
3159 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003160 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003161 }
3162
3163 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003164 public boolean isVideoCallingEnabled(String callingPackage) {
3165 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3166 return false;
3167 }
3168
Andrew Lee77527ac2014-10-21 16:57:39 -07003169 // Check the user preference and the system-level IMS setting. Even if the user has
3170 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3171 // In the long run, we may instead need to check if there exists a connection service
3172 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003173 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3174 return imsManager.isVtEnabledByPlatform()
3175 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3176 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003177 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003178
Andrew Leea1239f22015-03-02 17:44:07 -08003179 @Override
3180 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003181 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003182 }
3183
3184 @Override
3185 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003186 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003187 }
3188
Andrew Lee9431b832015-03-09 18:46:45 -07003189 @Override
3190 public boolean isTtyModeSupported() {
3191 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3192 TelephonyManager telephonyManager =
3193 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003194 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003195 }
3196
3197 @Override
3198 public boolean isHearingAidCompatibilitySupported() {
3199 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3200 }
3201
Sanket Padawe7310cc72015-01-14 09:53:20 -08003202 /**
3203 * Returns the unique device ID of phone, for example, the IMEI for
3204 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3205 *
3206 * <p>Requires Permission:
3207 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3208 */
3209 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003210 public String getDeviceId(String callingPackage) {
3211 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3212 return null;
3213 }
3214
Sanket Padawe7310cc72015-01-14 09:53:20 -08003215 final Phone phone = PhoneFactory.getPhone(0);
3216 if (phone != null) {
3217 return phone.getDeviceId();
3218 } else {
3219 return null;
3220 }
3221 }
3222
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003223 /*
3224 * {@hide}
3225 * Returns the IMS Registration Status
3226 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003227 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003228 public boolean isImsRegistered() {
3229 return mPhone.isImsRegistered();
3230 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003231
Ping Sun014fe8e2016-03-02 19:16:45 +08003232 /**
3233 * {@hide}
3234 * Returns the IMS Registration Status on a particular subid
3235 *
3236 * @param subId
3237 */
3238 public boolean isImsRegisteredForSubscriber(int subId) {
3239 Phone phone = getPhone(subId);
3240 if (phone != null) {
3241 return phone.isImsRegistered();
3242 } else {
3243 return false;
3244 }
3245 }
3246
Santos Cordon7a1885b2015-02-03 11:15:19 -08003247 @Override
3248 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3249 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3250 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003251
Nathan Haroldc55097a2015-03-11 18:14:50 -07003252 /*
3253 * {@hide}
3254 * Returns the IMS Registration Status
3255 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003256 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003257 return mPhone.isWifiCallingEnabled();
3258 }
3259
3260 /*
3261 * {@hide}
3262 * Returns the IMS Registration Status
3263 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003264 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003265 return mPhone.isVolteEnabled();
3266 }
Svet Ganovb320e182015-04-16 12:30:10 -07003267
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003268 /*
3269 * {@hide} Returns the IMS Registration Status
3270 */
3271 public boolean isVideoTelephonyAvailable() {
3272 return mPhone.isVideoEnabled();
3273 }
3274
Svet Ganovb320e182015-04-16 12:30:10 -07003275 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003276 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003277 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003278 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3279
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003280 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003281 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003282 } catch (SecurityException e) {
3283 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3284 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003285 }
Svet Ganovb320e182015-04-16 12:30:10 -07003286
3287 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3288 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3289 return false;
3290 }
3291
3292 return true;
3293 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003294
Makoto Onukifee69342015-06-29 14:44:50 -07003295 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003296 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003297 */
3298 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003299 // Default SMS app can always read it.
3300 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3301 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3302 return true;
3303 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003304
Makoto Onukie4072d12015-08-03 15:12:23 -07003305 try {
3306 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003307 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003308 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003309 // Can be read with READ_SMS too.
3310 try {
3311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3312 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3313 if (opCode != AppOpsManager.OP_NONE) {
3314 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3315 == AppOpsManager.MODE_ALLOWED;
3316 } else {
3317 return true;
3318 }
3319 } catch (SecurityException readSmsSecurityException) {
3320 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003321 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003322 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003324 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003325 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003326 if (opCode != AppOpsManager.OP_NONE) {
3327 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3328 == AppOpsManager.MODE_ALLOWED;
3329 } else {
3330 return true;
3331 }
3332 } catch (SecurityException readPhoneNumberSecurityException) {
3333 }
3334
3335 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3336 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3337 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003338 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003339 }
3340
Stuart Scott8eef64f2015-04-08 15:13:54 -07003341 @Override
3342 public void factoryReset(int subId) {
3343 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003344 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3345 return;
3346 }
3347
Svet Ganovcc087f82015-05-12 20:35:54 -07003348 final long identity = Binder.clearCallingIdentity();
3349 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003350 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3351 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003352 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003353 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003354 // Set network selection mode to automatic
3355 setNetworkSelectionModeAutomatic(subId);
3356 // Set preferred mobile network type to the best available
3357 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3358 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003359 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003363 }
3364 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003365
3366 @Override
3367 public String getLocaleFromDefaultSim() {
3368 // We query all subscriptions instead of just the active ones, because
3369 // this might be called early on in the provisioning flow when the
3370 // subscriptions potentially aren't active yet.
3371 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3372 if (slist == null || slist.isEmpty()) {
3373 return null;
3374 }
3375
3376 // This function may be called very early, say, from the setup wizard, at
3377 // which point we won't have a default subscription set. If that's the case
3378 // we just choose the first, which will be valid in "most cases".
3379 final int defaultSubId = getDefaultSubscription();
3380 SubscriptionInfo info = null;
3381 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3382 info = slist.get(0);
3383 } else {
3384 for (SubscriptionInfo item : slist) {
3385 if (item.getSubscriptionId() == defaultSubId) {
3386 info = item;
3387 break;
3388 }
3389 }
3390
3391 if (info == null) {
3392 return null;
3393 }
3394 }
3395
3396 // Try and fetch the locale from the carrier properties or from the SIM language
3397 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003398 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003399 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003400 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003401 if (defaultPhone != null) {
3402 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3403 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003404 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003405 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3406 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003407 } else {
3408 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003409 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003410 }
3411 }
3412
Narayan Kamath011676f2015-07-29 12:04:08 +01003413 // The SIM language preferences only store a language (e.g. fr = French), not an
3414 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3415 // the SIM and carrier preferences does not include a country we add the country
3416 // determined from the SIM MCC to provide an exact locale.
3417 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003418 if (mccLocale != null) {
3419 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3420 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003421 }
3422
Tony Hill183b2de2015-06-24 14:53:58 +01003423 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003424 return null;
3425 }
3426
3427 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 return mSubscriptionController.getAllSubInfoList(
3431 mPhone.getContext().getOpPackageName());
3432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 return mSubscriptionController.getActiveSubscriptionInfoList(
3441 mPhone.getContext().getOpPackageName());
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003446
3447 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003448 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3449 * representing the state of the modem.
3450 *
3451 * NOTE: This clears the modem state, so there should only every be one caller.
3452 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003453 */
3454 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003455 public void requestModemActivityInfo(ResultReceiver result) {
3456 enforceModifyPermission();
3457
3458 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3459 Bundle bundle = new Bundle();
3460 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3461 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003462 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003463
3464 /**
3465 * {@hide}
3466 * Returns the service state information on specified subscription.
3467 */
3468 @Override
3469 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3470
3471 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3472 return null;
3473 }
3474
3475 final Phone phone = getPhone(subId);
3476 if (phone == null) {
3477 return null;
3478 }
3479
3480 return phone.getServiceState();
3481 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003482
3483 /**
3484 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3485 *
3486 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3487 * voicemail ringtone.
3488 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3489 * PhoneAccount.
3490 */
3491 @Override
3492 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003493 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003494 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003495 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003496 }
3497
fionaxu7ed723d2017-05-30 18:58:54 -07003498 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003499 }
3500
3501 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003502 * Sets the per-account voicemail ringtone.
3503 *
3504 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3505 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3506 *
3507 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3508 * voicemail ringtone.
3509 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3510 * PhoneAccount.
3511 */
3512 @Override
3513 public void setVoicemailRingtoneUri(String callingPackage,
3514 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3516 if (!TextUtils.equals(callingPackage,
3517 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3518 enforceModifyPermissionOrCarrierPrivilege(
3519 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3520 }
3521 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3522 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003523 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003524 }
fionaxu7ed723d2017-05-30 18:58:54 -07003525 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003526 }
3527
3528 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003529 * Returns whether vibration is set for voicemail notification in Phone settings.
3530 *
3531 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3532 * voicemail vibration setting.
3533 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3534 */
3535 @Override
3536 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003537 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003538 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003539 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003540 }
3541
fionaxu7ed723d2017-05-30 18:58:54 -07003542 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003543 }
3544
Youhan Wange64578a2016-05-02 15:32:42 -07003545 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003546 * Sets the per-account voicemail vibration.
3547 *
3548 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3549 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3550 *
3551 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3552 * voicemail vibration setting.
3553 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3554 * specific PhoneAccount.
3555 */
3556 @Override
3557 public void setVoicemailVibrationEnabled(String callingPackage,
3558 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3560 if (!TextUtils.equals(callingPackage,
3561 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3562 enforceModifyPermissionOrCarrierPrivilege(
3563 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3564 }
3565
3566 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3567 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003568 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003569 }
fionaxu7ed723d2017-05-30 18:58:54 -07003570 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003571 }
3572
3573 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003574 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3575 *
3576 * @throws SecurityException if the caller does not have the required permission
3577 */
3578 private void enforceReadPrivilegedPermission() {
3579 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3580 null);
3581 }
3582
3583 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003584 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3585 * permission.
3586 *
3587 * @throws SecurityException if the caller does not have the required permission
3588 */
3589 private void enforceSendSmsPermission() {
3590 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3591 }
3592
3593 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003594 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003595 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003596 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003597 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003598 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003599 ComponentName componentName =
3600 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3601 if(componentName == null) {
3602 throw new SecurityException("Caller not current active visual voicemail package[null]");
3603 }
3604 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003605 if (!callingPackage.equals(vvmPackage)) {
3606 throw new SecurityException("Caller not current active visual voicemail package[" +
3607 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003608 }
3609 }
3610
3611 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003612 * Return the application ID for the app type.
3613 *
3614 * @param subId the subscription ID that this request applies to.
3615 * @param appType the uicc app type.
3616 * @return Application ID for specificied app type, or null if no uicc.
3617 */
3618 @Override
3619 public String getAidForAppType(int subId, int appType) {
3620 enforceReadPrivilegedPermission();
3621 Phone phone = getPhone(subId);
3622 if (phone == null) {
3623 return null;
3624 }
3625 String aid = null;
3626 try {
3627 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3628 .getApplicationByType(appType).getAid();
3629 } catch (Exception e) {
3630 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3631 }
3632 return aid;
3633 }
3634
Youhan Wang4001d252016-05-11 10:29:41 -07003635 /**
3636 * Return the Electronic Serial Number.
3637 *
3638 * @param subId the subscription ID that this request applies to.
3639 * @return ESN or null if error.
3640 */
3641 @Override
3642 public String getEsn(int subId) {
3643 enforceReadPrivilegedPermission();
3644 Phone phone = getPhone(subId);
3645 if (phone == null) {
3646 return null;
3647 }
3648 String esn = null;
3649 try {
3650 esn = phone.getEsn();
3651 } catch (Exception e) {
3652 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3653 }
3654 return esn;
3655 }
3656
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003657 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003658 * Return the Preferred Roaming List Version.
3659 *
3660 * @param subId the subscription ID that this request applies to.
3661 * @return PRLVersion or null if error.
3662 */
3663 @Override
3664 public String getCdmaPrlVersion(int subId) {
3665 enforceReadPrivilegedPermission();
3666 Phone phone = getPhone(subId);
3667 if (phone == null) {
3668 return null;
3669 }
3670 String cdmaPrlVersion = null;
3671 try {
3672 cdmaPrlVersion = phone.getCdmaPrlVersion();
3673 } catch (Exception e) {
3674 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3675 }
3676 return cdmaPrlVersion;
3677 }
3678
3679 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003680 * Get snapshot of Telephony histograms
3681 * @return List of Telephony histograms
3682 * @hide
3683 */
3684 @Override
3685 public List<TelephonyHistogram> getTelephonyHistograms() {
3686 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3687 return RIL.getTelephonyRILTimingHistograms();
3688 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003689
3690 /**
3691 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003692 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003693 * Require system privileges. In the future we may add this to carrier APIs.
3694 *
3695 * @return The number of carriers set successfully, should match length of carriers
3696 */
3697 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003698 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003699 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003700
Meng Wang9b7c4e92017-02-17 11:41:27 -08003701 if (carriers == null) {
3702 throw new NullPointerException("carriers cannot be null");
3703 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003704
3705 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003706 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3707 return retVal[0];
3708 }
3709
3710 /**
3711 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003712 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003713 * Require system privileges. In the future we may add this to carrier APIs.
3714 *
3715 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3716 * means all carriers are allowed.
3717 */
3718 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003719 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003720 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003721 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003722 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3723 }
3724
fionaxu59545b42016-05-25 15:53:37 -07003725 /**
3726 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3727 * @param subId the subscription ID that this action applies to.
3728 * @param enabled control enable or disable metered apns.
3729 * {@hide}
3730 */
3731 @Override
3732 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3733 enforceModifyPermission();
3734 final Phone phone = getPhone(subId);
3735 if (phone == null) {
3736 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3737 return;
3738 }
3739 try {
3740 phone.carrierActionSetMeteredApnsEnabled(enabled);
3741 } catch (Exception e) {
3742 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3743 }
3744 }
3745
3746 /**
3747 * Action set from carrier signalling broadcast receivers to enable/disable radio
3748 * @param subId the subscription ID that this action applies to.
3749 * @param enabled control enable or disable radio.
3750 * {@hide}
3751 */
3752 @Override
3753 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3754 enforceModifyPermission();
3755 final Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3758 return;
3759 }
3760 try {
3761 phone.carrierActionSetRadioEnabled(enabled);
3762 } catch (Exception e) {
3763 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3764 }
3765 }
3766
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003767 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003768 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3769 * network status based on which carrier apps could apply actions accordingly,
3770 * enable/disable default url handler for example.
3771 *
3772 * @param subId the subscription ID that this action applies to.
3773 * @param report control start/stop reporting the default network status.
3774 * {@hide}
3775 */
3776 @Override
3777 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3778 enforceModifyPermission();
3779 final Phone phone = getPhone(subId);
3780 if (phone == null) {
3781 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3782 return;
3783 }
3784 try {
3785 phone.carrierActionReportDefaultNetworkStatus(report);
3786 } catch (Exception e) {
3787 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3788 }
3789 }
3790
3791 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003792 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3793 * bug report is being generated.
3794 */
3795 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003796 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003797 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3798 != PackageManager.PERMISSION_GRANTED) {
3799 writer.println("Permission Denial: can't dump Phone from pid="
3800 + Binder.getCallingPid()
3801 + ", uid=" + Binder.getCallingUid()
3802 + "without permission "
3803 + android.Manifest.permission.DUMP);
3804 return;
3805 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003806 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003807 }
Jack Yueb89b242016-06-22 13:27:47 -07003808
3809 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003810 * Get aggregated video call data usage since boot.
3811 *
3812 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3813 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003814 * {@hide}
3815 */
3816 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003817 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003818 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3819 null);
3820
Jack Yu84291ec2017-05-26 16:07:50 -07003821 // NetworkStatsService keeps tracking the active network interface and identity. It
3822 // records the delta with the corresponding network identity. We just return the total video
3823 // call data usage snapshot since boot.
3824 Phone phone = getPhone(subId);
3825 if (phone != null) {
3826 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003827 }
Jack Yu84291ec2017-05-26 16:07:50 -07003828 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003829 }
Jack Yu75ab2952016-07-08 14:29:33 -07003830
3831 /**
3832 * Policy control of data connection. Usually used when data limit is passed.
3833 * @param enabled True if enabling the data, otherwise disabling.
3834 * @param subId Subscription index
3835 * {@hide}
3836 */
3837 @Override
3838 public void setPolicyDataEnabled(boolean enabled, int subId) {
3839 enforceModifyPermission();
3840 Phone phone = getPhone(subId);
3841 if (phone != null) {
3842 phone.setPolicyDataEnabled(enabled);
3843 }
3844 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003845
3846 /**
3847 * Get Client request stats
3848 * @return List of Client Request Stats
3849 * @hide
3850 */
3851 @Override
3852 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3853 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3854 return null;
3855 }
3856
3857 Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 return phone.getClientRequestStats();
3860 }
3861
3862 return null;
3863 }
3864
3865 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3866 if (workSource != null) {
3867 return workSource;
3868 }
3869
3870 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3871 workSource = new WorkSource(uid, packageName);
3872 return workSource;
3873 }
Jack Yueb4124c2017-02-16 15:32:43 -08003874
3875 /**
Grace Chen70990072017-03-24 17:21:30 -07003876 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003877 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003878 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003879 * @param state State of SIM (power down, power up, pass through)
3880 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3881 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3882 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003883 *
3884 **/
3885 @Override
Grace Chen70990072017-03-24 17:21:30 -07003886 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003887 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003888 Phone phone = PhoneFactory.getPhone(slotIndex);
3889
Jack Yueb4124c2017-02-16 15:32:43 -08003890 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003891 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003892 }
3893 }
Shuo Qiandd210312017-04-12 22:11:33 +00003894
Tyler Gunn65d45c22017-06-05 11:22:26 -07003895 private boolean isUssdApiAllowed(int subId) {
3896 CarrierConfigManager configManager =
3897 (CarrierConfigManager) mPhone.getContext().getSystemService(
3898 Context.CARRIER_CONFIG_SERVICE);
3899 if (configManager == null) {
3900 return false;
3901 }
3902 PersistableBundle pb = configManager.getConfigForSubId(subId);
3903 if (pb == null) {
3904 return false;
3905 }
3906 return pb.getBoolean(
3907 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3908 }
3909
Shuo Qiandd210312017-04-12 22:11:33 +00003910 /**
3911 * Check if phone is in emergency callback mode
3912 * @return true if phone is in emergency callback mode
3913 * @param subId sub id
3914 */
3915 public boolean getEmergencyCallbackMode(int subId) {
3916 final Phone phone = getPhone(subId);
3917 if (phone != null) {
3918 return phone.isInEcm();
3919 } else {
3920 return false;
3921 }
3922 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003923
3924 /**
3925 * Get the current signal strength information for the given subscription.
3926 * Because this information is not updated when the device is in a low power state
3927 * it should not be relied-upon to be current.
3928 * @param subId Subscription index
3929 * @return the most recent cached signal strength info from the modem
3930 */
3931 @Override
3932 public SignalStrength getSignalStrength(int subId) {
3933 Phone p = getPhone(subId);
3934 if (p == null) {
3935 return null;
3936 }
3937
3938 return p.getSignalStrength();
3939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003940}