blob: c1af4612f6539fd2ff58de210d5a5cd97a2c275c [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080079import android.util.EventLog;
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) {
Tyler Gunn67073572018-02-14 14:19:42 -08001188 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1189 != PackageManager.PERMISSION_GRANTED) {
1190 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1191 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1192 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1193 }
Stuart Scott584921c2015-01-15 17:10:34 -08001194 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 }
1196
1197 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001198 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001199 }
1200
Wink Savilleb564aae2014-10-23 10:18:09 -07001201 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 if (DBG) log("answerRingingCall...");
1203 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1204 // but that can probably wait till the big TelephonyManager API overhaul.
1205 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1206 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001207 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 }
1209
1210 /**
1211 * Make the actual telephony calls to implement answerRingingCall().
1212 * This should only be called from the main thread of the Phone app.
1213 * @see #answerRingingCall
1214 *
1215 * TODO: it would be nice to return true if we answered the call, or
1216 * false if there wasn't actually a ringing incoming call, or some
1217 * other error occurred. (In other words, pass back the return value
1218 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1219 * But that would require calling this method via sendRequest() rather
1220 * than sendRequestAsync(), and right now we don't actually *need* that
1221 * return value, so let's just return void for now.
1222 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001223 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001224 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001226 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1227 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 if (hasActiveCall && hasHoldingCall) {
1229 // Both lines are in use!
1230 // TODO: provide a flag to let the caller specify what
1231 // policy to use if both lines are in use. (The current
1232 // behavior is hardwired to "answer incoming, end ongoing",
1233 // which is how the CALL button is specced to behave.)
1234 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1235 return;
1236 } else {
1237 // answerCall() will automatically hold the current active
1238 // call, if there is one.
1239 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1240 return;
1241 }
1242 } else {
1243 // No call was ringing.
1244 return;
1245 }
1246 }
1247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001249 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001251 public void silenceRinger() {
1252 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isOffhook(String callingPackage) {
1257 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001258 }
1259
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 @Override
1261 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1262 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1263 return false;
1264 }
1265
Sanket Padawe356d7632015-06-22 14:03:32 -07001266 final Phone phone = getPhone(subId);
1267 if (phone != null) {
1268 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1269 } else {
1270 return false;
1271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isRinging(String callingPackage) {
1276 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1281 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1282 return false;
1283 }
1284
Sanket Padawe356d7632015-06-22 14:03:32 -07001285 final Phone phone = getPhone(subId);
1286 if (phone != null) {
1287 return (phone.getState() == PhoneConstants.State.RINGING);
1288 } else {
1289 return false;
1290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isIdle(String callingPackage) {
1295 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001296 }
1297
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001298 @Override
1299 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1300 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1301 return false;
1302 }
1303
Sanket Padawe356d7632015-06-22 14:03:32 -07001304 final Phone phone = getPhone(subId);
1305 if (phone != null) {
1306 return (phone.getState() == PhoneConstants.State.IDLE);
1307 } else {
1308 return false;
1309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1319 }
1320
1321 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001322 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001323 }
1324
Wink Savilleb564aae2014-10-23 10:18:09 -07001325 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001327 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1328 }
1329
1330 /** {@hide} */
1331 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001337 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 checkSimPin.start();
1339 return checkSimPin.unlockSim(null, pin);
1340 }
1341
Wink Saville9de0f752013-10-22 19:04:03 -07001342 /** {@hide} */
1343 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPuk.start();
1351 return checkSimPuk.unlockSim(puk, pin);
1352 }
1353
1354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 * a synchronous one.
1357 */
1358 private static class UnlockSim extends Thread {
1359
1360 private final IccCard mSimCard;
1361
1362 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001363 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1364 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365
1366 // For replies from SimCard interface
1367 private Handler mHandler;
1368
1369 // For async handler to identify request type
1370 private static final int SUPPLY_PIN_COMPLETE = 100;
1371
1372 public UnlockSim(IccCard simCard) {
1373 mSimCard = simCard;
1374 }
1375
1376 @Override
1377 public void run() {
1378 Looper.prepare();
1379 synchronized (UnlockSim.this) {
1380 mHandler = new Handler() {
1381 @Override
1382 public void handleMessage(Message msg) {
1383 AsyncResult ar = (AsyncResult) msg.obj;
1384 switch (msg.what) {
1385 case SUPPLY_PIN_COMPLETE:
1386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001388 mRetryCount = msg.arg1;
1389 if (ar.exception != null) {
1390 if (ar.exception instanceof CommandException &&
1391 ((CommandException)(ar.exception)).getCommandError()
1392 == CommandException.Error.PASSWORD_INCORRECT) {
1393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1394 } else {
1395 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1396 }
1397 } else {
1398 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 mDone = true;
1401 UnlockSim.this.notifyAll();
1402 }
1403 break;
1404 }
1405 }
1406 };
1407 UnlockSim.this.notifyAll();
1408 }
1409 Looper.loop();
1410 }
1411
1412 /*
1413 * Use PIN or PUK to unlock SIM card
1414 *
1415 * If PUK is null, unlock SIM card with PIN
1416 *
1417 * If PUK is not null, unlock SIM card with PUK and set PIN code
1418 */
Wink Saville9de0f752013-10-22 19:04:03 -07001419 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 while (mHandler == null) {
1422 try {
1423 wait();
1424 } catch (InterruptedException e) {
1425 Thread.currentThread().interrupt();
1426 }
1427 }
1428 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1429
1430 if (puk == null) {
1431 mSimCard.supplyPin(pin, callback);
1432 } else {
1433 mSimCard.supplyPuk(puk, pin, callback);
1434 }
1435
1436 while (!mDone) {
1437 try {
1438 Log.d(LOG_TAG, "wait for done");
1439 wait();
1440 } catch (InterruptedException e) {
1441 // Restore the interrupted status
1442 Thread.currentThread().interrupt();
1443 }
1444 }
1445 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001446 int[] resultArray = new int[2];
1447 resultArray[0] = mResult;
1448 resultArray[1] = mRetryCount;
1449 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455
1456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 // No permission check needed here: this call is harmless, and it's
1460 // needed for the ServiceState.requestStateUpdate() call (which is
1461 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 phone.updateServiceLocation();
1465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOn(String callingPackage) {
1470 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001473 @Override
1474 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1475 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1476 return false;
1477 }
1478 return isRadioOnForSubscriber(subId);
1479 }
1480
1481 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001482 final Phone phone = getPhone(subId);
1483 if (phone != null) {
1484 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1485 } else {
1486 return false;
1487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
1489
1490 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
Wink Saville36469e72014-06-11 15:17:00 -07001494
Wink Savilleb564aae2014-10-23 10:18:09 -07001495 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001497 final Phone phone = getPhone(subId);
1498 if (phone != null) {
1499 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1500 }
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
1503 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001505 }
1506
Wink Savilleb564aae2014-10-23 10:18:09 -07001507 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001508 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001509 final Phone phone = getPhone(subId);
1510 if (phone == null) {
1511 return false;
1512 }
1513 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001514 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 }
1517 return true;
1518 }
Wink Saville36469e72014-06-11 15:17:00 -07001519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001520 public boolean needMobileRadioShutdown() {
1521 /*
1522 * If any of the Radios are available, it will need to be
1523 * shutdown. So return true if any Radio is available.
1524 */
1525 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1526 Phone phone = PhoneFactory.getPhone(i);
1527 if (phone != null && phone.isRadioAvailable()) return true;
1528 }
1529 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1530 return false;
1531 }
1532
1533 public void shutdownMobileRadios() {
1534 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1535 logv("Shutting down Phone " + i);
1536 shutdownRadioUsingPhoneId(i);
1537 }
1538 }
1539
1540 private void shutdownRadioUsingPhoneId(int phoneId) {
1541 enforceModifyPermission();
1542 Phone phone = PhoneFactory.getPhone(phoneId);
1543 if (phone != null && phone.isRadioAvailable()) {
1544 phone.shutdownRadio();
1545 }
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001549 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001550 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1551 if (defaultPhone != null) {
1552 defaultPhone.setRadioPower(turnOn);
1553 return true;
1554 } else {
1555 loge("There's no default phone.");
1556 return false;
1557 }
Wink Saville36469e72014-06-11 15:17:00 -07001558 }
1559
Wink Savilleb564aae2014-10-23 10:18:09 -07001560 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 final Phone phone = getPhone(subId);
1563 if (phone != null) {
1564 phone.setRadioPower(turnOn);
1565 return true;
1566 } else {
1567 return false;
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Wink Saville36469e72014-06-11 15:17:00 -07001571 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 public boolean enableDataConnectivity() {
1574 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001575 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001578 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 return true;
1580 } else {
1581 return false;
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Wink Saville36469e72014-06-11 15:17:00 -07001585 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 public boolean disableDataConnectivity() {
1588 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001589 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001592 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 return true;
1594 } else {
1595 return false;
1596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001600 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001603 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 } else {
1605 return false;
1606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 }
1608
1609 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
pkanwarae03a6b2016-11-06 20:37:09 -08001613 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001614 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1616 return;
1617 }
1618 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1619 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1620 };
1621
Wink Savilleb564aae2014-10-23 10:18:09 -07001622 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1625 return false;
1626 }
Wink Saville36469e72014-06-11 15:17:00 -07001627 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 }
1629
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001631 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001632 }
1633
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001634 public int getCallStateForSlot(int slotIndex) {
1635 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001636 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001637 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001642 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001644 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001646 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001652 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 if (phone != null) {
1654 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1655 } else {
1656 return TelephonyManager.DATA_ACTIVITY_NONE;
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001661 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001662 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001663 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001664 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001667 if (DBG_LOC) log("getCellLocation: is active user");
1668 Bundle data = new Bundle();
1669 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1670 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 return null;
1672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001675 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1676 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001677 }
1678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001680 public String getNetworkCountryIsoForPhone(int phoneId) {
1681 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1682 // registered cell info, so return a NULL country instead.
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1686 if (TelephonyManager.NETWORK_TYPE_IWLAN
1687 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1688 return "";
1689 }
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
1693 return TelephonyManager.getTelephonyProperty(
1694 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1695 }
1696
1697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001699 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001700 }
1701
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 mApp.enforceCallingOrSelfPermission(
1705 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 final Phone phone = getPhone(subId);
1707 if (phone != null) {
1708 phone.enableLocationUpdates();
1709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
1712 @Override
1713 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mApp.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 phone.disableLocationUpdates();
1724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 @Override
1728 @SuppressWarnings("unchecked")
1729 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001730 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001731 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001732 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
1735 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1736 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1737 return null;
1738 }
Svetoslav64fad262015-04-14 14:35:21 -07001739
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001740 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 try {
1746 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1747 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1748 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1749 } catch (RuntimeException e) {
1750 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
1754
1755
1756 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001757 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001759 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001760 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001764 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1766 for (Phone phone : PhoneFactory.getPhones()) {
1767 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1768 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001775 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001776 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001777 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001781 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001782 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1783 return null;
1784 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001785 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001786 return phone == null ? null : phone.getImei();
1787 }
1788
1789 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001790 public String getMeidForSlot(int slotIndex, String callingPackage) {
1791 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1792 return null;
1793 }
1794 Phone phone = PhoneFactory.getPhone(slotIndex);
1795 return phone == null ? null : phone.getMeid();
1796 }
1797
1798 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1801 return null;
1802 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001803 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 return phone == null ? null : phone.getDeviceSvn();
1805 }
1806
fionaxu43304da2017-11-27 22:51:16 -08001807 @Override
1808 public int getSubscriptionCarrierId(int subId) {
1809 final Phone phone = getPhone(subId);
1810 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1811 }
1812
1813 @Override
1814 public String getSubscriptionCarrierName(int subId) {
1815 final Phone phone = getPhone(subId);
1816 return phone == null ? null : phone.getCarrierName();
1817 }
1818
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 //
1820 // Internal helper methods.
1821 //
1822
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001823 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1825 *
1826 * @throws SecurityException if the caller does not have the required permission
1827 */
1828 private void enforceModifyPermission() {
1829 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1830 }
1831
1832 /**
Junda Liua2e36012014-07-09 18:30:01 -07001833 * Make sure either system app or the caller has carrier privilege.
1834 *
1835 * @throws SecurityException if the caller does not have the required permission/privilege
1836 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001837 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001838 int permission = mApp.checkCallingOrSelfPermission(
1839 android.Manifest.permission.MODIFY_PHONE_STATE);
1840 if (permission == PackageManager.PERMISSION_GRANTED) {
1841 return;
1842 }
1843
1844 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001845 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001846 }
1847
1848 /**
1849 * Make sure the caller has carrier privilege.
1850 *
1851 * @throws SecurityException if the caller does not have the required permission
1852 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001853 private void enforceCarrierPrivilege(int subId) {
1854 if (getCarrierPrivilegeStatus(subId) !=
1855 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001856 loge("No Carrier Privilege.");
1857 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001858 }
1859 }
1860
1861 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 * Make sure the caller has the CALL_PHONE permission.
1863 *
1864 * @throws SecurityException if the caller does not have the required permission
1865 */
1866 private void enforceCallPermission() {
1867 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1868 }
1869
Stuart Scott8eef64f2015-04-08 15:13:54 -07001870 private void enforceConnectivityInternalPermission() {
1871 mApp.enforceCallingOrSelfPermission(
1872 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1873 "ConnectivityService");
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 private String createTelUrl(String number) {
1877 if (TextUtils.isEmpty(number)) {
1878 return null;
1879 }
1880
Jake Hambye994d462014-02-03 13:10:13 -08001881 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
Ihab Awadf9e92732013-12-05 18:02:52 -08001884 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1886 }
1887
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 private static void logv(String msg) {
1889 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1890 }
1891
Ihab Awadf9e92732013-12-05 18:02:52 -08001892 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1894 }
1895
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001898 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001902 public int getActivePhoneTypeForSlot(int slotIndex) {
1903 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 if (phone == null) {
1905 return PhoneConstants.PHONE_TYPE_NONE;
1906 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001907 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 /**
1912 * Returns the CDMA ERI icon index to display
1913 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 @Override
1915 public int getCdmaEriIconIndex(String callingPackage) {
1916 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001917 }
1918
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001920 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1921 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1922 return -1;
1923 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 final Phone phone = getPhone(subId);
1925 if (phone != null) {
1926 return phone.getCdmaEriIconIndex();
1927 } else {
1928 return -1;
1929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
1932 /**
1933 * Returns the CDMA ERI icon mode,
1934 * 0 - ON
1935 * 1 - FLASHING
1936 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 @Override
1938 public int getCdmaEriIconMode(String callingPackage) {
1939 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001940 }
1941
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1944 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1945 return -1;
1946 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 final Phone phone = getPhone(subId);
1948 if (phone != null) {
1949 return phone.getCdmaEriIconMode();
1950 } else {
1951 return -1;
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
1955 /**
1956 * Returns the CDMA ERI text,
1957 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 @Override
1959 public String getCdmaEriText(String callingPackage) {
1960 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001961 }
1962
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001964 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1965 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1966 return null;
1967 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 final Phone phone = getPhone(subId);
1969 if (phone != null) {
1970 return phone.getCdmaEriText();
1971 } else {
1972 return null;
1973 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
1976 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001977 * Returns the CDMA MDN.
1978 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001981 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 final Phone phone = getPhone(subId);
1983 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1984 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 } else {
1986 return null;
1987 }
1988 }
1989
1990 /**
1991 * Returns the CDMA MIN.
1992 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001994 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001995 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 final Phone phone = getPhone(subId);
1997 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1998 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001999 } else {
2000 return null;
2001 }
2002 }
2003
2004 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 * Returns true if CDMA provisioning needs to run.
2006 */
2007 public boolean needsOtaServiceProvisioning() {
2008 return mPhone.needsOtaServiceProvisioning();
2009 }
2010
2011 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002012 * Sets the voice mail number of a given subId.
2013 */
2014 @Override
2015 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002016 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002017 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2018 new Pair<String, String>(alphaTag, number), new Integer(subId));
2019 return success;
2020 }
2021
Ta-wei Yen87c49842016-05-13 21:19:52 -07002022 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002023 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2025 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2026 if (!TextUtils.equals(callingPackage, systemDialer)) {
2027 throw new SecurityException("caller must be system dialer");
2028 }
2029 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2030 if (phoneAccountHandle == null){
2031 return null;
2032 }
2033 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2034 }
2035
2036 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002037 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2039 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2040 return null;
2041 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002042 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2043 }
2044
2045 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002046 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2047 VisualVoicemailSmsFilterSettings settings) {
2048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002050 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2051 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 }
2053
2054 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002055 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 }
2060
2061 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002062 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2063 String callingPackage, int subId) {
2064 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002065 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002066 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002067 }
2068
2069 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002070 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002071 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002072 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002073 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2074 }
2075
2076 @Override
2077 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2078 String number, int port, String text, PendingIntent sentIntent) {
2079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002080 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002081 enforceSendSmsPermission();
2082 // Make the calls as the phone process.
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2086 if (port == 0) {
2087 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2088 sentIntent, null, false);
2089 } else {
2090 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2091 smsManager.sendDataMessageWithSelfPermissions(number, null,
2092 (short) port, data, sentIntent, null);
2093 }
2094 } finally {
2095 Binder.restoreCallingIdentity(identity);
2096 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002098 /**
fionaxu0152e512016-11-14 13:36:14 -08002099 * Sets the voice activation state of a given subId.
2100 */
2101 @Override
2102 public void setVoiceActivationState(int subId, int activationState) {
2103 enforceModifyPermissionOrCarrierPrivilege(subId);
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.setVoiceActivationState(activationState);
2107 } else {
2108 loge("setVoiceActivationState fails with invalid subId: " + subId);
2109 }
2110 }
2111
2112 /**
2113 * Sets the data activation state of a given subId.
2114 */
2115 @Override
2116 public void setDataActivationState(int subId, int activationState) {
2117 enforceModifyPermissionOrCarrierPrivilege(subId);
2118 final Phone phone = getPhone(subId);
2119 if (phone != null) {
2120 phone.setDataActivationState(activationState);
2121 } else {
2122 loge("setVoiceActivationState fails with invalid subId: " + subId);
2123 }
2124 }
2125
2126 /**
2127 * Returns the voice activation state of a given subId.
2128 */
2129 @Override
2130 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002131 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002132 final Phone phone = getPhone(subId);
2133 if (phone != null) {
2134 return phone.getVoiceActivationState();
2135 } else {
2136 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2137 }
2138 }
2139
2140 /**
2141 * Returns the data activation state of a given subId.
2142 */
2143 @Override
2144 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002145 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002146 final Phone phone = getPhone(subId);
2147 if (phone != null) {
2148 return phone.getDataActivationState();
2149 } else {
2150 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2151 }
2152 }
2153
2154 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 * Returns the unread count of voicemails
2156 */
2157 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002158 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002159 }
2160
2161 /**
2162 * Returns the unread count of voicemails for a subId
2163 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002165 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 final Phone phone = getPhone(subId);
2167 if (phone != null) {
2168 return phone.getVoiceMessageCount();
2169 } else {
2170 return 0;
2171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
2174 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002175 * returns true, if the device is in a state where both voice and data
2176 * are supported simultaneously. This can change based on location or network condition.
2177 */
2178 @Override
2179 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2180 final Phone phone = getPhone(subId);
2181 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2182 }
2183
2184 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002185 * Send the dialer code if called from the current default dialer or the caller has
2186 * carrier privilege.
2187 * @param inputCode The dialer code to send
2188 */
2189 @Override
2190 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2192 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2193 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2194 enforceCarrierPrivilege(getDefaultSubscription());
2195 }
2196 mPhone.sendDialerSpecialCode(inputCode);
2197 }
2198
2199 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002200 * Returns the data network type.
2201 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 *
2203 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2204 */
2205 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002206 public int getNetworkType() {
2207 final Phone phone = getPhone(getDefaultSubscription());
2208 if (phone != null) {
2209 return phone.getServiceState().getDataNetworkType();
2210 } else {
2211 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2212 }
Wink Saville36469e72014-06-11 15:17:00 -07002213 }
2214
2215 /**
2216 * Returns the network type for a subId
2217 */
2218 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002219 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2220 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2221 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2222 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002223
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 return phone.getServiceState().getDataNetworkType();
2227 } else {
2228 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
2232 /**
2233 * Returns the data network type
2234 */
2235 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 public int getDataNetworkType(String callingPackage) {
2237 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
2240 /**
2241 * Returns the data network type for a subId
2242 */
2243 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2245 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2246 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2247 }
2248
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 final Phone phone = getPhone(subId);
2250 if (phone != null) {
2251 return phone.getServiceState().getDataNetworkType();
2252 } else {
2253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
2256
2257 /**
Wink Saville36469e72014-06-11 15:17:00 -07002258 * Returns the Voice network type for a subId
2259 */
2260 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002261 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2262 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2264 }
2265
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 final Phone phone = getPhone(subId);
2267 if (phone != null) {
2268 return phone.getServiceState().getVoiceNetworkType();
2269 } else {
2270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
2274 /**
2275 * @return true if a ICC card is present
2276 */
2277 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002278 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002279 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2280 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002281 }
2282
2283 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002284 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002285 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002287 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2288 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002289 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002291 } else {
2292 return false;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
2297 * Return if the current radio is LTE on CDMA. This
2298 * is a tri-state return value as for a period of time
2299 * the mode may be unknown.
2300 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002303 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002305 @Override
2306 public int getLteOnCdmaMode(String callingPackage) {
2307 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002311 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2312 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2313 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2314 }
2315
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 final Phone phone = getPhone(subId);
2317 if (phone == null) {
2318 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2319 } else {
2320 return phone.getLteOnCdmaMode();
2321 }
Wink Saville36469e72014-06-11 15:17:00 -07002322 }
2323
2324 public void setPhone(Phone phone) {
2325 mPhone = phone;
2326 }
2327
2328 /**
2329 * {@hide}
2330 * Returns Default subId, 0 in the case of single standby.
2331 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002333 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Shishir Agrawala9f32182016-04-12 12:00:16 -07002336 private int getSlotForDefaultSubscription() {
2337 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2338 }
2339
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002341 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002343
2344 /**
2345 * @see android.telephony.TelephonyManager.WifiCallingChoices
2346 */
2347 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002348 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2349 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002350 }
2351
2352 /**
2353 * @see android.telephony.TelephonyManager.WifiCallingChoices
2354 */
2355 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002356 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2357 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2358 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002359 }
2360
Sailesh Nepald1e68152013-12-12 19:08:02 -08002361 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002362 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002363 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002364 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002365
Shishir Agrawal566b7612013-10-28 14:41:00 -07002366 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002367 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2368 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002369 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002370
Derek Tan740e1672017-06-27 14:56:27 -07002371 if (TextUtils.equals(ISDR_AID, aid)) {
2372 // Only allows LPA to open logical channel to ISD-R.
2373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2374 ComponentInfo bestComponent =
2375 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2376 if (bestComponent == null
2377 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2378 loge("The calling package is not allowed to access ISD-R.");
2379 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2380 }
2381 }
2382
2383 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002384 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002385 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002386 if (DBG) log("iccOpenLogicalChannel: " + response);
2387 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002388 }
2389
2390 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002391 public boolean iccCloseLogicalChannel(int subId, int channel) {
2392 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002393
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002394 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 if (channel < 0) {
2396 return false;
2397 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002398 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002399 if (DBG) log("iccCloseLogicalChannel: " + success);
2400 return success;
2401 }
2402
2403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002405 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407
2408 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2410 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002411 " data=" + data);
2412 }
2413
2414 if (channel < 0) {
2415 return "";
2416 }
2417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002418 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002419 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002420 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2421
Shishir Agrawal566b7612013-10-28 14:41:00 -07002422 // Append the returned status code to the end of the response payload.
2423 String s = Integer.toHexString(
2424 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002425 if (response.payload != null) {
2426 s = IccUtils.bytesToHexString(response.payload) + s;
2427 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428 return s;
2429 }
Jake Hambye994d462014-02-03 13:10:13 -08002430
Evan Charltonc66da362014-05-16 14:06:40 -07002431 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002432 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2433 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002435
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002436 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2437 && TextUtils.equals(ISDR_AID, data)) {
2438 // Only allows LPA to select ISD-R.
2439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2440 ComponentInfo bestComponent =
2441 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2442 if (bestComponent == null
2443 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2444 loge("The calling package is not allowed to select ISD-R.");
2445 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2446 }
2447 }
2448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002449 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002450 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2451 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002452 }
2453
2454 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002456 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002458 // Append the returned status code to the end of the response payload.
2459 String s = Integer.toHexString(
2460 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002461 if (response.payload != null) {
2462 s = IccUtils.bytesToHexString(response.payload) + s;
2463 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002464 return s;
2465 }
2466
2467 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002468 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002470 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471
2472 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 p1 + " " + p2 + " " + p3 + ":" + filePath);
2475 }
2476
2477 IccIoResult response =
2478 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2480 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481
2482 if (DBG) {
2483 log("Exchange SIM_IO [R]" + response);
2484 }
2485
2486 byte[] result = null;
2487 int length = 2;
2488 if (response.payload != null) {
2489 length = 2 + response.payload.length;
2490 result = new byte[length];
2491 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2492 } else {
2493 result = new byte[length];
2494 }
2495
2496 result[length - 1] = (byte) response.sw2;
2497 result[length - 2] = (byte) response.sw1;
2498 return result;
2499 }
2500
Nathan Haroldb3014052017-01-25 15:57:32 -08002501 /**
2502 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2503 * on a particular subscription
2504 */
2505 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002506 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2507 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002508 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2509 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2510 return null;
2511 }
2512 Object response = sendRequest(
2513 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2514 if (response instanceof String[]) {
2515 return (String[]) response;
2516 }
2517 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2518 return null;
2519 }
2520
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002521 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 public String sendEnvelopeWithStatus(int subId, String content) {
2523 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002524
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002526 if (response.payload == null) {
2527 return "";
2528 }
2529
2530 // Append the returned status code to the end of the response payload.
2531 String s = Integer.toHexString(
2532 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2533 s = IccUtils.bytesToHexString(response.payload) + s;
2534 return s;
2535 }
2536
Jake Hambye994d462014-02-03 13:10:13 -08002537 /**
2538 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2539 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2540 *
2541 * @param itemID the ID of the item to read
2542 * @return the NV item as a String, or null on error.
2543 */
2544 @Override
2545 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002547 if (DBG) log("nvReadItem: item " + itemID);
2548 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2549 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2550 return value;
2551 }
2552
2553 /**
2554 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2555 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2556 *
2557 * @param itemID the ID of the item to read
2558 * @param itemValue the value to write, as a String
2559 * @return true on success; false on any failure
2560 */
2561 @Override
2562 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002563 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002564 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2565 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2566 new Pair<Integer, String>(itemID, itemValue));
2567 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2568 return success;
2569 }
2570
2571 /**
2572 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2573 * Used for device configuration by some CDMA operators.
2574 *
2575 * @param preferredRoamingList byte array containing the new PRL
2576 * @return true on success; false on any failure
2577 */
2578 @Override
2579 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002580 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002581 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2582 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2583 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2584 return success;
2585 }
2586
2587 /**
2588 * Perform the specified type of NV config reset.
2589 * Used for device configuration by some CDMA operators.
2590 *
2591 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2592 * @return true on success; false on any failure
2593 */
2594 @Override
2595 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002596 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002597 if (DBG) log("nvResetConfig: type " + resetType);
2598 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2599 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2600 return success;
2601 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002602
2603 /**
Wink Saville36469e72014-06-11 15:17:00 -07002604 * {@hide}
2605 * Returns Default sim, 0 in the case of single standby.
2606 */
2607 public int getDefaultSim() {
2608 //TODO Need to get it from Telephony Devcontroller
2609 return 0;
2610 }
2611
Svet Ganovb320e182015-04-16 12:30:10 -07002612 public String[] getPcscfAddress(String apnType, String callingPackage) {
2613 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2614 return new String[0];
2615 }
2616
2617
ram87fca6f2014-07-18 18:58:44 +05302618 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002619 }
2620
Brad Ebinger51f743a2017-01-23 13:50:20 -08002621 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002622 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2623 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002625 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002626 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002627 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002628 }
2629
2630 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002631 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2632 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002633 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002634 public void disableIms(int slotId) {
2635 enforceModifyPermission();
2636 PhoneFactory.getImsResolver().disableIms(slotId);
2637 }
2638
2639 /**
2640 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2641 * feature or {@link null} if the service is not available. If the feature is available, the
2642 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2643 */
2644 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002645 IImsServiceFeatureCallback callback) {
2646 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002647 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002648 }
2649
2650 /**
2651 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2652 * feature during emergency calling or {@link null} if the service is not available. If the
2653 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2654 * listener for feature updates.
2655 */
2656 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2657 enforceModifyPermission();
2658 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002659 }
2660
Brad Ebinger5f64b052017-12-14 14:26:15 -08002661 /**
2662 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2663 * specified.
2664 */
2665 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2666 enforceModifyPermission();
2667 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2668 }
2669
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002670 /**
2671 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2672 * specified.
2673 */
2674 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2675 enforceModifyPermission();
2676 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2677 }
2678
Wink Saville36469e72014-06-11 15:17:00 -07002679 public void setImsRegistrationState(boolean registered) {
2680 enforceModifyPermission();
2681 mPhone.setImsRegistrationState(registered);
2682 }
2683
2684 /**
Stuart Scott54788802015-03-30 13:18:01 -07002685 * Set the network selection mode to automatic.
2686 *
2687 */
2688 @Override
2689 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002690 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002691 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2692 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2693 }
2694
2695 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002696 * Set the network selection mode to manual with the selected carrier.
2697 */
2698 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002699 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002700 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002701 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002702 OperatorInfo operator = new OperatorInfo(
2703 /* operatorAlphaLong */ "",
2704 /* operatorAlphaShort */ "",
2705 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002706 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002707 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2708 persistSelection);
2709 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002710 }
2711
2712 /**
2713 * Scans for available networks.
2714 */
2715 @Override
2716 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002717 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002718 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2719 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2720 CMD_PERFORM_NETWORK_SCAN, null, subId);
2721 return result;
2722 }
2723
2724 /**
yinxub1bed742017-04-17 11:45:04 -07002725 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002726 *
yinxub1bed742017-04-17 11:45:04 -07002727 * @param subId id of the subscription
2728 * @param request contains the radio access networks with bands/channels to scan
2729 * @param messenger callback messenger for scan results or errors
2730 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002731 * @return the id of the requested scan which can be used to stop the scan.
2732 */
2733 @Override
2734 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2735 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002736 enforceModifyPermissionOrCarrierPrivilege(subId);
2737 return mNetworkScanRequestTracker.startNetworkScan(
2738 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002739 }
2740
2741 /**
2742 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002743 *
2744 * @param subId id of the subscription
2745 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002746 */
2747 @Override
2748 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002749 enforceModifyPermissionOrCarrierPrivilege(subId);
2750 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002751 }
2752
2753 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002754 * Get the calculated preferred network type.
2755 * Used for debugging incorrect network type.
2756 *
2757 * @return the preferred network type, defined in RILConstants.java.
2758 */
2759 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002760 public int getCalculatedPreferredNetworkType(String callingPackage) {
2761 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2762 return RILConstants.PREFERRED_NETWORK_MODE;
2763 }
2764
Amit Mahajan43330e02014-11-18 11:54:45 -08002765 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002766 }
2767
2768 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002769 * Get the preferred network type.
2770 * Used for device configuration by some CDMA operators.
2771 *
2772 * @return the preferred network type, defined in RILConstants.java.
2773 */
2774 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002775 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002776 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002777 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002778 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002779 int networkType = (result != null ? result[0] : -1);
2780 if (DBG) log("getPreferredNetworkType: " + networkType);
2781 return networkType;
2782 }
2783
2784 /**
2785 * Set the preferred network type.
2786 * Used for device configuration by some CDMA operators.
2787 *
2788 * @param networkType the preferred network type, defined in RILConstants.java.
2789 * @return true on success; false on any failure.
2790 */
2791 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002792 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002793 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002794 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2795 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002796 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002797 if (success) {
2798 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002799 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002800 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002801 return success;
2802 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002803
2804 /**
Junda Liu475951f2014-11-07 16:45:03 -08002805 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2806 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2807 * tethering.
2808 *
2809 * @return 0: Not required. 1: required. 2: Not set.
2810 * @hide
2811 */
2812 @Override
2813 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002814 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002815 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2816 Settings.Global.TETHER_DUN_REQUIRED, 2);
2817 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2818 // config_tether_apndata.
2819 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2820 dunRequired = 1;
2821 }
2822 return dunRequired;
2823 }
2824
2825 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002826 * Set mobile data enabled
2827 * Used by the user through settings etc to turn on/off mobile data
2828 *
2829 * @param enable {@code true} turn turn data on, else {@code false}
2830 */
2831 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002832 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002833 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002834 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002835 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002836 Phone phone = PhoneFactory.getPhone(phoneId);
2837 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002838 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2839 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002840 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002841 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002842 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002843 }
2844
2845 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002846 * Get the user enabled state of Mobile Data.
2847 *
2848 * TODO: remove and use isUserDataEnabled.
2849 * This can't be removed now because some vendor codes
2850 * calls through ITelephony directly while they should
2851 * use TelephonyManager.
2852 *
2853 * @return true on enabled
2854 */
2855 @Override
2856 public boolean getDataEnabled(int subId) {
2857 return isUserDataEnabled(subId);
2858 }
2859
2860 /**
2861 * Get whether mobile data is enabled per user setting.
2862 *
2863 * There are other factors deciding whether mobile data is actually enabled, but they are
2864 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002865 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002866 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002867 *
2868 * @return {@code true} if data is enabled else {@code false}
2869 */
2870 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002871 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002872 try {
2873 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2874 null);
2875 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002876 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002877 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002878 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002879 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002880 Phone phone = PhoneFactory.getPhone(phoneId);
2881 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002882 boolean retVal = phone.isUserDataEnabled();
2883 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002884 return retVal;
2885 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002886 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2887 return false;
2888 }
2889 }
2890
2891 /**
2892 * Get whether mobile data is enabled.
2893 *
2894 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2895 * whether mobile data is actually enabled.
2896 *
2897 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2898 *
2899 * @return {@code true} if data is enabled else {@code false}
2900 */
2901 @Override
2902 public boolean isDataEnabled(int subId) {
2903 try {
2904 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2905 null);
2906 } catch (Exception e) {
2907 enforceModifyPermissionOrCarrierPrivilege(subId);
2908 }
2909 int phoneId = mSubscriptionController.getPhoneId(subId);
2910 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2911 Phone phone = PhoneFactory.getPhone(phoneId);
2912 if (phone != null) {
2913 boolean retVal = phone.isDataEnabled();
2914 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2915 return retVal;
2916 } else {
2917 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002918 return false;
2919 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002920 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002921
2922 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002923 public int getCarrierPrivilegeStatus(int subId) {
2924 final Phone phone = getPhone(subId);
2925 if (phone == null) {
2926 loge("getCarrierPrivilegeStatus: Invalid subId");
2927 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2928 }
2929 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002930 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002931 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2933 }
2934 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002935 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002936 }
Junda Liu29340342014-07-10 15:23:27 -07002937
2938 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002939 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002940 if (TextUtils.isEmpty(pkgName))
2941 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002942 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002943 if (card == null) {
2944 loge("checkCarrierPrivilegesForPackage: No UICC");
2945 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2946 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002947 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2948 }
2949
2950 @Override
2951 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002952 if (TextUtils.isEmpty(pkgName))
2953 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002954 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2955 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2956 UiccCard card = UiccController.getInstance().getUiccCard(i);
2957 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002958 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002959 continue;
2960 }
2961
2962 result = card.getCarrierPrivilegeStatus(
2963 mPhone.getContext().getPackageManager(), pkgName);
2964 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2965 break;
2966 }
2967 }
2968
2969 return result;
Junda Liu29340342014-07-10 15:23:27 -07002970 }
Derek Tan89e89d42014-07-08 17:00:10 -07002971
2972 @Override
Junda Liue64de782015-04-16 17:19:16 -07002973 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2974 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2975 loge("phoneId " + phoneId + " is not valid.");
2976 return null;
2977 }
2978 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002979 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002980 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002981 return null ;
2982 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002983 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002984 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002985 }
2986
Amith Yamasani6e118872016-02-19 12:53:51 -08002987 @Override
2988 public List<String> getPackagesWithCarrierPrivileges() {
2989 PackageManager pm = mPhone.getContext().getPackageManager();
2990 List<String> privilegedPackages = new ArrayList<>();
2991 List<PackageInfo> packages = null;
2992 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2993 UiccCard card = UiccController.getInstance().getUiccCard(i);
2994 if (card == null) {
2995 // No UICC in that slot.
2996 continue;
2997 }
2998 if (card.hasCarrierPrivilegeRules()) {
2999 if (packages == null) {
3000 // Only check packages in user 0 for now
3001 packages = pm.getInstalledPackagesAsUser(
3002 PackageManager.MATCH_DISABLED_COMPONENTS
3003 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3004 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3005 }
3006 for (int p = packages.size() - 1; p >= 0; p--) {
3007 PackageInfo pkgInfo = packages.get(p);
3008 if (pkgInfo != null && pkgInfo.packageName != null
3009 && card.getCarrierPrivilegeStatus(pkgInfo)
3010 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3011 privilegedPackages.add(pkgInfo.packageName);
3012 }
3013 }
3014 }
3015 }
3016 return privilegedPackages;
3017 }
3018
Wink Savilleb564aae2014-10-23 10:18:09 -07003019 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003020 final Phone phone = getPhone(subId);
3021 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003022 if (card == null) {
3023 loge("getIccId: No UICC");
3024 return null;
3025 }
3026 String iccId = card.getIccId();
3027 if (TextUtils.isEmpty(iccId)) {
3028 loge("getIccId: ICC ID is null or empty.");
3029 return null;
3030 }
3031 return iccId;
3032 }
3033
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003034 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003035 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3036 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003037 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003038
Jeff Sharkey85190e62014-12-05 09:40:12 -08003039 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 final Phone phone = getPhone(subId);
3041 if (phone == null) {
3042 return false;
3043 }
3044 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003045
3046 if (DBG_MERGE) {
3047 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3048 + subscriberId + " to " + number);
3049 }
3050
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003051 if (TextUtils.isEmpty(iccId)) {
3052 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003053 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003054
Jeff Sharkey85190e62014-12-05 09:40:12 -08003055 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3056
3057 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003058 if (alphaTag == null) {
3059 editor.remove(alphaTagPrefKey);
3060 } else {
3061 editor.putString(alphaTagPrefKey, alphaTag);
3062 }
3063
Jeff Sharkey85190e62014-12-05 09:40:12 -08003064 // Record both the line number and IMSI for this ICCID, since we need to
3065 // track all merged IMSIs based on line number
3066 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3067 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003068 if (number == null) {
3069 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003070 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003071 } else {
3072 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003073 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003074 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003075
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003076 editor.commit();
3077 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003078 }
3079
3080 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003081 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003082 // This is open to apps with WRITE_SMS.
3083 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003084 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003085 return null;
3086 }
Derek Tan97ebb422014-09-05 16:55:38 -07003087
3088 String iccId = getIccId(subId);
3089 if (iccId != null) {
3090 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003091 if (DBG_MERGE) {
3092 log("getLine1NumberForDisplay returning " +
3093 mTelephonySharedPreferences.getString(numberPrefKey, null));
3094 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003095 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003096 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003097 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003098 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003099 }
3100
3101 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003102 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3103 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3104 return null;
3105 }
Derek Tan97ebb422014-09-05 16:55:38 -07003106
3107 String iccId = getIccId(subId);
3108 if (iccId != null) {
3109 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003110 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003111 }
Derek Tan97ebb422014-09-05 16:55:38 -07003112 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003113 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003114
3115 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003116 public String[] getMergedSubscriberIds(String callingPackage) {
3117 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3118 return null;
3119 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003120 final Context context = mPhone.getContext();
3121 final TelephonyManager tele = TelephonyManager.from(context);
3122 final SubscriptionManager sub = SubscriptionManager.from(context);
3123
3124 // Figure out what subscribers are currently active
3125 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003126 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3127 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 final int[] subIds = sub.getActiveSubscriptionIdList();
3131 for (int subId : subIds) {
3132 activeSubscriberIds.add(tele.getSubscriberId(subId));
3133 }
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003136 }
3137
3138 // First pass, find a number override for an active subscriber
3139 String mergeNumber = null;
3140 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3141 for (String key : prefs.keySet()) {
3142 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3143 final String subscriberId = (String) prefs.get(key);
3144 if (activeSubscriberIds.contains(subscriberId)) {
3145 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3146 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3147 mergeNumber = (String) prefs.get(numberKey);
3148 if (DBG_MERGE) {
3149 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3150 + " for active subscriber " + subscriberId);
3151 }
3152 if (!TextUtils.isEmpty(mergeNumber)) {
3153 break;
3154 }
3155 }
3156 }
3157 }
3158
3159 // Shortcut when no active merged subscribers
3160 if (TextUtils.isEmpty(mergeNumber)) {
3161 return null;
3162 }
3163
3164 // Second pass, find all subscribers under that line override
3165 final ArraySet<String> result = new ArraySet<>();
3166 for (String key : prefs.keySet()) {
3167 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3168 final String number = (String) prefs.get(key);
3169 if (mergeNumber.equals(number)) {
3170 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3171 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3172 final String subscriberId = (String) prefs.get(subscriberKey);
3173 if (!TextUtils.isEmpty(subscriberId)) {
3174 result.add(subscriberId);
3175 }
3176 }
3177 }
3178 }
3179
3180 final String[] resultArray = result.toArray(new String[result.size()]);
3181 Arrays.sort(resultArray);
3182 if (DBG_MERGE) {
3183 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3184 }
3185 return resultArray;
3186 }
3187
3188 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003189 public boolean setOperatorBrandOverride(int subId, String brand) {
3190 enforceCarrierPrivilege(subId);
3191 final Phone phone = getPhone(subId);
3192 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003193 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003194
3195 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003196 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003197 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3198 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003199 enforceCarrierPrivilege(subId);
3200 final Phone phone = getPhone(subId);
3201 if (phone == null) {
3202 return false;
3203 }
3204 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003205 cdmaNonRoamingList);
3206 }
3207
3208 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003209 public void setRadioCapability(RadioAccessFamily[] rafs) {
3210 try {
3211 ProxyController.getInstance().setRadioCapability(rafs);
3212 } catch (RuntimeException e) {
3213 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3214 }
3215 }
3216
3217 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3219 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3220 return RadioAccessFamily.RAF_UNKNOWN;
3221 }
3222
Wink Saville5d475dd2014-10-17 15:00:58 -07003223 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3224 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003225
3226 @Override
3227 public void enableVideoCalling(boolean enable) {
3228 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003229 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003230 }
3231
3232 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003233 public boolean isVideoCallingEnabled(String callingPackage) {
3234 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3235 return false;
3236 }
3237
Andrew Lee77527ac2014-10-21 16:57:39 -07003238 // Check the user preference and the system-level IMS setting. Even if the user has
3239 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3240 // In the long run, we may instead need to check if there exists a connection service
3241 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003242 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3243 return imsManager.isVtEnabledByPlatform()
3244 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3245 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003246 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003247
Andrew Leea1239f22015-03-02 17:44:07 -08003248 @Override
3249 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003250 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003251 }
3252
3253 @Override
3254 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003255 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003256 }
3257
Andrew Lee9431b832015-03-09 18:46:45 -07003258 @Override
3259 public boolean isTtyModeSupported() {
3260 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3261 TelephonyManager telephonyManager =
3262 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003263 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003264 }
3265
3266 @Override
3267 public boolean isHearingAidCompatibilitySupported() {
3268 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3269 }
3270
Hall Liu98187582018-01-22 19:15:32 -08003271 public boolean isRttSupported() {
3272 boolean isCarrierSupported =
3273 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3274 boolean isDeviceSupported =
3275 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3276 return isCarrierSupported && isDeviceSupported;
3277 }
3278
Sanket Padawe7310cc72015-01-14 09:53:20 -08003279 /**
3280 * Returns the unique device ID of phone, for example, the IMEI for
3281 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3282 *
3283 * <p>Requires Permission:
3284 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3285 */
3286 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003287 public String getDeviceId(String callingPackage) {
3288 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3289 return null;
3290 }
3291
Sanket Padawe7310cc72015-01-14 09:53:20 -08003292 final Phone phone = PhoneFactory.getPhone(0);
3293 if (phone != null) {
3294 return phone.getDeviceId();
3295 } else {
3296 return null;
3297 }
3298 }
3299
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003300 /*
3301 * {@hide}
3302 * Returns the IMS Registration Status
3303 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003304 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003305 public boolean isImsRegistered() {
3306 return mPhone.isImsRegistered();
3307 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003308
Ping Sunc67b7c22016-03-02 19:16:45 +08003309 /**
3310 * {@hide}
3311 * Returns the IMS Registration Status on a particular subid
3312 *
3313 * @param subId
3314 */
3315 public boolean isImsRegisteredForSubscriber(int subId) {
3316 Phone phone = getPhone(subId);
3317 if (phone != null) {
3318 return phone.isImsRegistered();
3319 } else {
3320 return false;
3321 }
3322 }
3323
Santos Cordon7a1885b2015-02-03 11:15:19 -08003324 @Override
3325 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3326 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3327 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003328
Nathan Haroldc55097a2015-03-11 18:14:50 -07003329 /*
3330 * {@hide}
3331 * Returns the IMS Registration Status
3332 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003333 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003334 return mPhone.isWifiCallingEnabled();
3335 }
3336
3337 /*
3338 * {@hide}
3339 * Returns the IMS Registration Status
3340 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003341 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003342 return mPhone.isVolteEnabled();
3343 }
Svet Ganovb320e182015-04-16 12:30:10 -07003344
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003345 /*
3346 * {@hide} Returns the IMS Registration Status
3347 */
3348 public boolean isVideoTelephonyAvailable() {
3349 return mPhone.isVideoEnabled();
3350 }
3351
Svet Ganovb320e182015-04-16 12:30:10 -07003352 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003353 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003354 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003355 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3356
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003357 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003358 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003359 } catch (SecurityException e) {
3360 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3361 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003362 }
Svet Ganovb320e182015-04-16 12:30:10 -07003363
3364 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3365 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3366 return false;
3367 }
3368
3369 return true;
3370 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003371
Makoto Onukifee69342015-06-29 14:44:50 -07003372 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003373 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003374 */
3375 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003376 // Default SMS app can always read it.
3377 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3378 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3379 return true;
3380 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003381
Makoto Onukie4072d12015-08-03 15:12:23 -07003382 try {
3383 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003384 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003385 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003386 // Can be read with READ_SMS too.
3387 try {
3388 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3389 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3390 if (opCode != AppOpsManager.OP_NONE) {
3391 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3392 == AppOpsManager.MODE_ALLOWED;
3393 } else {
3394 return true;
3395 }
3396 } catch (SecurityException readSmsSecurityException) {
3397 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003398 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003399 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003401 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003402 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003403 if (opCode != AppOpsManager.OP_NONE) {
3404 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3405 == AppOpsManager.MODE_ALLOWED;
3406 } else {
3407 return true;
3408 }
3409 } catch (SecurityException readPhoneNumberSecurityException) {
3410 }
3411
3412 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3413 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3414 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003415 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003416 }
3417
Stuart Scott8eef64f2015-04-08 15:13:54 -07003418 @Override
3419 public void factoryReset(int subId) {
3420 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003421 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3422 return;
3423 }
3424
Svet Ganovcc087f82015-05-12 20:35:54 -07003425 final long identity = Binder.clearCallingIdentity();
3426 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003427 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3428 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003429 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003430 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003431 // Set network selection mode to automatic
3432 setNetworkSelectionModeAutomatic(subId);
3433 // Set preferred mobile network type to the best available
3434 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3435 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003436 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003437 // Remove IMSI encryption keys from Carrier DB.
3438 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003439 }
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003442 }
3443 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003444
3445 @Override
3446 public String getLocaleFromDefaultSim() {
3447 // We query all subscriptions instead of just the active ones, because
3448 // this might be called early on in the provisioning flow when the
3449 // subscriptions potentially aren't active yet.
3450 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3451 if (slist == null || slist.isEmpty()) {
3452 return null;
3453 }
3454
3455 // This function may be called very early, say, from the setup wizard, at
3456 // which point we won't have a default subscription set. If that's the case
3457 // we just choose the first, which will be valid in "most cases".
3458 final int defaultSubId = getDefaultSubscription();
3459 SubscriptionInfo info = null;
3460 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3461 info = slist.get(0);
3462 } else {
3463 for (SubscriptionInfo item : slist) {
3464 if (item.getSubscriptionId() == defaultSubId) {
3465 info = item;
3466 break;
3467 }
3468 }
3469
3470 if (info == null) {
3471 return null;
3472 }
3473 }
3474
3475 // Try and fetch the locale from the carrier properties or from the SIM language
3476 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003477 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003478 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003479 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003480 if (defaultPhone != null) {
3481 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3482 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003483 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003484 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3485 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003486 } else {
3487 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003488 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003489 }
3490 }
3491
Narayan Kamath011676f2015-07-29 12:04:08 +01003492 // The SIM language preferences only store a language (e.g. fr = French), not an
3493 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3494 // the SIM and carrier preferences does not include a country we add the country
3495 // determined from the SIM MCC to provide an exact locale.
3496 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003497 if (mccLocale != null) {
3498 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3499 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003500 }
3501
Tony Hill183b2de2015-06-24 14:53:58 +01003502 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003503 return null;
3504 }
3505
3506 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 return mSubscriptionController.getAllSubInfoList(
3510 mPhone.getContext().getOpPackageName());
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 }
3515
3516 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 return mSubscriptionController.getActiveSubscriptionInfoList(
3520 mPhone.getContext().getOpPackageName());
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003525
Chenjie Yu1ba97252018-01-11 18:16:20 -08003526 private final ModemActivityInfo mLastModemActivityInfo =
3527 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3528
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003529 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003530 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3531 * representing the state of the modem.
3532 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003533 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3534 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003535 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003536 */
3537 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003538 public void requestModemActivityInfo(ResultReceiver result) {
3539 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003540 ModemActivityInfo ret = null;
3541 synchronized (mLastModemActivityInfo) {
3542 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3543 null);
3544 if (info != null) {
3545 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3546 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3547 mergedTxTimeMs[i] =
3548 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3549 }
3550 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3551 mLastModemActivityInfo.setSleepTimeMillis(
3552 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3553 mLastModemActivityInfo.setIdleTimeMillis(
3554 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3555 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3556 mLastModemActivityInfo.setRxTimeMillis(
3557 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3558 mLastModemActivityInfo.setEnergyUsed(
3559 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3560 }
3561 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3562 mLastModemActivityInfo.getSleepTimeMillis(),
3563 mLastModemActivityInfo.getIdleTimeMillis(),
3564 mLastModemActivityInfo.getTxTimeMillis(),
3565 mLastModemActivityInfo.getRxTimeMillis(),
3566 mLastModemActivityInfo.getEnergyUsed());
3567 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003568 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003569 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003570 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003571 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003572
3573 /**
3574 * {@hide}
3575 * Returns the service state information on specified subscription.
3576 */
3577 @Override
3578 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3579
3580 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3581 return null;
3582 }
3583
3584 final Phone phone = getPhone(subId);
3585 if (phone == null) {
3586 return null;
3587 }
3588
3589 return phone.getServiceState();
3590 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003591
3592 /**
3593 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3594 *
3595 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3596 * voicemail ringtone.
3597 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3598 * PhoneAccount.
3599 */
3600 @Override
3601 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003602 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003603 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003604 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003605 }
3606
fionaxu7ed723d2017-05-30 18:58:54 -07003607 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003608 }
3609
3610 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003611 * Sets the per-account voicemail ringtone.
3612 *
3613 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3614 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3615 *
3616 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3617 * voicemail ringtone.
3618 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3619 * PhoneAccount.
3620 */
3621 @Override
3622 public void setVoicemailRingtoneUri(String callingPackage,
3623 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3625 if (!TextUtils.equals(callingPackage,
3626 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3627 enforceModifyPermissionOrCarrierPrivilege(
3628 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3629 }
3630 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3631 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003632 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003633 }
fionaxu7ed723d2017-05-30 18:58:54 -07003634 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003635 }
3636
3637 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003638 * Returns whether vibration is set for voicemail notification in Phone settings.
3639 *
3640 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3641 * voicemail vibration setting.
3642 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3643 */
3644 @Override
3645 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003646 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003647 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003648 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003649 }
3650
fionaxu7ed723d2017-05-30 18:58:54 -07003651 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003652 }
3653
Youhan Wange64578a2016-05-02 15:32:42 -07003654 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003655 * Sets the per-account voicemail vibration.
3656 *
3657 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3658 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3659 *
3660 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3661 * voicemail vibration setting.
3662 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3663 * specific PhoneAccount.
3664 */
3665 @Override
3666 public void setVoicemailVibrationEnabled(String callingPackage,
3667 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3669 if (!TextUtils.equals(callingPackage,
3670 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3671 enforceModifyPermissionOrCarrierPrivilege(
3672 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3673 }
3674
3675 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3676 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003677 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003678 }
fionaxu7ed723d2017-05-30 18:58:54 -07003679 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003680 }
3681
3682 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003683 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3684 *
3685 * @throws SecurityException if the caller does not have the required permission
3686 */
3687 private void enforceReadPrivilegedPermission() {
3688 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3689 null);
3690 }
3691
3692 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003693 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3694 * permission.
3695 *
3696 * @throws SecurityException if the caller does not have the required permission
3697 */
3698 private void enforceSendSmsPermission() {
3699 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3700 }
3701
3702 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003703 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003704 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003705 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003706 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003707 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003708 ComponentName componentName =
3709 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3710 if(componentName == null) {
3711 throw new SecurityException("Caller not current active visual voicemail package[null]");
3712 }
3713 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003714 if (!callingPackage.equals(vvmPackage)) {
3715 throw new SecurityException("Caller not current active visual voicemail package[" +
3716 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003717 }
3718 }
3719
3720 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003721 * Return the application ID for the app type.
3722 *
3723 * @param subId the subscription ID that this request applies to.
3724 * @param appType the uicc app type.
3725 * @return Application ID for specificied app type, or null if no uicc.
3726 */
3727 @Override
3728 public String getAidForAppType(int subId, int appType) {
3729 enforceReadPrivilegedPermission();
3730 Phone phone = getPhone(subId);
3731 if (phone == null) {
3732 return null;
3733 }
3734 String aid = null;
3735 try {
3736 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3737 .getApplicationByType(appType).getAid();
3738 } catch (Exception e) {
3739 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3740 }
3741 return aid;
3742 }
3743
Youhan Wang4001d252016-05-11 10:29:41 -07003744 /**
3745 * Return the Electronic Serial Number.
3746 *
3747 * @param subId the subscription ID that this request applies to.
3748 * @return ESN or null if error.
3749 */
3750 @Override
3751 public String getEsn(int subId) {
3752 enforceReadPrivilegedPermission();
3753 Phone phone = getPhone(subId);
3754 if (phone == null) {
3755 return null;
3756 }
3757 String esn = null;
3758 try {
3759 esn = phone.getEsn();
3760 } catch (Exception e) {
3761 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3762 }
3763 return esn;
3764 }
3765
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003766 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003767 * Return the Preferred Roaming List Version.
3768 *
3769 * @param subId the subscription ID that this request applies to.
3770 * @return PRLVersion or null if error.
3771 */
3772 @Override
3773 public String getCdmaPrlVersion(int subId) {
3774 enforceReadPrivilegedPermission();
3775 Phone phone = getPhone(subId);
3776 if (phone == null) {
3777 return null;
3778 }
3779 String cdmaPrlVersion = null;
3780 try {
3781 cdmaPrlVersion = phone.getCdmaPrlVersion();
3782 } catch (Exception e) {
3783 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3784 }
3785 return cdmaPrlVersion;
3786 }
3787
3788 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003789 * Get snapshot of Telephony histograms
3790 * @return List of Telephony histograms
3791 * @hide
3792 */
3793 @Override
3794 public List<TelephonyHistogram> getTelephonyHistograms() {
3795 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3796 return RIL.getTelephonyRILTimingHistograms();
3797 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003798
3799 /**
3800 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003801 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003802 * Require system privileges. In the future we may add this to carrier APIs.
3803 *
3804 * @return The number of carriers set successfully, should match length of carriers
3805 */
3806 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003807 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003808 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003809
Meng Wang9b7c4e92017-02-17 11:41:27 -08003810 if (carriers == null) {
3811 throw new NullPointerException("carriers cannot be null");
3812 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003813
3814 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003815 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3816 return retVal[0];
3817 }
3818
3819 /**
3820 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003821 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003822 * Require system privileges. In the future we may add this to carrier APIs.
3823 *
3824 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3825 * means all carriers are allowed.
3826 */
3827 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003828 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003829 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003830 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003831 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3832 }
3833
fionaxu59545b42016-05-25 15:53:37 -07003834 /**
3835 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3836 * @param subId the subscription ID that this action applies to.
3837 * @param enabled control enable or disable metered apns.
3838 * {@hide}
3839 */
3840 @Override
3841 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3842 enforceModifyPermission();
3843 final Phone phone = getPhone(subId);
3844 if (phone == null) {
3845 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3846 return;
3847 }
3848 try {
3849 phone.carrierActionSetMeteredApnsEnabled(enabled);
3850 } catch (Exception e) {
3851 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3852 }
3853 }
3854
3855 /**
3856 * Action set from carrier signalling broadcast receivers to enable/disable radio
3857 * @param subId the subscription ID that this action applies to.
3858 * @param enabled control enable or disable radio.
3859 * {@hide}
3860 */
3861 @Override
3862 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3863 enforceModifyPermission();
3864 final Phone phone = getPhone(subId);
3865 if (phone == null) {
3866 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3867 return;
3868 }
3869 try {
3870 phone.carrierActionSetRadioEnabled(enabled);
3871 } catch (Exception e) {
3872 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3873 }
3874 }
3875
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003876 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003877 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3878 * network status based on which carrier apps could apply actions accordingly,
3879 * enable/disable default url handler for example.
3880 *
3881 * @param subId the subscription ID that this action applies to.
3882 * @param report control start/stop reporting the default network status.
3883 * {@hide}
3884 */
3885 @Override
3886 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3887 enforceModifyPermission();
3888 final Phone phone = getPhone(subId);
3889 if (phone == null) {
3890 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3891 return;
3892 }
3893 try {
3894 phone.carrierActionReportDefaultNetworkStatus(report);
3895 } catch (Exception e) {
3896 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3897 }
3898 }
3899
3900 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003901 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3902 * bug report is being generated.
3903 */
3904 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003905 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003906 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3907 != PackageManager.PERMISSION_GRANTED) {
3908 writer.println("Permission Denial: can't dump Phone from pid="
3909 + Binder.getCallingPid()
3910 + ", uid=" + Binder.getCallingUid()
3911 + "without permission "
3912 + android.Manifest.permission.DUMP);
3913 return;
3914 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003915 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003916 }
Jack Yueb89b242016-06-22 13:27:47 -07003917
3918 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003919 * Get aggregated video call data usage since boot.
3920 *
3921 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3922 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003923 * {@hide}
3924 */
3925 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003926 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3928 null);
3929
Jack Yu84291ec2017-05-26 16:07:50 -07003930 // NetworkStatsService keeps tracking the active network interface and identity. It
3931 // records the delta with the corresponding network identity. We just return the total video
3932 // call data usage snapshot since boot.
3933 Phone phone = getPhone(subId);
3934 if (phone != null) {
3935 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003936 }
Jack Yu84291ec2017-05-26 16:07:50 -07003937 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003938 }
Jack Yu75ab2952016-07-08 14:29:33 -07003939
3940 /**
3941 * Policy control of data connection. Usually used when data limit is passed.
3942 * @param enabled True if enabling the data, otherwise disabling.
3943 * @param subId Subscription index
3944 * {@hide}
3945 */
3946 @Override
3947 public void setPolicyDataEnabled(boolean enabled, int subId) {
3948 enforceModifyPermission();
3949 Phone phone = getPhone(subId);
3950 if (phone != null) {
3951 phone.setPolicyDataEnabled(enabled);
3952 }
3953 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003954
3955 /**
3956 * Get Client request stats
3957 * @return List of Client Request Stats
3958 * @hide
3959 */
3960 @Override
3961 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3962 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3963 return null;
3964 }
3965
3966 Phone phone = getPhone(subId);
3967 if (phone != null) {
3968 return phone.getClientRequestStats();
3969 }
3970
3971 return null;
3972 }
3973
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003974 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003975 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003976 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003977 }
Jack Yueb4124c2017-02-16 15:32:43 -08003978
3979 /**
Grace Chen70990072017-03-24 17:21:30 -07003980 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003981 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003982 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003983 * @param state State of SIM (power down, power up, pass through)
3984 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3985 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003987 *
3988 **/
3989 @Override
Grace Chen70990072017-03-24 17:21:30 -07003990 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003991 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003992 Phone phone = PhoneFactory.getPhone(slotIndex);
3993
Jack Yueb4124c2017-02-16 15:32:43 -08003994 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003995 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003996 }
3997 }
Shuo Qiandd210312017-04-12 22:11:33 +00003998
Tyler Gunn65d45c22017-06-05 11:22:26 -07003999 private boolean isUssdApiAllowed(int subId) {
4000 CarrierConfigManager configManager =
4001 (CarrierConfigManager) mPhone.getContext().getSystemService(
4002 Context.CARRIER_CONFIG_SERVICE);
4003 if (configManager == null) {
4004 return false;
4005 }
4006 PersistableBundle pb = configManager.getConfigForSubId(subId);
4007 if (pb == null) {
4008 return false;
4009 }
4010 return pb.getBoolean(
4011 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4012 }
4013
Shuo Qiandd210312017-04-12 22:11:33 +00004014 /**
4015 * Check if phone is in emergency callback mode
4016 * @return true if phone is in emergency callback mode
4017 * @param subId sub id
4018 */
goneil9c5f4872017-12-05 14:07:56 -08004019 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004020 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004021 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004022 final Phone phone = getPhone(subId);
4023 if (phone != null) {
4024 return phone.isInEcm();
4025 } else {
4026 return false;
4027 }
4028 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004029
4030 /**
4031 * Get the current signal strength information for the given subscription.
4032 * Because this information is not updated when the device is in a low power state
4033 * it should not be relied-upon to be current.
4034 * @param subId Subscription index
4035 * @return the most recent cached signal strength info from the modem
4036 */
4037 @Override
4038 public SignalStrength getSignalStrength(int subId) {
4039 Phone p = getPhone(subId);
4040 if (p == null) {
4041 return null;
4042 }
4043
4044 return p.getSignalStrength();
4045 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004046
4047 @Override
4048 public UiccSlotInfo[] getUiccSlotsInfo() {
4049 enforceReadPrivilegedPermission();
4050
4051 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4052 if (slots == null) return null;
4053 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4054 for (int i = 0; i < slots.length; i++) {
4055 UiccSlot slot = slots[i];
4056
4057 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4058
4059 int cardState = 0;
4060 switch (slot.getCardState()) {
4061 case CARDSTATE_ABSENT:
4062 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4063 break;
4064 case CARDSTATE_PRESENT:
4065 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4066 break;
4067 case CARDSTATE_ERROR:
4068 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4069 break;
4070 case CARDSTATE_RESTRICTED:
4071 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4072 break;
4073 default:
4074 break;
4075
4076 }
4077
Qingxi Li795c5882018-01-31 13:43:27 -08004078 infos[i] = new UiccSlotInfo(
4079 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004080 }
4081 return infos;
4082 }
4083
4084 @Override
4085 public boolean switchSlots(int[] physicalSlots) {
4086 enforceModifyPermission();
4087 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089}