blob: f03ad353d27e1ccc96dd3c78a541c6681fb5aeeb [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;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000070import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080073import android.telephony.ims.aidl.IImsConfig;
74import android.telephony.ims.aidl.IImsMmTelFeature;
75import android.telephony.ims.aidl.IImsRcsFeature;
76import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080077import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080083
Andrew Lee312e8172014-10-23 17:01:36 -070084import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080085import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070087import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070088import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010094import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070095import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070096import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080098import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700100import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700103import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800104import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700105import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700106import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.IccIoResult;
108import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700110import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800111import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700114import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800117import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700119import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700121import java.io.FileDescriptor;
122import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800126import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129
130/**
131 * Implementation of the ITelephony interface.
132 */
Santos Cordon117fee72014-05-16 17:56:12 -0700133public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 private static final String LOG_TAG = "PhoneInterfaceManager";
135 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
136 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138
139 // Message codes used with mMainThreadHandler
140 private static final int CMD_HANDLE_PIN_MMI = 1;
141 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
142 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
143 private static final int CMD_ANSWER_RINGING_CALL = 4;
144 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700145 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
146 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147 private static final int CMD_OPEN_CHANNEL = 9;
148 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
149 private static final int CMD_CLOSE_CHANNEL = 11;
150 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800151 private static final int CMD_NV_READ_ITEM = 13;
152 private static final int EVENT_NV_READ_ITEM_DONE = 14;
153 private static final int CMD_NV_WRITE_ITEM = 15;
154 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
155 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
156 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
157 private static final int CMD_NV_RESET_CONFIG = 19;
158 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800159 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
160 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
161 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
162 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800163 private static final int CMD_SEND_ENVELOPE = 25;
164 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700165 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
166 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
167 private static final int CMD_EXCHANGE_SIM_IO = 31;
168 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800169 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
170 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700171 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
172 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700173 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
174 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
176 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
177 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700179 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
180 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
181 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
182 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700183 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
185 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000186 private static final int CMD_SWITCH_SLOTS = 50;
187 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800189 // Parameters of select command.
190 private static final int SELECT_COMMAND = 0xA4;
191 private static final int SELECT_P1 = 0x04;
192 private static final int SELECT_P2 = 0;
193 private static final int SELECT_P3 = 0x10;
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 /** The singleton instance. */
196 private static PhoneInterfaceManager sInstance;
197
Wink Saville3ab207e2014-11-20 13:07:20 -0800198 private PhoneGlobals mApp;
199 private Phone mPhone;
200 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700201 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private AppOpsManager mAppOps;
203 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800205 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Derek Tan97ebb422014-09-05 16:55:38 -0700207 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
208 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800209 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700210
Derek Tan740e1672017-06-27 14:56:27 -0700211 // The AID of ISD-R.
212 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
213
yinxub1bed742017-04-17 11:45:04 -0700214 private NetworkScanRequestTracker mNetworkScanRequestTracker;
215
Derek Tan89e89d42014-07-08 17:00:10 -0700216 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700217 * A request object to use for transmitting data to an ICC.
218 */
219 private static final class IccAPDUArgument {
220 public int channel, cla, command, p1, p2, p3;
221 public String data;
222
223 public IccAPDUArgument(int channel, int cla, int command,
224 int p1, int p2, int p3, String data) {
225 this.channel = channel;
226 this.cla = cla;
227 this.command = command;
228 this.p1 = p1;
229 this.p2 = p2;
230 this.p3 = p3;
231 this.data = data;
232 }
233 }
234
235 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700236 * A request object to use for transmitting data to an ICC.
237 */
238 private static final class ManualNetworkSelectionArgument {
239 public OperatorInfo operatorInfo;
240 public boolean persistSelection;
241
242 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
243 this.operatorInfo = operatorInfo;
244 this.persistSelection = persistSelection;
245 }
246 }
247
248 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
250 * request after sending. The main thread will notify the request when it is complete.
251 */
252 private static final class MainThreadRequest {
253 /** The argument to use for the request */
254 public Object argument;
255 /** The result of the request that is run on the main thread */
256 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800257 // The subscriber id that this request applies to. Defaults to
258 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
259 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
261 public MainThreadRequest(Object argument) {
262 this.argument = argument;
263 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264
265 public MainThreadRequest(Object argument, Integer subId) {
266 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800267 if (subId != null) {
268 this.subId = subId;
269 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 }
272
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800273 private static final class IncomingThirdPartyCallArgs {
274 public final ComponentName component;
275 public final String callId;
276 public final String callerDisplayName;
277
278 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
279 String callerDisplayName) {
280 this.component = component;
281 this.callId = callId;
282 this.callerDisplayName = callerDisplayName;
283 }
284 }
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 /**
287 * A handler that processes messages on the main thread in the phone process. Since many
288 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
289 * inbound binder threads to the main thread in the phone process. The Binder thread
290 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
291 * on, which will be notified when the operation completes and will contain the result of the
292 * request.
293 *
294 * <p>If a MainThreadRequest object is provided in the msg.obj field,
295 * note that request.result must be set to something non-null for the calling thread to
296 * unblock.
297 */
298 private final class MainThreadHandler extends Handler {
299 @Override
300 public void handleMessage(Message msg) {
301 MainThreadRequest request;
302 Message onCompleted;
303 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800304 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700305 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
307 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700308 case CMD_HANDLE_USSD_REQUEST: {
309 request = (MainThreadRequest) msg.obj;
310 final Phone phone = getPhoneFromRequest(request);
311 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
312 String ussdRequest = ussdObject.first;
313 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700314
315 if (!isUssdApiAllowed(request.subId)) {
316 // Carrier does not support use of this API, return failure.
317 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
318 UssdResponse response = new UssdResponse(ussdRequest, null);
319 Bundle returnData = new Bundle();
320 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
321 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
322
323 request.result = true;
324 synchronized (request) {
325 request.notifyAll();
326 }
327 return;
328 }
329
Tyler Gunn52dcf772017-04-26 11:30:31 -0700330 try {
331 request.result = phone != null ?
332 phone.handleUssdRequest(ussdRequest, wrappedCallback)
333 : false;
334 } catch (CallStateException cse) {
335 request.result = false;
336 }
pkanwar32d516d2016-10-14 19:37:38 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
342 }
343
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 final Phone phone = getPhoneFromRequest(request);
347 request.result = phone != null ?
348 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
349 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
357 case CMD_HANDLE_NEIGHBORING_CELL:
358 request = (MainThreadRequest) msg.obj;
359 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
360 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700361 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 break;
363
364 case EVENT_NEIGHBORING_CELL_DONE:
365 ar = (AsyncResult) msg.obj;
366 request = (MainThreadRequest) ar.userObj;
367 if (ar.exception == null && ar.result != null) {
368 request.result = ar.result;
369 } else {
370 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800371 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373 // Wake up the requesting thread
374 synchronized (request) {
375 request.notifyAll();
376 }
377 break;
378
379 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700380 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800381 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700382 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 case CMD_END_CALL:
386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700389 Phone phone = getPhone(end_subId);
390 if (phone == null) {
391 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
392 break;
393 }
394 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
396 // CDMA: If the user presses the Power button we treat it as
397 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700398 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
400 // GSM: End the call as per the Phone state
401 hungUp = PhoneUtils.hangup(mCM);
402 } else {
403 throw new IllegalStateException("Unexpected phone type: " + phoneType);
404 }
405 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
406 request.result = hungUp;
407 // Wake up the requesting thread
408 synchronized (request) {
409 request.notifyAll();
410 }
411 break;
412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 if (uiccCard == null) {
418 loge("iccTransmitApduLogicalChannel: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
420 synchronized (request) {
421 request.notifyAll();
422 }
423 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
425 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument.channel, iccArgument.cla, iccArgument.command,
428 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 break;
432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 ar = (AsyncResult) msg.obj;
435 request = (MainThreadRequest) ar.userObj;
436 if (ar.exception == null && ar.result != null) {
437 request.result = ar.result;
438 } else {
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
440 if (ar.result == null) {
441 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800442 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800444 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 } else {
446 loge("iccTransmitApduLogicalChannel: Unknown exception");
447 }
448 }
449 synchronized (request) {
450 request.notifyAll();
451 }
452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
455 request = (MainThreadRequest) msg.obj;
456 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800457 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 if (uiccCard == null) {
459 loge("iccTransmitApduBasicChannel: No UICC");
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 synchronized (request) {
462 request.notifyAll();
463 }
464 } else {
465 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
466 request);
467 uiccCard.iccTransmitApduBasicChannel(
468 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
469 iccArgument.p3, iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduBasicChannel: Empty response");
482 } else if (ar.exception instanceof CommandException) {
483 loge("iccTransmitApduBasicChannel: CommandException: " +
484 ar.exception);
485 } else {
486 loge("iccTransmitApduBasicChannel: Unknown exception");
487 }
488 }
489 synchronized (request) {
490 request.notifyAll();
491 }
492 break;
493
494 case CMD_EXCHANGE_SIM_IO:
495 request = (MainThreadRequest) msg.obj;
496 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 if (uiccCard == null) {
499 loge("iccExchangeSimIO: No UICC");
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
501 synchronized (request) {
502 request.notifyAll();
503 }
504 } else {
505 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
506 request);
507 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
508 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
509 iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_EXCHANGE_SIM_IO_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6f, 0, (byte[])null);
520 }
521 synchronized (request) {
522 request.notifyAll();
523 }
524 break;
525
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 case CMD_SEND_ENVELOPE:
527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("sendEnvelopeWithStatus: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 synchronized (request) {
533 request.notifyAll();
534 }
535 } else {
536 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
537 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
538 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 break;
540
541 case EVENT_SEND_ENVELOPE_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("sendEnvelopeWithStatus: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("sendEnvelopeWithStatus: CommandException: " +
552 ar.exception);
553 } else {
554 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
555 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 }
557 synchronized (request) {
558 request.notifyAll();
559 }
560 break;
561
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 case CMD_OPEN_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800565 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800568 request.result = new IccOpenLogicalChannelResponse(-1,
569 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 synchronized (request) {
571 request.notifyAll();
572 }
573 } else {
574 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
576 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
580 case EVENT_OPEN_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 int[] result = (int[]) ar.result;
586 int channelId = result[0];
587 byte[] selectResponse = null;
588 if (result.length > 1) {
589 selectResponse = new byte[result.length - 1];
590 for (int i = 1; i < result.length; ++i) {
591 selectResponse[i - 1] = (byte) result[i];
592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.result == null) {
598 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 if (ar.exception != null) {
601 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
602 }
603
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700605 if (ar.exception instanceof CommandException) {
606 CommandException.Error error =
607 ((CommandException) (ar.exception)).getCommandError();
608 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700610 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(
615 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700617 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 synchronized (request) {
619 request.notifyAll();
620 }
621 break;
622
623 case CMD_CLOSE_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccCloseLogicalChannel: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
629 synchronized (request) {
630 request.notifyAll();
631 }
632 } else {
633 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
634 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800639 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
640 break;
641
642 case CMD_NV_READ_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
645 mPhone.nvReadItem((Integer) request.argument, onCompleted);
646 break;
647
648 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800654 request.result = "";
655 if (ar.result == null) {
656 loge("nvReadItem: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("nvReadItem: CommandException: " +
659 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800661 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
663 }
664 synchronized (request) {
665 request.notifyAll();
666 }
667 break;
668
Jake Hambye994d462014-02-03 13:10:13 -0800669 case CMD_NV_WRITE_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
672 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
673 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
674 break;
675
676 case EVENT_NV_WRITE_ITEM_DONE:
677 handleNullReturnEvent(msg, "nvWriteItem");
678 break;
679
680 case CMD_NV_WRITE_CDMA_PRL:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
683 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
684 break;
685
686 case EVENT_NV_WRITE_CDMA_PRL_DONE:
687 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
688 break;
689
690 case CMD_NV_RESET_CONFIG:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
693 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
694 break;
695
696 case EVENT_NV_RESET_CONFIG_DONE:
697 handleNullReturnEvent(msg, "nvResetConfig");
698 break;
699
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 case CMD_GET_PREFERRED_NETWORK_TYPE:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result; // Integer
711 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800712 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 if (ar.result == null) {
714 loge("getPreferredNetworkType: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("getPreferredNetworkType: CommandException: " +
717 ar.exception);
718 } else {
719 loge("getPreferredNetworkType: Unknown exception");
720 }
721 }
722 synchronized (request) {
723 request.notifyAll();
724 }
725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 case CMD_SET_VOICEMAIL_NUMBER:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
741 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800742 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
743 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800744 break;
745
746 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
747 handleNullReturnEvent(msg, "setVoicemailNumber");
748 break;
749
Stuart Scott54788802015-03-30 13:18:01 -0700750 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
753 request);
754 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
755 break;
756
757 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
758 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
759 break;
760
Shishir Agrawal302c8692015-06-19 13:49:39 -0700761 case CMD_PERFORM_NETWORK_SCAN:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
764 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
765 break;
766
767 case EVENT_PERFORM_NETWORK_SCAN_DONE:
768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
770 CellNetworkScanResult cellScanResult;
771 if (ar.exception == null && ar.result != null) {
772 cellScanResult = new CellNetworkScanResult(
773 CellNetworkScanResult.STATUS_SUCCESS,
774 (List<OperatorInfo>) ar.result);
775 } else {
776 if (ar.result == null) {
777 loge("getCellNetworkScanResults: Empty response");
778 }
779 if (ar.exception != null) {
780 loge("getCellNetworkScanResults: Exception: " + ar.exception);
781 }
782 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
783 if (ar.exception instanceof CommandException) {
784 CommandException.Error error =
785 ((CommandException) (ar.exception)).getCommandError();
786 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
788 } else if (error == CommandException.Error.GENERIC_FAILURE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
790 }
791 }
792 cellScanResult = new CellNetworkScanResult(errorCode, null);
793 }
794 request.result = cellScanResult;
795 synchronized (request) {
796 request.notifyAll();
797 }
798 break;
799
800 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
801 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700802 ManualNetworkSelectionArgument selArg =
803 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
805 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
807 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 break;
809
810 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
811 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
812 break;
813
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700814 case CMD_GET_MODEM_ACTIVITY_INFO:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700817 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 break;
819
820 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 if (ar.result == null) {
827 loge("queryModemActivityInfo: Empty response");
828 } else if (ar.exception instanceof CommandException) {
829 loge("queryModemActivityInfo: CommandException: " +
830 ar.exception);
831 } else {
832 loge("queryModemActivityInfo: Unknown exception");
833 }
834 }
Amit Mahajand4766222016-01-28 15:28:28 -0800835 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
836 if (request.result == null) {
837 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
838 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 synchronized (request) {
840 request.notifyAll();
841 }
842 break;
843
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 case CMD_SET_ALLOWED_CARRIERS:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
847 mPhone.setAllowedCarriers(
848 (List<CarrierIdentifier>) request.argument,
849 onCompleted);
850 break;
851
852 case EVENT_SET_ALLOWED_CARRIERS_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("setAllowedCarriers: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " +
862 ar.exception);
863 } else {
864 loge("setAllowedCarriers: Unknown exception");
865 }
866 }
867 // Result cannot be null. Return -1 on error.
868 if (request.result == null) {
869 request.result = new int[]{-1};
870 }
871 synchronized (request) {
872 request.notifyAll();
873 }
874 break;
875
876 case CMD_GET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
879 mPhone.getAllowedCarriers(onCompleted);
880 break;
881
882 case EVENT_GET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
888 if (ar.result == null) {
889 loge("getAllowedCarriers: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("getAllowedCarriers: CommandException: " +
892 ar.exception);
893 } else {
894 loge("getAllowedCarriers: Unknown exception");
895 }
896 }
897 // Result cannot be null. Return empty list of CarrierIdentifier.
898 if (request.result == null) {
899 request.result = new ArrayList<CarrierIdentifier>(0);
900 }
901 synchronized (request) {
902 request.notifyAll();
903 }
904 break;
905
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result;
911 } else {
912 request.result = new IllegalArgumentException(
913 "Failed to retrieve Forbidden Plmns");
914 if (ar.result == null) {
915 loge("getForbiddenPlmns: Empty response");
916 } else {
917 loge("getForbiddenPlmns: Unknown exception");
918 }
919 }
920 synchronized (request) {
921 request.notifyAll();
922 }
923 break;
924
925 case CMD_GET_FORBIDDEN_PLMNS:
926 request = (MainThreadRequest) msg.obj;
927 uiccCard = getUiccCardFromRequest(request);
928 if (uiccCard == null) {
929 loge("getForbiddenPlmns() UiccCard is null");
930 request.result = new IllegalArgumentException(
931 "getForbiddenPlmns() UiccCard is null");
932 synchronized (request) {
933 request.notifyAll();
934 }
935 break;
936 }
937 Integer appType = (Integer) request.argument;
938 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
939 if (uiccApp == null) {
940 loge("getForbiddenPlmns() no app with specified type -- "
941 + appType);
942 request.result = new IllegalArgumentException("Failed to get UICC App");
943 synchronized (request) {
944 request.notifyAll();
945 }
946 break;
947 } else {
948 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
949 + " specified type -- " + appType);
950 }
951 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
952 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
953 onCompleted);
954 break;
955
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000956 case CMD_SWITCH_SLOTS:
957 request = (MainThreadRequest) msg.obj;
958 int[] physicalSlots = (int[]) request.argument;
959 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
960 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
961 break;
962
963 case EVENT_SWITCH_SLOTS_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 request.result = (ar.exception == null);
967 synchronized (request) {
968 request.notifyAll();
969 }
970 break;
971
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972 default:
973 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
974 break;
975 }
976 }
Jake Hambye994d462014-02-03 13:10:13 -0800977
978 private void handleNullReturnEvent(Message msg, String command) {
979 AsyncResult ar = (AsyncResult) msg.obj;
980 MainThreadRequest request = (MainThreadRequest) ar.userObj;
981 if (ar.exception == null) {
982 request.result = true;
983 } else {
984 request.result = false;
985 if (ar.exception instanceof CommandException) {
986 loge(command + ": CommandException: " + ar.exception);
987 } else {
988 loge(command + ": Unknown exception");
989 }
990 }
991 synchronized (request) {
992 request.notifyAll();
993 }
994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 }
996
997 /**
998 * Posts the specified command to be executed on the main thread,
999 * waits for the request to complete, and returns the result.
1000 * @see #sendRequestAsync
1001 */
1002 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001003 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001004 }
1005
1006 /**
1007 * Posts the specified command to be executed on the main thread,
1008 * waits for the request to complete, and returns the result.
1009 * @see #sendRequestAsync
1010 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001011 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1013 throw new RuntimeException("This method will deadlock if called from the main thread.");
1014 }
1015
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001016 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001017 Message msg = mMainThreadHandler.obtainMessage(command, request);
1018 msg.sendToTarget();
1019
1020 // Wait for the request to complete
1021 synchronized (request) {
1022 while (request.result == null) {
1023 try {
1024 request.wait();
1025 } catch (InterruptedException e) {
1026 // Do nothing, go back and wait until the request is complete
1027 }
1028 }
1029 }
1030 return request.result;
1031 }
1032
1033 /**
1034 * Asynchronous ("fire and forget") version of sendRequest():
1035 * Posts the specified command to be executed on the main thread, and
1036 * returns immediately.
1037 * @see #sendRequest
1038 */
1039 private void sendRequestAsync(int command) {
1040 mMainThreadHandler.sendEmptyMessage(command);
1041 }
1042
1043 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001044 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1045 * @see {@link #sendRequest(int,Object)}
1046 */
1047 private void sendRequestAsync(int command, Object argument) {
1048 MainThreadRequest request = new MainThreadRequest(argument);
1049 Message msg = mMainThreadHandler.obtainMessage(command, request);
1050 msg.sendToTarget();
1051 }
1052
1053 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 * Initialize the singleton PhoneInterfaceManager instance.
1055 * This is only done once, at startup, from PhoneApp.onCreate().
1056 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001057 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 synchronized (PhoneInterfaceManager.class) {
1059 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001060 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 } else {
1062 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1063 }
1064 return sInstance;
1065 }
1066 }
1067
1068 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 mApp = app;
1071 mPhone = phone;
1072 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001073 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1075 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001076 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001077 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001078 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001079 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 publish();
1082 }
1083
1084 private void publish() {
1085 if (DBG) log("publish: " + this);
1086
1087 ServiceManager.addService("phone", this);
1088 }
1089
Stuart Scott584921c2015-01-15 17:10:34 -08001090 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001091 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1092 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001093 }
1094
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001095 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1096 Phone phone = getPhoneFromRequest(request);
1097 return phone == null ? null :
1098 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1099 }
1100
Wink Saville36469e72014-06-11 15:17:00 -07001101 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001102 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001103 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 //
1106 // Implementation of the ITelephony interface.
1107 //
1108
1109 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001110 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001111 }
1112
Wink Savilleb564aae2014-10-23 10:18:09 -07001113 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 if (DBG) log("dial: " + number);
1115 // No permission check needed here: This is just a wrapper around the
1116 // ACTION_DIAL intent, which is available to any app since it puts up
1117 // the UI before it does anything.
1118
1119 String url = createTelUrl(number);
1120 if (url == null) {
1121 return;
1122 }
1123
1124 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001125 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1127 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1129 mApp.startActivity(intent);
1130 }
1131 }
1132
1133 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001134 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001135 }
1136
Wink Savilleb564aae2014-10-23 10:18:09 -07001137 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 if (DBG) log("call: " + number);
1139
1140 // This is just a wrapper around the ACTION_CALL intent, but we still
1141 // need to do a permission check since we're calling startActivity()
1142 // from the context of the phone app.
1143 enforceCallPermission();
1144
1145 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1146 != AppOpsManager.MODE_ALLOWED) {
1147 return;
1148 }
1149
1150 String url = createTelUrl(number);
1151 if (url == null) {
1152 return;
1153 }
1154
Wink Saville08874612014-08-31 19:19:58 -07001155 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001156 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001157 if (slist != null) {
1158 for (SubscriptionInfo subInfoRecord : slist) {
1159 if (subInfoRecord.getSubscriptionId() == subId) {
1160 isValid = true;
1161 break;
1162 }
Wink Saville08874612014-08-31 19:19:58 -07001163 }
1164 }
1165 if (isValid == false) {
1166 return;
1167 }
1168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001170 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1172 mApp.startActivity(intent);
1173 }
1174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 /**
1176 * End a call based on call state
1177 * @return true is a call was ended
1178 */
1179 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001180 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
1183 /**
1184 * End a call based on the call state of the subId
1185 * @return true is a call was ended
1186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001187 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001189 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
1192 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001193 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001194 }
1195
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 if (DBG) log("answerRingingCall...");
1198 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1199 // but that can probably wait till the big TelephonyManager API overhaul.
1200 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1201 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001202 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 }
1204
1205 /**
1206 * Make the actual telephony calls to implement answerRingingCall().
1207 * This should only be called from the main thread of the Phone app.
1208 * @see #answerRingingCall
1209 *
1210 * TODO: it would be nice to return true if we answered the call, or
1211 * false if there wasn't actually a ringing incoming call, or some
1212 * other error occurred. (In other words, pass back the return value
1213 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1214 * But that would require calling this method via sendRequest() rather
1215 * than sendRequestAsync(), and right now we don't actually *need* that
1216 * return value, so let's just return void for now.
1217 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001219 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001221 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1222 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 if (hasActiveCall && hasHoldingCall) {
1224 // Both lines are in use!
1225 // TODO: provide a flag to let the caller specify what
1226 // policy to use if both lines are in use. (The current
1227 // behavior is hardwired to "answer incoming, end ongoing",
1228 // which is how the CALL button is specced to behave.)
1229 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1230 return;
1231 } else {
1232 // answerCall() will automatically hold the current active
1233 // call, if there is one.
1234 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1235 return;
1236 }
1237 } else {
1238 // No call was ringing.
1239 return;
1240 }
1241 }
1242
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001244 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001246 public void silenceRinger() {
1247 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 }
1249
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001250 @Override
1251 public boolean isOffhook(String callingPackage) {
1252 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1257 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1258 return false;
1259 }
1260
Sanket Padawe356d7632015-06-22 14:03:32 -07001261 final Phone phone = getPhone(subId);
1262 if (phone != null) {
1263 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1264 } else {
1265 return false;
1266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isRinging(String callingPackage) {
1271 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1276 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1277 return false;
1278 }
1279
Sanket Padawe356d7632015-06-22 14:03:32 -07001280 final Phone phone = getPhone(subId);
1281 if (phone != null) {
1282 return (phone.getState() == PhoneConstants.State.RINGING);
1283 } else {
1284 return false;
1285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isIdle(String callingPackage) {
1290 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1295 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1296 return false;
1297 }
1298
Sanket Padawe356d7632015-06-22 14:03:32 -07001299 final Phone phone = getPhone(subId);
1300 if (phone != null) {
1301 return (phone.getState() == PhoneConstants.State.IDLE);
1302 } else {
1303 return false;
1304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 }
1306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1314 }
1315
1316 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1323 }
1324
1325 /** {@hide} */
1326 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
1329
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001332 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 checkSimPin.start();
1334 return checkSimPin.unlockSim(null, pin);
1335 }
1336
Wink Saville9de0f752013-10-22 19:04:03 -07001337 /** {@hide} */
1338 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001344 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 checkSimPuk.start();
1346 return checkSimPuk.unlockSim(puk, pin);
1347 }
1348
1349 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001350 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 * a synchronous one.
1352 */
1353 private static class UnlockSim extends Thread {
1354
1355 private final IccCard mSimCard;
1356
1357 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001358 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1359 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
1361 // For replies from SimCard interface
1362 private Handler mHandler;
1363
1364 // For async handler to identify request type
1365 private static final int SUPPLY_PIN_COMPLETE = 100;
1366
1367 public UnlockSim(IccCard simCard) {
1368 mSimCard = simCard;
1369 }
1370
1371 @Override
1372 public void run() {
1373 Looper.prepare();
1374 synchronized (UnlockSim.this) {
1375 mHandler = new Handler() {
1376 @Override
1377 public void handleMessage(Message msg) {
1378 AsyncResult ar = (AsyncResult) msg.obj;
1379 switch (msg.what) {
1380 case SUPPLY_PIN_COMPLETE:
1381 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1382 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001383 mRetryCount = msg.arg1;
1384 if (ar.exception != null) {
1385 if (ar.exception instanceof CommandException &&
1386 ((CommandException)(ar.exception)).getCommandError()
1387 == CommandException.Error.PASSWORD_INCORRECT) {
1388 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1389 } else {
1390 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1391 }
1392 } else {
1393 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mDone = true;
1396 UnlockSim.this.notifyAll();
1397 }
1398 break;
1399 }
1400 }
1401 };
1402 UnlockSim.this.notifyAll();
1403 }
1404 Looper.loop();
1405 }
1406
1407 /*
1408 * Use PIN or PUK to unlock SIM card
1409 *
1410 * If PUK is null, unlock SIM card with PIN
1411 *
1412 * If PUK is not null, unlock SIM card with PUK and set PIN code
1413 */
Wink Saville9de0f752013-10-22 19:04:03 -07001414 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415
1416 while (mHandler == null) {
1417 try {
1418 wait();
1419 } catch (InterruptedException e) {
1420 Thread.currentThread().interrupt();
1421 }
1422 }
1423 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1424
1425 if (puk == null) {
1426 mSimCard.supplyPin(pin, callback);
1427 } else {
1428 mSimCard.supplyPuk(puk, pin, callback);
1429 }
1430
1431 while (!mDone) {
1432 try {
1433 Log.d(LOG_TAG, "wait for done");
1434 wait();
1435 } catch (InterruptedException e) {
1436 // Restore the interrupted status
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001441 int[] resultArray = new int[2];
1442 resultArray[0] = mResult;
1443 resultArray[1] = mRetryCount;
1444 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 }
1446 }
1447
1448 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001450
1451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 // No permission check needed here: this call is harmless, and it's
1455 // needed for the ServiceState.requestStateUpdate() call (which is
1456 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001457 final Phone phone = getPhone(subId);
1458 if (phone != null) {
1459 phone.updateServiceLocation();
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001463 @Override
1464 public boolean isRadioOn(String callingPackage) {
1465 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1470 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1471 return false;
1472 }
1473 return isRadioOnForSubscriber(subId);
1474 }
1475
1476 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1480 } else {
1481 return false;
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
1485 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
Wink Saville36469e72014-06-11 15:17:00 -07001489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 final Phone phone = getPhone(subId);
1493 if (phone != null) {
1494 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1495 }
Wink Saville36469e72014-06-11 15:17:00 -07001496 }
1497
1498 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001503 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001504 final Phone phone = getPhone(subId);
1505 if (phone == null) {
1506 return false;
1507 }
1508 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001509 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 return true;
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001515 public boolean needMobileRadioShutdown() {
1516 /*
1517 * If any of the Radios are available, it will need to be
1518 * shutdown. So return true if any Radio is available.
1519 */
1520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1521 Phone phone = PhoneFactory.getPhone(i);
1522 if (phone != null && phone.isRadioAvailable()) return true;
1523 }
1524 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1525 return false;
1526 }
1527
1528 public void shutdownMobileRadios() {
1529 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1530 logv("Shutting down Phone " + i);
1531 shutdownRadioUsingPhoneId(i);
1532 }
1533 }
1534
1535 private void shutdownRadioUsingPhoneId(int phoneId) {
1536 enforceModifyPermission();
1537 Phone phone = PhoneFactory.getPhone(phoneId);
1538 if (phone != null && phone.isRadioAvailable()) {
1539 phone.shutdownRadio();
1540 }
1541 }
1542
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001544 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001545 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1546 if (defaultPhone != null) {
1547 defaultPhone.setRadioPower(turnOn);
1548 return true;
1549 } else {
1550 loge("There's no default phone.");
1551 return false;
1552 }
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 phone.setRadioPower(turnOn);
1560 return true;
1561 } else {
1562 return false;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville36469e72014-06-11 15:17:00 -07001566 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 public boolean enableDataConnectivity() {
1569 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001570 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001573 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 return true;
1575 } else {
1576 return false;
1577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Wink Saville36469e72014-06-11 15:17:00 -07001580 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 public boolean disableDataConnectivity() {
1583 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001584 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 final Phone phone = getPhone(subId);
1586 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001587 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 return true;
1589 } else {
1590 return false;
1591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 }
1593
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001595 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 final Phone phone = getPhone(subId);
1597 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001598 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 } else {
1600 return false;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
1603
1604 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001606 }
1607
pkanwarae03a6b2016-11-06 20:37:09 -08001608 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001609 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1611 return;
1612 }
1613 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1614 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1615 };
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1620 return false;
1621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001626 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001629 public int getCallStateForSlot(int slotIndex) {
1630 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001631 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001632 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
1634
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001637 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001639 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001641 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 }
1644
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001647 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 if (phone != null) {
1649 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1650 } else {
1651 return TelephonyManager.DATA_ACTIVITY_NONE;
1652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001656 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001657 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001658 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001659 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
1661
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001662 if (DBG_LOC) log("getCellLocation: is active user");
1663 Bundle data = new Bundle();
1664 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1665 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 return null;
1667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001670 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1671 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001672 }
1673
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001675 public String getNetworkCountryIsoForPhone(int phoneId) {
1676 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1677 // registered cell info, so return a NULL country instead.
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1681 if (TelephonyManager.NETWORK_TYPE_IWLAN
1682 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1683 return "";
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
1687 }
1688 return TelephonyManager.getTelephonyProperty(
1689 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1690 }
1691
1692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001694 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001695 }
1696
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001698 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 mApp.enforceCallingOrSelfPermission(
1700 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.enableLocationUpdates();
1704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 @Override
1708 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 mApp.enforceCallingOrSelfPermission(
1715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.disableLocationUpdates();
1719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 @Override
1723 @SuppressWarnings("unchecked")
1724 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001725 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001726 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001727 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
1730 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1731 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1732 return null;
1733 }
Svetoslav64fad262015-04-14 14:35:21 -07001734
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001735 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001737 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001739 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001740 try {
1741 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1742 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1743 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1744 } catch (RuntimeException e) {
1745 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750
1751 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001752 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001753 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001754 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001755 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001760 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1761 for (Phone phone : PhoneFactory.getPhones()) {
1762 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1763 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001768 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001770 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001772 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Shishir Agrawala9f32182016-04-12 12:00:16 -07001775 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001776 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001777 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1778 return null;
1779 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001780 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 return phone == null ? null : phone.getImei();
1782 }
1783
1784 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001785 public String getMeidForSlot(int slotIndex, String callingPackage) {
1786 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1787 return null;
1788 }
1789 Phone phone = PhoneFactory.getPhone(slotIndex);
1790 return phone == null ? null : phone.getMeid();
1791 }
1792
1793 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001794 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001795 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1796 return null;
1797 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001798 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 return phone == null ? null : phone.getDeviceSvn();
1800 }
1801
fionaxu43304da2017-11-27 22:51:16 -08001802 @Override
1803 public int getSubscriptionCarrierId(int subId) {
1804 final Phone phone = getPhone(subId);
1805 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1806 }
1807
1808 @Override
1809 public String getSubscriptionCarrierName(int subId) {
1810 final Phone phone = getPhone(subId);
1811 return phone == null ? null : phone.getCarrierName();
1812 }
1813
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 //
1815 // Internal helper methods.
1816 //
1817
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001818 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1820 *
1821 * @throws SecurityException if the caller does not have the required permission
1822 */
1823 private void enforceModifyPermission() {
1824 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1825 }
1826
1827 /**
Junda Liua2e36012014-07-09 18:30:01 -07001828 * Make sure either system app or the caller has carrier privilege.
1829 *
1830 * @throws SecurityException if the caller does not have the required permission/privilege
1831 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001832 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001833 int permission = mApp.checkCallingOrSelfPermission(
1834 android.Manifest.permission.MODIFY_PHONE_STATE);
1835 if (permission == PackageManager.PERMISSION_GRANTED) {
1836 return;
1837 }
1838
1839 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001840 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001841 }
1842
1843 /**
1844 * Make sure the caller has carrier privilege.
1845 *
1846 * @throws SecurityException if the caller does not have the required permission
1847 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001848 private void enforceCarrierPrivilege(int subId) {
1849 if (getCarrierPrivilegeStatus(subId) !=
1850 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001851 loge("No Carrier Privilege.");
1852 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001853 }
1854 }
1855
1856 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 * Make sure the caller has the CALL_PHONE permission.
1858 *
1859 * @throws SecurityException if the caller does not have the required permission
1860 */
1861 private void enforceCallPermission() {
1862 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1863 }
1864
Stuart Scott8eef64f2015-04-08 15:13:54 -07001865 private void enforceConnectivityInternalPermission() {
1866 mApp.enforceCallingOrSelfPermission(
1867 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1868 "ConnectivityService");
1869 }
1870
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 private String createTelUrl(String number) {
1872 if (TextUtils.isEmpty(number)) {
1873 return null;
1874 }
1875
Jake Hambye994d462014-02-03 13:10:13 -08001876 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
Ihab Awadf9e92732013-12-05 18:02:52 -08001879 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1881 }
1882
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001883 private static void logv(String msg) {
1884 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1885 }
1886
Ihab Awadf9e92732013-12-05 18:02:52 -08001887 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1889 }
1890
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001893 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001897 public int getActivePhoneTypeForSlot(int slotIndex) {
1898 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 if (phone == null) {
1900 return PhoneConstants.PHONE_TYPE_NONE;
1901 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001902 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
1906 /**
1907 * Returns the CDMA ERI icon index to display
1908 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001909 @Override
1910 public int getCdmaEriIconIndex(String callingPackage) {
1911 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001912 }
1913
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1916 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1917 return -1;
1918 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 final Phone phone = getPhone(subId);
1920 if (phone != null) {
1921 return phone.getCdmaEriIconIndex();
1922 } else {
1923 return -1;
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
1927 /**
1928 * Returns the CDMA ERI icon mode,
1929 * 0 - ON
1930 * 1 - FLASHING
1931 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 @Override
1933 public int getCdmaEriIconMode(String callingPackage) {
1934 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001935 }
1936
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001938 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1939 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1940 return -1;
1941 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 return phone.getCdmaEriIconMode();
1945 } else {
1946 return -1;
1947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
1950 /**
1951 * Returns the CDMA ERI text,
1952 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001953 @Override
1954 public String getCdmaEriText(String callingPackage) {
1955 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1960 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1961 return null;
1962 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 final Phone phone = getPhone(subId);
1964 if (phone != null) {
1965 return phone.getCdmaEriText();
1966 } else {
1967 return null;
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
1971 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001972 * Returns the CDMA MDN.
1973 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001975 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001976 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 final Phone phone = getPhone(subId);
1978 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1979 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001980 } else {
1981 return null;
1982 }
1983 }
1984
1985 /**
1986 * Returns the CDMA MIN.
1987 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001989 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001990 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 final Phone phone = getPhone(subId);
1992 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1993 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001994 } else {
1995 return null;
1996 }
1997 }
1998
1999 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 * Returns true if CDMA provisioning needs to run.
2001 */
2002 public boolean needsOtaServiceProvisioning() {
2003 return mPhone.needsOtaServiceProvisioning();
2004 }
2005
2006 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002007 * Sets the voice mail number of a given subId.
2008 */
2009 @Override
2010 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002011 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002012 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2013 new Pair<String, String>(alphaTag, number), new Integer(subId));
2014 return success;
2015 }
2016
Ta-wei Yen87c49842016-05-13 21:19:52 -07002017 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002018 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2020 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2021 if (!TextUtils.equals(callingPackage, systemDialer)) {
2022 throw new SecurityException("caller must be system dialer");
2023 }
2024 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2025 if (phoneAccountHandle == null){
2026 return null;
2027 }
2028 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2029 }
2030
2031 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002032 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2034 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2035 return null;
2036 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002037 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2038 }
2039
2040 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002041 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2042 VisualVoicemailSmsFilterSettings settings) {
2043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002044 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002045 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2046 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002047 }
2048
2049 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002050 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002053 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002054 }
2055
2056 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2058 String callingPackage, int subId) {
2059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002062 }
2063
2064 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002065 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002066 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002067 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002068 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2069 }
2070
2071 @Override
2072 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2073 String number, int port, String text, PendingIntent sentIntent) {
2074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002075 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002076 enforceSendSmsPermission();
2077 // Make the calls as the phone process.
2078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2081 if (port == 0) {
2082 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2083 sentIntent, null, false);
2084 } else {
2085 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2086 smsManager.sendDataMessageWithSelfPermissions(number, null,
2087 (short) port, data, sentIntent, null);
2088 }
2089 } finally {
2090 Binder.restoreCallingIdentity(identity);
2091 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002092 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002093 /**
fionaxu0152e512016-11-14 13:36:14 -08002094 * Sets the voice activation state of a given subId.
2095 */
2096 @Override
2097 public void setVoiceActivationState(int subId, int activationState) {
2098 enforceModifyPermissionOrCarrierPrivilege(subId);
2099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 phone.setVoiceActivationState(activationState);
2102 } else {
2103 loge("setVoiceActivationState fails with invalid subId: " + subId);
2104 }
2105 }
2106
2107 /**
2108 * Sets the data activation state of a given subId.
2109 */
2110 @Override
2111 public void setDataActivationState(int subId, int activationState) {
2112 enforceModifyPermissionOrCarrierPrivilege(subId);
2113 final Phone phone = getPhone(subId);
2114 if (phone != null) {
2115 phone.setDataActivationState(activationState);
2116 } else {
2117 loge("setVoiceActivationState fails with invalid subId: " + subId);
2118 }
2119 }
2120
2121 /**
2122 * Returns the voice activation state of a given subId.
2123 */
2124 @Override
2125 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002126 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 return phone.getVoiceActivationState();
2130 } else {
2131 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2132 }
2133 }
2134
2135 /**
2136 * Returns the data activation state of a given subId.
2137 */
2138 @Override
2139 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002140 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002141 final Phone phone = getPhone(subId);
2142 if (phone != null) {
2143 return phone.getDataActivationState();
2144 } else {
2145 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2146 }
2147 }
2148
2149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 * Returns the unread count of voicemails
2151 */
2152 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002153 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002154 }
2155
2156 /**
2157 * Returns the unread count of voicemails for a subId
2158 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002159 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002160 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 final Phone phone = getPhone(subId);
2162 if (phone != null) {
2163 return phone.getVoiceMessageCount();
2164 } else {
2165 return 0;
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
2169 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002170 * returns true, if the device is in a state where both voice and data
2171 * are supported simultaneously. This can change based on location or network condition.
2172 */
2173 @Override
2174 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2175 final Phone phone = getPhone(subId);
2176 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2177 }
2178
2179 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002180 * Send the dialer code if called from the current default dialer or the caller has
2181 * carrier privilege.
2182 * @param inputCode The dialer code to send
2183 */
2184 @Override
2185 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2187 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2188 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2189 enforceCarrierPrivilege(getDefaultSubscription());
2190 }
2191 mPhone.sendDialerSpecialCode(inputCode);
2192 }
2193
2194 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002195 * Returns the data network type.
2196 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 *
2198 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2199 */
2200 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002201 public int getNetworkType() {
2202 final Phone phone = getPhone(getDefaultSubscription());
2203 if (phone != null) {
2204 return phone.getServiceState().getDataNetworkType();
2205 } else {
2206 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2207 }
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
2210 /**
2211 * Returns the network type for a subId
2212 */
2213 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2215 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2217 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 return phone.getServiceState().getDataNetworkType();
2222 } else {
2223 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
2227 /**
2228 * Returns the data network type
2229 */
2230 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 public int getDataNetworkType(String callingPackage) {
2232 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002233 }
2234
2235 /**
2236 * Returns the data network type for a subId
2237 */
2238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2240 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2241 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2242 }
2243
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 final Phone phone = getPhone(subId);
2245 if (phone != null) {
2246 return phone.getServiceState().getDataNetworkType();
2247 } else {
2248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
Wink Saville36469e72014-06-11 15:17:00 -07002253 * Returns the Voice network type for a subId
2254 */
2255 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002256 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2257 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2259 }
2260
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 final Phone phone = getPhone(subId);
2262 if (phone != null) {
2263 return phone.getServiceState().getVoiceNetworkType();
2264 } else {
2265 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
2270 * @return true if a ICC card is present
2271 */
2272 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002273 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002274 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2275 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
2278 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002279 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002280 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002281 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002282 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2283 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002284 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002285 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002286 } else {
2287 return false;
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * Return if the current radio is LTE on CDMA. This
2293 * is a tri-state return value as for a period of time
2294 * the mode may be unknown.
2295 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002296 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002298 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 @Override
2301 public int getLteOnCdmaMode(String callingPackage) {
2302 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002303 }
2304
Sanket Padawe356d7632015-06-22 14:03:32 -07002305 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2307 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2308 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2309 }
2310
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 final Phone phone = getPhone(subId);
2312 if (phone == null) {
2313 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2314 } else {
2315 return phone.getLteOnCdmaMode();
2316 }
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
2319 public void setPhone(Phone phone) {
2320 mPhone = phone;
2321 }
2322
2323 /**
2324 * {@hide}
2325 * Returns Default subId, 0 in the case of single standby.
2326 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002327 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002328 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002329 }
2330
Shishir Agrawala9f32182016-04-12 12:00:16 -07002331 private int getSlotForDefaultSubscription() {
2332 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2333 }
2334
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002336 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002338
2339 /**
2340 * @see android.telephony.TelephonyManager.WifiCallingChoices
2341 */
2342 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002343 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2344 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002345 }
2346
2347 /**
2348 * @see android.telephony.TelephonyManager.WifiCallingChoices
2349 */
2350 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002351 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2352 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2353 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002354 }
2355
Sailesh Nepald1e68152013-12-12 19:08:02 -08002356 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002357 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002358 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002359 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002360
Shishir Agrawal566b7612013-10-28 14:41:00 -07002361 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002362 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2363 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002364 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002365
Derek Tan740e1672017-06-27 14:56:27 -07002366 if (TextUtils.equals(ISDR_AID, aid)) {
2367 // Only allows LPA to open logical channel to ISD-R.
2368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2369 ComponentInfo bestComponent =
2370 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2371 if (bestComponent == null
2372 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2373 loge("The calling package is not allowed to access ISD-R.");
2374 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2375 }
2376 }
2377
2378 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002379 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002380 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002381 if (DBG) log("iccOpenLogicalChannel: " + response);
2382 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383 }
2384
2385 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002386 public boolean iccCloseLogicalChannel(int subId, int channel) {
2387 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002388
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390 if (channel < 0) {
2391 return false;
2392 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394 if (DBG) log("iccCloseLogicalChannel: " + success);
2395 return success;
2396 }
2397
2398 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402
2403 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2405 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002406 " data=" + data);
2407 }
2408
2409 if (channel < 0) {
2410 return "";
2411 }
2412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002413 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2416
Shishir Agrawal566b7612013-10-28 14:41:00 -07002417 // Append the returned status code to the end of the response payload.
2418 String s = Integer.toHexString(
2419 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002420 if (response.payload != null) {
2421 s = IccUtils.bytesToHexString(response.payload) + s;
2422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 return s;
2424 }
Jake Hambye994d462014-02-03 13:10:13 -08002425
Evan Charltonc66da362014-05-16 14:06:40 -07002426 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002427 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2428 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002430
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002431 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2432 && TextUtils.equals(ISDR_AID, data)) {
2433 // Only allows LPA to select ISD-R.
2434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2435 ComponentInfo bestComponent =
2436 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2437 if (bestComponent == null
2438 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2439 loge("The calling package is not allowed to select ISD-R.");
2440 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2441 }
2442 }
2443
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002444 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002445 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2446 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002447 }
2448
2449 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002450 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002451 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 // Append the returned status code to the end of the response payload.
2454 String s = Integer.toHexString(
2455 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002456 if (response.payload != null) {
2457 s = IccUtils.bytesToHexString(response.payload) + s;
2458 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 return s;
2460 }
2461
2462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002463 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002464 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002466
2467 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002468 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 p1 + " " + p2 + " " + p3 + ":" + filePath);
2470 }
2471
2472 IccIoResult response =
2473 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2475 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476
2477 if (DBG) {
2478 log("Exchange SIM_IO [R]" + response);
2479 }
2480
2481 byte[] result = null;
2482 int length = 2;
2483 if (response.payload != null) {
2484 length = 2 + response.payload.length;
2485 result = new byte[length];
2486 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2487 } else {
2488 result = new byte[length];
2489 }
2490
2491 result[length - 1] = (byte) response.sw2;
2492 result[length - 2] = (byte) response.sw1;
2493 return result;
2494 }
2495
Nathan Haroldb3014052017-01-25 15:57:32 -08002496 /**
2497 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2498 * on a particular subscription
2499 */
2500 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002501 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2502 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002503 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2504 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2505 return null;
2506 }
2507 Object response = sendRequest(
2508 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2509 if (response instanceof String[]) {
2510 return (String[]) response;
2511 }
2512 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2513 return null;
2514 }
2515
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002516 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002517 public String sendEnvelopeWithStatus(int subId, String content) {
2518 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002519
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002521 if (response.payload == null) {
2522 return "";
2523 }
2524
2525 // Append the returned status code to the end of the response payload.
2526 String s = Integer.toHexString(
2527 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2528 s = IccUtils.bytesToHexString(response.payload) + s;
2529 return s;
2530 }
2531
Jake Hambye994d462014-02-03 13:10:13 -08002532 /**
2533 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2534 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2535 *
2536 * @param itemID the ID of the item to read
2537 * @return the NV item as a String, or null on error.
2538 */
2539 @Override
2540 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002541 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002542 if (DBG) log("nvReadItem: item " + itemID);
2543 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2544 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2545 return value;
2546 }
2547
2548 /**
2549 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2550 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2551 *
2552 * @param itemID the ID of the item to read
2553 * @param itemValue the value to write, as a String
2554 * @return true on success; false on any failure
2555 */
2556 @Override
2557 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002559 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2560 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2561 new Pair<Integer, String>(itemID, itemValue));
2562 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2563 return success;
2564 }
2565
2566 /**
2567 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2568 * Used for device configuration by some CDMA operators.
2569 *
2570 * @param preferredRoamingList byte array containing the new PRL
2571 * @return true on success; false on any failure
2572 */
2573 @Override
2574 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002575 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002576 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2577 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2578 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2579 return success;
2580 }
2581
2582 /**
2583 * Perform the specified type of NV config reset.
2584 * Used for device configuration by some CDMA operators.
2585 *
2586 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2587 * @return true on success; false on any failure
2588 */
2589 @Override
2590 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002591 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002592 if (DBG) log("nvResetConfig: type " + resetType);
2593 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2594 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2595 return success;
2596 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002597
2598 /**
Wink Saville36469e72014-06-11 15:17:00 -07002599 * {@hide}
2600 * Returns Default sim, 0 in the case of single standby.
2601 */
2602 public int getDefaultSim() {
2603 //TODO Need to get it from Telephony Devcontroller
2604 return 0;
2605 }
2606
Svet Ganovb320e182015-04-16 12:30:10 -07002607 public String[] getPcscfAddress(String apnType, String callingPackage) {
2608 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2609 return new String[0];
2610 }
2611
2612
ram87fca6f2014-07-18 18:58:44 +05302613 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002614 }
2615
Brad Ebinger51f743a2017-01-23 13:50:20 -08002616 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002617 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2618 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002619 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002620 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002621 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002622 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002623 }
2624
2625 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002626 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2627 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002628 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002629 public void disableIms(int slotId) {
2630 enforceModifyPermission();
2631 PhoneFactory.getImsResolver().disableIms(slotId);
2632 }
2633
2634 /**
2635 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2636 * feature or {@link null} if the service is not available. If the feature is available, the
2637 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2638 */
2639 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002640 IImsServiceFeatureCallback callback) {
2641 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002642 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002643 }
2644
2645 /**
2646 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2647 * feature during emergency calling or {@link null} if the service is not available. If the
2648 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2649 * listener for feature updates.
2650 */
2651 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2652 enforceModifyPermission();
2653 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002654 }
2655
Brad Ebinger5f64b052017-12-14 14:26:15 -08002656 /**
2657 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2658 * specified.
2659 */
2660 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2661 enforceModifyPermission();
2662 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2663 }
2664
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002665 /**
2666 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2667 * specified.
2668 */
2669 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2670 enforceModifyPermission();
2671 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2672 }
2673
Wink Saville36469e72014-06-11 15:17:00 -07002674 public void setImsRegistrationState(boolean registered) {
2675 enforceModifyPermission();
2676 mPhone.setImsRegistrationState(registered);
2677 }
2678
2679 /**
Stuart Scott54788802015-03-30 13:18:01 -07002680 * Set the network selection mode to automatic.
2681 *
2682 */
2683 @Override
2684 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002685 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002686 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2687 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2688 }
2689
2690 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002691 * Set the network selection mode to manual with the selected carrier.
2692 */
2693 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002694 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002695 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002696 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002697 OperatorInfo operator = new OperatorInfo(
2698 /* operatorAlphaLong */ "",
2699 /* operatorAlphaShort */ "",
2700 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002701 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002702 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2703 persistSelection);
2704 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002705 }
2706
2707 /**
2708 * Scans for available networks.
2709 */
2710 @Override
2711 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002712 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002713 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2714 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2715 CMD_PERFORM_NETWORK_SCAN, null, subId);
2716 return result;
2717 }
2718
2719 /**
yinxub1bed742017-04-17 11:45:04 -07002720 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002721 *
yinxub1bed742017-04-17 11:45:04 -07002722 * @param subId id of the subscription
2723 * @param request contains the radio access networks with bands/channels to scan
2724 * @param messenger callback messenger for scan results or errors
2725 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002726 * @return the id of the requested scan which can be used to stop the scan.
2727 */
2728 @Override
2729 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2730 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002731 enforceModifyPermissionOrCarrierPrivilege(subId);
2732 return mNetworkScanRequestTracker.startNetworkScan(
2733 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002734 }
2735
2736 /**
2737 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002738 *
2739 * @param subId id of the subscription
2740 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002741 */
2742 @Override
2743 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002744 enforceModifyPermissionOrCarrierPrivilege(subId);
2745 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002746 }
2747
2748 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002749 * Get the calculated preferred network type.
2750 * Used for debugging incorrect network type.
2751 *
2752 * @return the preferred network type, defined in RILConstants.java.
2753 */
2754 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002755 public int getCalculatedPreferredNetworkType(String callingPackage) {
2756 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2757 return RILConstants.PREFERRED_NETWORK_MODE;
2758 }
2759
Amit Mahajan43330e02014-11-18 11:54:45 -08002760 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002761 }
2762
2763 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002764 * Get the preferred network type.
2765 * Used for device configuration by some CDMA operators.
2766 *
2767 * @return the preferred network type, defined in RILConstants.java.
2768 */
2769 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002770 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002771 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002772 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002773 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002774 int networkType = (result != null ? result[0] : -1);
2775 if (DBG) log("getPreferredNetworkType: " + networkType);
2776 return networkType;
2777 }
2778
2779 /**
2780 * Set the preferred network type.
2781 * Used for device configuration by some CDMA operators.
2782 *
2783 * @param networkType the preferred network type, defined in RILConstants.java.
2784 * @return true on success; false on any failure.
2785 */
2786 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002787 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002788 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002789 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2790 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002791 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002792 if (success) {
2793 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002794 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002795 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002796 return success;
2797 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002798
2799 /**
Junda Liu475951f2014-11-07 16:45:03 -08002800 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2801 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2802 * tethering.
2803 *
2804 * @return 0: Not required. 1: required. 2: Not set.
2805 * @hide
2806 */
2807 @Override
2808 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002809 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002810 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2811 Settings.Global.TETHER_DUN_REQUIRED, 2);
2812 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2813 // config_tether_apndata.
2814 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2815 dunRequired = 1;
2816 }
2817 return dunRequired;
2818 }
2819
2820 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002821 * Set mobile data enabled
2822 * Used by the user through settings etc to turn on/off mobile data
2823 *
2824 * @param enable {@code true} turn turn data on, else {@code false}
2825 */
2826 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002827 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002828 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002829 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002830 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002831 Phone phone = PhoneFactory.getPhone(phoneId);
2832 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002833 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2834 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002835 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002836 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002837 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002838 }
2839
2840 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002841 * Get the user enabled state of Mobile Data.
2842 *
2843 * TODO: remove and use isUserDataEnabled.
2844 * This can't be removed now because some vendor codes
2845 * calls through ITelephony directly while they should
2846 * use TelephonyManager.
2847 *
2848 * @return true on enabled
2849 */
2850 @Override
2851 public boolean getDataEnabled(int subId) {
2852 return isUserDataEnabled(subId);
2853 }
2854
2855 /**
2856 * Get whether mobile data is enabled per user setting.
2857 *
2858 * There are other factors deciding whether mobile data is actually enabled, but they are
2859 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002860 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002861 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002862 *
2863 * @return {@code true} if data is enabled else {@code false}
2864 */
2865 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002866 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002867 try {
2868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2869 null);
2870 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002871 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002872 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002873 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002874 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002875 Phone phone = PhoneFactory.getPhone(phoneId);
2876 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002877 boolean retVal = phone.isUserDataEnabled();
2878 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 return retVal;
2880 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002881 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2882 return false;
2883 }
2884 }
2885
2886 /**
2887 * Get whether mobile data is enabled.
2888 *
2889 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2890 * whether mobile data is actually enabled.
2891 *
2892 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2893 *
2894 * @return {@code true} if data is enabled else {@code false}
2895 */
2896 @Override
2897 public boolean isDataEnabled(int subId) {
2898 try {
2899 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2900 null);
2901 } catch (Exception e) {
2902 enforceModifyPermissionOrCarrierPrivilege(subId);
2903 }
2904 int phoneId = mSubscriptionController.getPhoneId(subId);
2905 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2906 Phone phone = PhoneFactory.getPhone(phoneId);
2907 if (phone != null) {
2908 boolean retVal = phone.isDataEnabled();
2909 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2910 return retVal;
2911 } else {
2912 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002913 return false;
2914 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002915 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002916
2917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002918 public int getCarrierPrivilegeStatus(int subId) {
2919 final Phone phone = getPhone(subId);
2920 if (phone == null) {
2921 loge("getCarrierPrivilegeStatus: Invalid subId");
2922 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2923 }
2924 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002925 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002926 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002927 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2928 }
2929 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002930 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002931 }
Junda Liu29340342014-07-10 15:23:27 -07002932
2933 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002934 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002935 if (TextUtils.isEmpty(pkgName))
2936 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002937 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002938 if (card == null) {
2939 loge("checkCarrierPrivilegesForPackage: No UICC");
2940 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2941 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002942 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2943 }
2944
2945 @Override
2946 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002947 if (TextUtils.isEmpty(pkgName))
2948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002949 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2950 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2951 UiccCard card = UiccController.getInstance().getUiccCard(i);
2952 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002953 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002954 continue;
2955 }
2956
2957 result = card.getCarrierPrivilegeStatus(
2958 mPhone.getContext().getPackageManager(), pkgName);
2959 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2960 break;
2961 }
2962 }
2963
2964 return result;
Junda Liu29340342014-07-10 15:23:27 -07002965 }
Derek Tan89e89d42014-07-08 17:00:10 -07002966
2967 @Override
Junda Liue64de782015-04-16 17:19:16 -07002968 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2969 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2970 loge("phoneId " + phoneId + " is not valid.");
2971 return null;
2972 }
2973 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002974 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002975 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002976 return null ;
2977 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002978 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002979 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002980 }
2981
Amith Yamasani6e118872016-02-19 12:53:51 -08002982 @Override
2983 public List<String> getPackagesWithCarrierPrivileges() {
2984 PackageManager pm = mPhone.getContext().getPackageManager();
2985 List<String> privilegedPackages = new ArrayList<>();
2986 List<PackageInfo> packages = null;
2987 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2988 UiccCard card = UiccController.getInstance().getUiccCard(i);
2989 if (card == null) {
2990 // No UICC in that slot.
2991 continue;
2992 }
2993 if (card.hasCarrierPrivilegeRules()) {
2994 if (packages == null) {
2995 // Only check packages in user 0 for now
2996 packages = pm.getInstalledPackagesAsUser(
2997 PackageManager.MATCH_DISABLED_COMPONENTS
2998 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2999 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3000 }
3001 for (int p = packages.size() - 1; p >= 0; p--) {
3002 PackageInfo pkgInfo = packages.get(p);
3003 if (pkgInfo != null && pkgInfo.packageName != null
3004 && card.getCarrierPrivilegeStatus(pkgInfo)
3005 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3006 privilegedPackages.add(pkgInfo.packageName);
3007 }
3008 }
3009 }
3010 }
3011 return privilegedPackages;
3012 }
3013
Wink Savilleb564aae2014-10-23 10:18:09 -07003014 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 final Phone phone = getPhone(subId);
3016 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003017 if (card == null) {
3018 loge("getIccId: No UICC");
3019 return null;
3020 }
3021 String iccId = card.getIccId();
3022 if (TextUtils.isEmpty(iccId)) {
3023 loge("getIccId: ICC ID is null or empty.");
3024 return null;
3025 }
3026 return iccId;
3027 }
3028
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003029 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003030 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3031 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003032 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003033
Jeff Sharkey85190e62014-12-05 09:40:12 -08003034 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003035 final Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 return false;
3038 }
3039 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003040
3041 if (DBG_MERGE) {
3042 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3043 + subscriberId + " to " + number);
3044 }
3045
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003046 if (TextUtils.isEmpty(iccId)) {
3047 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003048 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003049
Jeff Sharkey85190e62014-12-05 09:40:12 -08003050 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3051
3052 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003053 if (alphaTag == null) {
3054 editor.remove(alphaTagPrefKey);
3055 } else {
3056 editor.putString(alphaTagPrefKey, alphaTag);
3057 }
3058
Jeff Sharkey85190e62014-12-05 09:40:12 -08003059 // Record both the line number and IMSI for this ICCID, since we need to
3060 // track all merged IMSIs based on line number
3061 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3062 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003063 if (number == null) {
3064 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003065 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003066 } else {
3067 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003068 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003069 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003070
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003071 editor.commit();
3072 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003073 }
3074
3075 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003076 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003077 // This is open to apps with WRITE_SMS.
3078 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003079 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003080 return null;
3081 }
Derek Tan97ebb422014-09-05 16:55:38 -07003082
3083 String iccId = getIccId(subId);
3084 if (iccId != null) {
3085 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003086 if (DBG_MERGE) {
3087 log("getLine1NumberForDisplay returning " +
3088 mTelephonySharedPreferences.getString(numberPrefKey, null));
3089 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003090 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003091 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003092 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003093 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003094 }
3095
3096 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003097 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3098 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3099 return null;
3100 }
Derek Tan97ebb422014-09-05 16:55:38 -07003101
3102 String iccId = getIccId(subId);
3103 if (iccId != null) {
3104 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003105 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003106 }
Derek Tan97ebb422014-09-05 16:55:38 -07003107 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003108 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003109
3110 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003111 public String[] getMergedSubscriberIds(String callingPackage) {
3112 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3113 return null;
3114 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003115 final Context context = mPhone.getContext();
3116 final TelephonyManager tele = TelephonyManager.from(context);
3117 final SubscriptionManager sub = SubscriptionManager.from(context);
3118
3119 // Figure out what subscribers are currently active
3120 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003121 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3122 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 final int[] subIds = sub.getActiveSubscriptionIdList();
3126 for (int subId : subIds) {
3127 activeSubscriberIds.add(tele.getSubscriberId(subId));
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003131 }
3132
3133 // First pass, find a number override for an active subscriber
3134 String mergeNumber = null;
3135 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3136 for (String key : prefs.keySet()) {
3137 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3138 final String subscriberId = (String) prefs.get(key);
3139 if (activeSubscriberIds.contains(subscriberId)) {
3140 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3141 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3142 mergeNumber = (String) prefs.get(numberKey);
3143 if (DBG_MERGE) {
3144 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3145 + " for active subscriber " + subscriberId);
3146 }
3147 if (!TextUtils.isEmpty(mergeNumber)) {
3148 break;
3149 }
3150 }
3151 }
3152 }
3153
3154 // Shortcut when no active merged subscribers
3155 if (TextUtils.isEmpty(mergeNumber)) {
3156 return null;
3157 }
3158
3159 // Second pass, find all subscribers under that line override
3160 final ArraySet<String> result = new ArraySet<>();
3161 for (String key : prefs.keySet()) {
3162 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3163 final String number = (String) prefs.get(key);
3164 if (mergeNumber.equals(number)) {
3165 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3166 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3167 final String subscriberId = (String) prefs.get(subscriberKey);
3168 if (!TextUtils.isEmpty(subscriberId)) {
3169 result.add(subscriberId);
3170 }
3171 }
3172 }
3173 }
3174
3175 final String[] resultArray = result.toArray(new String[result.size()]);
3176 Arrays.sort(resultArray);
3177 if (DBG_MERGE) {
3178 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3179 }
3180 return resultArray;
3181 }
3182
3183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003184 public boolean setOperatorBrandOverride(int subId, String brand) {
3185 enforceCarrierPrivilege(subId);
3186 final Phone phone = getPhone(subId);
3187 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003188 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003189
3190 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003191 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003192 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3193 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003194 enforceCarrierPrivilege(subId);
3195 final Phone phone = getPhone(subId);
3196 if (phone == null) {
3197 return false;
3198 }
3199 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003200 cdmaNonRoamingList);
3201 }
3202
3203 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003204 public void setRadioCapability(RadioAccessFamily[] rafs) {
3205 try {
3206 ProxyController.getInstance().setRadioCapability(rafs);
3207 } catch (RuntimeException e) {
3208 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3209 }
3210 }
3211
3212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003213 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3214 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3215 return RadioAccessFamily.RAF_UNKNOWN;
3216 }
3217
Wink Saville5d475dd2014-10-17 15:00:58 -07003218 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3219 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003220
3221 @Override
3222 public void enableVideoCalling(boolean enable) {
3223 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003224 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003225 }
3226
3227 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003228 public boolean isVideoCallingEnabled(String callingPackage) {
3229 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3230 return false;
3231 }
3232
Andrew Lee77527ac2014-10-21 16:57:39 -07003233 // Check the user preference and the system-level IMS setting. Even if the user has
3234 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3235 // In the long run, we may instead need to check if there exists a connection service
3236 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003237 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3238 return imsManager.isVtEnabledByPlatform()
3239 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3240 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003241 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003242
Andrew Leea1239f22015-03-02 17:44:07 -08003243 @Override
3244 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003245 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003246 }
3247
3248 @Override
3249 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003250 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003251 }
3252
Andrew Lee9431b832015-03-09 18:46:45 -07003253 @Override
3254 public boolean isTtyModeSupported() {
3255 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3256 TelephonyManager telephonyManager =
3257 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003258 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003259 }
3260
3261 @Override
3262 public boolean isHearingAidCompatibilitySupported() {
3263 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3264 }
3265
Hall Liu98187582018-01-22 19:15:32 -08003266 public boolean isRttSupported() {
3267 boolean isCarrierSupported =
3268 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3269 boolean isDeviceSupported =
3270 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3271 return isCarrierSupported && isDeviceSupported;
3272 }
3273
Sanket Padawe7310cc72015-01-14 09:53:20 -08003274 /**
3275 * Returns the unique device ID of phone, for example, the IMEI for
3276 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3277 *
3278 * <p>Requires Permission:
3279 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3280 */
3281 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003282 public String getDeviceId(String callingPackage) {
3283 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3284 return null;
3285 }
3286
Sanket Padawe7310cc72015-01-14 09:53:20 -08003287 final Phone phone = PhoneFactory.getPhone(0);
3288 if (phone != null) {
3289 return phone.getDeviceId();
3290 } else {
3291 return null;
3292 }
3293 }
3294
Ping Sunc67b7c22016-03-02 19:16:45 +08003295 /**
3296 * {@hide}
3297 * Returns the IMS Registration Status on a particular subid
3298 *
3299 * @param subId
3300 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003301 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003302 Phone phone = getPhone(subId);
3303 if (phone != null) {
3304 return phone.isImsRegistered();
3305 } else {
3306 return false;
3307 }
3308 }
3309
Santos Cordon7a1885b2015-02-03 11:15:19 -08003310 @Override
3311 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3312 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3313 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003314
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003315 /**
3316 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003317 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003318 public boolean isWifiCallingAvailable(int subId) {
3319 Phone phone = getPhone(subId);
3320 if (phone != null) {
3321 return phone.isWifiCallingEnabled();
3322 } else {
3323 return false;
3324 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003325 }
3326
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003327 /**
3328 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003329 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003330 public boolean isVolteAvailable(int subId) {
3331 Phone phone = getPhone(subId);
3332 if (phone != null) {
3333 return phone.isVolteEnabled();
3334 } else {
3335 return false;
3336 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003337 }
Svet Ganovb320e182015-04-16 12:30:10 -07003338
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003339 /**
3340 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003341 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003342 public boolean isVideoTelephonyAvailable(int subId) {
3343 Phone phone = getPhone(subId);
3344 if (phone != null) {
3345 return phone.isVideoEnabled();
3346 } else {
3347 return false;
3348 }
3349 }
3350
3351 /**
3352 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3353 * defined in {@link ImsRegistrationImplBase}.
3354 */
3355 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3356 Phone phone = getPhone(subId);
3357 if (phone != null) {
3358 return phone.getImsRegistrationTech();
3359 } else {
3360 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3361 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003362 }
3363
Svet Ganovb320e182015-04-16 12:30:10 -07003364 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003365 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003366 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003367 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3368
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003369 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003370 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003371 } catch (SecurityException e) {
3372 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3373 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003374 }
Svet Ganovb320e182015-04-16 12:30:10 -07003375
3376 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3377 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3378 return false;
3379 }
3380
3381 return true;
3382 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003383
Makoto Onukifee69342015-06-29 14:44:50 -07003384 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003385 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003386 */
3387 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003388 // Default SMS app can always read it.
3389 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3390 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3391 return true;
3392 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003393
Makoto Onukie4072d12015-08-03 15:12:23 -07003394 try {
3395 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003396 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003397 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003398 // Can be read with READ_SMS too.
3399 try {
3400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3401 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3402 if (opCode != AppOpsManager.OP_NONE) {
3403 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3404 == AppOpsManager.MODE_ALLOWED;
3405 } else {
3406 return true;
3407 }
3408 } catch (SecurityException readSmsSecurityException) {
3409 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003410 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003411 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003412 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003413 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003414 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003415 if (opCode != AppOpsManager.OP_NONE) {
3416 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3417 == AppOpsManager.MODE_ALLOWED;
3418 } else {
3419 return true;
3420 }
3421 } catch (SecurityException readPhoneNumberSecurityException) {
3422 }
3423
3424 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3425 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3426 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003427 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003428 }
3429
Stuart Scott8eef64f2015-04-08 15:13:54 -07003430 @Override
3431 public void factoryReset(int subId) {
3432 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003433 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3434 return;
3435 }
3436
Svet Ganovcc087f82015-05-12 20:35:54 -07003437 final long identity = Binder.clearCallingIdentity();
3438 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003439 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3440 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003441 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003442 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003443 // Set network selection mode to automatic
3444 setNetworkSelectionModeAutomatic(subId);
3445 // Set preferred mobile network type to the best available
3446 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3447 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003448 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003449 // Remove IMSI encryption keys from Carrier DB.
3450 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003451 }
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003454 }
3455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003456
3457 @Override
3458 public String getLocaleFromDefaultSim() {
3459 // We query all subscriptions instead of just the active ones, because
3460 // this might be called early on in the provisioning flow when the
3461 // subscriptions potentially aren't active yet.
3462 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3463 if (slist == null || slist.isEmpty()) {
3464 return null;
3465 }
3466
3467 // This function may be called very early, say, from the setup wizard, at
3468 // which point we won't have a default subscription set. If that's the case
3469 // we just choose the first, which will be valid in "most cases".
3470 final int defaultSubId = getDefaultSubscription();
3471 SubscriptionInfo info = null;
3472 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3473 info = slist.get(0);
3474 } else {
3475 for (SubscriptionInfo item : slist) {
3476 if (item.getSubscriptionId() == defaultSubId) {
3477 info = item;
3478 break;
3479 }
3480 }
3481
3482 if (info == null) {
3483 return null;
3484 }
3485 }
3486
3487 // Try and fetch the locale from the carrier properties or from the SIM language
3488 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003489 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003490 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003491 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003492 if (defaultPhone != null) {
3493 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3494 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003495 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003496 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3497 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003498 } else {
3499 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003500 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003501 }
3502 }
3503
Narayan Kamath011676f2015-07-29 12:04:08 +01003504 // The SIM language preferences only store a language (e.g. fr = French), not an
3505 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3506 // the SIM and carrier preferences does not include a country we add the country
3507 // determined from the SIM MCC to provide an exact locale.
3508 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003509 if (mccLocale != null) {
3510 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3511 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003512 }
3513
Tony Hill183b2de2015-06-24 14:53:58 +01003514 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003515 return null;
3516 }
3517
3518 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 return mSubscriptionController.getAllSubInfoList(
3522 mPhone.getContext().getOpPackageName());
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
3528 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return mSubscriptionController.getActiveSubscriptionInfoList(
3532 mPhone.getContext().getOpPackageName());
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
3536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003537
Chenjie Yu1ba97252018-01-11 18:16:20 -08003538 private final ModemActivityInfo mLastModemActivityInfo =
3539 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3540
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003541 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003542 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3543 * representing the state of the modem.
3544 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003545 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3546 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003547 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003548 */
3549 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003550 public void requestModemActivityInfo(ResultReceiver result) {
3551 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003552 ModemActivityInfo ret = null;
3553 synchronized (mLastModemActivityInfo) {
3554 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3555 null);
3556 if (info != null) {
3557 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3558 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3559 mergedTxTimeMs[i] =
3560 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3561 }
3562 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3563 mLastModemActivityInfo.setSleepTimeMillis(
3564 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3565 mLastModemActivityInfo.setIdleTimeMillis(
3566 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3567 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3568 mLastModemActivityInfo.setRxTimeMillis(
3569 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3570 mLastModemActivityInfo.setEnergyUsed(
3571 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3572 }
3573 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3574 mLastModemActivityInfo.getSleepTimeMillis(),
3575 mLastModemActivityInfo.getIdleTimeMillis(),
3576 mLastModemActivityInfo.getTxTimeMillis(),
3577 mLastModemActivityInfo.getRxTimeMillis(),
3578 mLastModemActivityInfo.getEnergyUsed());
3579 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003580 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003581 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003582 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003583 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003584
3585 /**
3586 * {@hide}
3587 * Returns the service state information on specified subscription.
3588 */
3589 @Override
3590 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3591
3592 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3593 return null;
3594 }
3595
3596 final Phone phone = getPhone(subId);
3597 if (phone == null) {
3598 return null;
3599 }
3600
3601 return phone.getServiceState();
3602 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003603
3604 /**
3605 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3606 *
3607 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3608 * voicemail ringtone.
3609 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3610 * PhoneAccount.
3611 */
3612 @Override
3613 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003615 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003616 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003617 }
3618
fionaxu7ed723d2017-05-30 18:58:54 -07003619 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003620 }
3621
3622 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003623 * Sets the per-account voicemail ringtone.
3624 *
3625 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3626 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3627 *
3628 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3629 * voicemail ringtone.
3630 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3631 * PhoneAccount.
3632 */
3633 @Override
3634 public void setVoicemailRingtoneUri(String callingPackage,
3635 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3636 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3637 if (!TextUtils.equals(callingPackage,
3638 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3639 enforceModifyPermissionOrCarrierPrivilege(
3640 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3641 }
3642 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3643 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003644 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003645 }
fionaxu7ed723d2017-05-30 18:58:54 -07003646 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003647 }
3648
3649 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003650 * Returns whether vibration is set for voicemail notification in Phone settings.
3651 *
3652 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3653 * voicemail vibration setting.
3654 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3655 */
3656 @Override
3657 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003658 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003659 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003660 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003661 }
3662
fionaxu7ed723d2017-05-30 18:58:54 -07003663 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003664 }
3665
Youhan Wange64578a2016-05-02 15:32:42 -07003666 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003667 * Sets the per-account voicemail vibration.
3668 *
3669 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3670 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3671 *
3672 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3673 * voicemail vibration setting.
3674 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3675 * specific PhoneAccount.
3676 */
3677 @Override
3678 public void setVoicemailVibrationEnabled(String callingPackage,
3679 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3681 if (!TextUtils.equals(callingPackage,
3682 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3683 enforceModifyPermissionOrCarrierPrivilege(
3684 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3685 }
3686
3687 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3688 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003689 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003690 }
fionaxu7ed723d2017-05-30 18:58:54 -07003691 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003692 }
3693
3694 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003695 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3696 *
3697 * @throws SecurityException if the caller does not have the required permission
3698 */
3699 private void enforceReadPrivilegedPermission() {
3700 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3701 null);
3702 }
3703
3704 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003705 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3706 * permission.
3707 *
3708 * @throws SecurityException if the caller does not have the required permission
3709 */
3710 private void enforceSendSmsPermission() {
3711 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3712 }
3713
3714 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003715 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003716 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003717 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003718 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003719 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003720 ComponentName componentName =
3721 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3722 if(componentName == null) {
3723 throw new SecurityException("Caller not current active visual voicemail package[null]");
3724 }
3725 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003726 if (!callingPackage.equals(vvmPackage)) {
3727 throw new SecurityException("Caller not current active visual voicemail package[" +
3728 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003729 }
3730 }
3731
3732 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003733 * Return the application ID for the app type.
3734 *
3735 * @param subId the subscription ID that this request applies to.
3736 * @param appType the uicc app type.
3737 * @return Application ID for specificied app type, or null if no uicc.
3738 */
3739 @Override
3740 public String getAidForAppType(int subId, int appType) {
3741 enforceReadPrivilegedPermission();
3742 Phone phone = getPhone(subId);
3743 if (phone == null) {
3744 return null;
3745 }
3746 String aid = null;
3747 try {
3748 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3749 .getApplicationByType(appType).getAid();
3750 } catch (Exception e) {
3751 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3752 }
3753 return aid;
3754 }
3755
Youhan Wang4001d252016-05-11 10:29:41 -07003756 /**
3757 * Return the Electronic Serial Number.
3758 *
3759 * @param subId the subscription ID that this request applies to.
3760 * @return ESN or null if error.
3761 */
3762 @Override
3763 public String getEsn(int subId) {
3764 enforceReadPrivilegedPermission();
3765 Phone phone = getPhone(subId);
3766 if (phone == null) {
3767 return null;
3768 }
3769 String esn = null;
3770 try {
3771 esn = phone.getEsn();
3772 } catch (Exception e) {
3773 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3774 }
3775 return esn;
3776 }
3777
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003778 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003779 * Return the Preferred Roaming List Version.
3780 *
3781 * @param subId the subscription ID that this request applies to.
3782 * @return PRLVersion or null if error.
3783 */
3784 @Override
3785 public String getCdmaPrlVersion(int subId) {
3786 enforceReadPrivilegedPermission();
3787 Phone phone = getPhone(subId);
3788 if (phone == null) {
3789 return null;
3790 }
3791 String cdmaPrlVersion = null;
3792 try {
3793 cdmaPrlVersion = phone.getCdmaPrlVersion();
3794 } catch (Exception e) {
3795 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3796 }
3797 return cdmaPrlVersion;
3798 }
3799
3800 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003801 * Get snapshot of Telephony histograms
3802 * @return List of Telephony histograms
3803 * @hide
3804 */
3805 @Override
3806 public List<TelephonyHistogram> getTelephonyHistograms() {
3807 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3808 return RIL.getTelephonyRILTimingHistograms();
3809 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003810
3811 /**
3812 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003813 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003814 * Require system privileges. In the future we may add this to carrier APIs.
3815 *
3816 * @return The number of carriers set successfully, should match length of carriers
3817 */
3818 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003819 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003820 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003821
Meng Wang9b7c4e92017-02-17 11:41:27 -08003822 if (carriers == null) {
3823 throw new NullPointerException("carriers cannot be null");
3824 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003825
3826 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003827 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3828 return retVal[0];
3829 }
3830
3831 /**
3832 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003833 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003834 * Require system privileges. In the future we may add this to carrier APIs.
3835 *
3836 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3837 * means all carriers are allowed.
3838 */
3839 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003840 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003841 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003842 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003843 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3844 }
3845
fionaxu59545b42016-05-25 15:53:37 -07003846 /**
3847 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3848 * @param subId the subscription ID that this action applies to.
3849 * @param enabled control enable or disable metered apns.
3850 * {@hide}
3851 */
3852 @Override
3853 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3854 enforceModifyPermission();
3855 final Phone phone = getPhone(subId);
3856 if (phone == null) {
3857 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3858 return;
3859 }
3860 try {
3861 phone.carrierActionSetMeteredApnsEnabled(enabled);
3862 } catch (Exception e) {
3863 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3864 }
3865 }
3866
3867 /**
3868 * Action set from carrier signalling broadcast receivers to enable/disable radio
3869 * @param subId the subscription ID that this action applies to.
3870 * @param enabled control enable or disable radio.
3871 * {@hide}
3872 */
3873 @Override
3874 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3875 enforceModifyPermission();
3876 final Phone phone = getPhone(subId);
3877 if (phone == null) {
3878 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3879 return;
3880 }
3881 try {
3882 phone.carrierActionSetRadioEnabled(enabled);
3883 } catch (Exception e) {
3884 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3885 }
3886 }
3887
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003888 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003889 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3890 * network status based on which carrier apps could apply actions accordingly,
3891 * enable/disable default url handler for example.
3892 *
3893 * @param subId the subscription ID that this action applies to.
3894 * @param report control start/stop reporting the default network status.
3895 * {@hide}
3896 */
3897 @Override
3898 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3899 enforceModifyPermission();
3900 final Phone phone = getPhone(subId);
3901 if (phone == null) {
3902 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3903 return;
3904 }
3905 try {
3906 phone.carrierActionReportDefaultNetworkStatus(report);
3907 } catch (Exception e) {
3908 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3909 }
3910 }
3911
3912 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003913 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3914 * bug report is being generated.
3915 */
3916 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003917 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003918 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3919 != PackageManager.PERMISSION_GRANTED) {
3920 writer.println("Permission Denial: can't dump Phone from pid="
3921 + Binder.getCallingPid()
3922 + ", uid=" + Binder.getCallingUid()
3923 + "without permission "
3924 + android.Manifest.permission.DUMP);
3925 return;
3926 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003927 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003928 }
Jack Yueb89b242016-06-22 13:27:47 -07003929
3930 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003931 * Get aggregated video call data usage since boot.
3932 *
3933 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3934 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003935 * {@hide}
3936 */
3937 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003938 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003939 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3940 null);
3941
Jack Yu84291ec2017-05-26 16:07:50 -07003942 // NetworkStatsService keeps tracking the active network interface and identity. It
3943 // records the delta with the corresponding network identity. We just return the total video
3944 // call data usage snapshot since boot.
3945 Phone phone = getPhone(subId);
3946 if (phone != null) {
3947 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003948 }
Jack Yu84291ec2017-05-26 16:07:50 -07003949 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003950 }
Jack Yu75ab2952016-07-08 14:29:33 -07003951
3952 /**
3953 * Policy control of data connection. Usually used when data limit is passed.
3954 * @param enabled True if enabling the data, otherwise disabling.
3955 * @param subId Subscription index
3956 * {@hide}
3957 */
3958 @Override
3959 public void setPolicyDataEnabled(boolean enabled, int subId) {
3960 enforceModifyPermission();
3961 Phone phone = getPhone(subId);
3962 if (phone != null) {
3963 phone.setPolicyDataEnabled(enabled);
3964 }
3965 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003966
3967 /**
3968 * Get Client request stats
3969 * @return List of Client Request Stats
3970 * @hide
3971 */
3972 @Override
3973 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3974 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3975 return null;
3976 }
3977
3978 Phone phone = getPhone(subId);
3979 if (phone != null) {
3980 return phone.getClientRequestStats();
3981 }
3982
3983 return null;
3984 }
3985
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003986 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003987 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003988 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003989 }
Jack Yueb4124c2017-02-16 15:32:43 -08003990
3991 /**
Grace Chen70990072017-03-24 17:21:30 -07003992 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003993 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003994 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003995 * @param state State of SIM (power down, power up, pass through)
3996 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3997 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3998 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003999 *
4000 **/
4001 @Override
Grace Chen70990072017-03-24 17:21:30 -07004002 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004003 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004004 Phone phone = PhoneFactory.getPhone(slotIndex);
4005
Jack Yueb4124c2017-02-16 15:32:43 -08004006 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004007 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004008 }
4009 }
Shuo Qiandd210312017-04-12 22:11:33 +00004010
Tyler Gunn65d45c22017-06-05 11:22:26 -07004011 private boolean isUssdApiAllowed(int subId) {
4012 CarrierConfigManager configManager =
4013 (CarrierConfigManager) mPhone.getContext().getSystemService(
4014 Context.CARRIER_CONFIG_SERVICE);
4015 if (configManager == null) {
4016 return false;
4017 }
4018 PersistableBundle pb = configManager.getConfigForSubId(subId);
4019 if (pb == null) {
4020 return false;
4021 }
4022 return pb.getBoolean(
4023 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4024 }
4025
Shuo Qiandd210312017-04-12 22:11:33 +00004026 /**
4027 * Check if phone is in emergency callback mode
4028 * @return true if phone is in emergency callback mode
4029 * @param subId sub id
4030 */
goneil9c5f4872017-12-05 14:07:56 -08004031 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004032 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004033 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004034 final Phone phone = getPhone(subId);
4035 if (phone != null) {
4036 return phone.isInEcm();
4037 } else {
4038 return false;
4039 }
4040 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004041
4042 /**
4043 * Get the current signal strength information for the given subscription.
4044 * Because this information is not updated when the device is in a low power state
4045 * it should not be relied-upon to be current.
4046 * @param subId Subscription index
4047 * @return the most recent cached signal strength info from the modem
4048 */
4049 @Override
4050 public SignalStrength getSignalStrength(int subId) {
4051 Phone p = getPhone(subId);
4052 if (p == null) {
4053 return null;
4054 }
4055
4056 return p.getSignalStrength();
4057 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004058
4059 @Override
4060 public UiccSlotInfo[] getUiccSlotsInfo() {
4061 enforceReadPrivilegedPermission();
4062
4063 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4064 if (slots == null) return null;
4065 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4066 for (int i = 0; i < slots.length; i++) {
4067 UiccSlot slot = slots[i];
4068
4069 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4070
4071 int cardState = 0;
4072 switch (slot.getCardState()) {
4073 case CARDSTATE_ABSENT:
4074 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4075 break;
4076 case CARDSTATE_PRESENT:
4077 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4078 break;
4079 case CARDSTATE_ERROR:
4080 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4081 break;
4082 case CARDSTATE_RESTRICTED:
4083 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4084 break;
4085 default:
4086 break;
4087
4088 }
4089
Qingxi Li795c5882018-01-31 13:43:27 -08004090 infos[i] = new UiccSlotInfo(
4091 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004092 }
4093 return infos;
4094 }
4095
4096 @Override
4097 public boolean switchSlots(int[] physicalSlots) {
4098 enforceModifyPermission();
4099 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004101}