blob: c9c50cdb743b0bc100cdba15c974e6b5b7493a5e [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 Ebinger7e934f52017-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;
Hall Liu1aa510f2017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080078import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080084
Andrew Lee312e8172014-10-23 17:01:36 -070085import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080086import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070088import com.android.internal.telephony.CallStateException;
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 Basseri03923952017-07-19 12:22:35 -0700105import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700106import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.IccIoResult;
108import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700110import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800111import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700114import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800117import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700119import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700121import java.io.FileDescriptor;
122import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800126import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129
130/**
131 * Implementation of the ITelephony interface.
132 */
Santos Cordon117fee72014-05-16 17:56:12 -0700133public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 private static final String LOG_TAG = "PhoneInterfaceManager";
135 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
136 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138
139 // Message codes used with mMainThreadHandler
140 private static final int CMD_HANDLE_PIN_MMI = 1;
141 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
142 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
143 private static final int CMD_ANSWER_RINGING_CALL = 4;
144 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700145 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
146 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147 private static final int CMD_OPEN_CHANNEL = 9;
148 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
149 private static final int CMD_CLOSE_CHANNEL = 11;
150 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800151 private static final int CMD_NV_READ_ITEM = 13;
152 private static final int EVENT_NV_READ_ITEM_DONE = 14;
153 private static final int CMD_NV_WRITE_ITEM = 15;
154 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
155 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
156 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
157 private static final int CMD_NV_RESET_CONFIG = 19;
158 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800159 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
160 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
161 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
162 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800163 private static final int CMD_SEND_ENVELOPE = 25;
164 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700165 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
166 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
167 private static final int CMD_EXCHANGE_SIM_IO = 31;
168 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800169 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
170 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700171 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
172 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700173 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
174 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
176 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
177 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700179 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
180 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
181 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
182 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700183 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
185 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000186 private static final int CMD_SWITCH_SLOTS = 50;
187 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800189 // Parameters of select command.
190 private static final int SELECT_COMMAND = 0xA4;
191 private static final int SELECT_P1 = 0x04;
192 private static final int SELECT_P2 = 0;
193 private static final int SELECT_P3 = 0x10;
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 /** The singleton instance. */
196 private static PhoneInterfaceManager sInstance;
197
Wink Saville3ab207e2014-11-20 13:07:20 -0800198 private PhoneGlobals mApp;
199 private Phone mPhone;
200 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700201 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private AppOpsManager mAppOps;
203 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800205 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Derek Tan97ebb422014-09-05 16:55:38 -0700207 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
208 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800209 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700210
Derek Tan740e1672017-06-27 14:56:27 -0700211 // The AID of ISD-R.
212 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
213
yinxub1bed742017-04-17 11:45:04 -0700214 private NetworkScanRequestTracker mNetworkScanRequestTracker;
215
Derek Tan89e89d42014-07-08 17:00:10 -0700216 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700217 * A request object to use for transmitting data to an ICC.
218 */
219 private static final class IccAPDUArgument {
220 public int channel, cla, command, p1, p2, p3;
221 public String data;
222
223 public IccAPDUArgument(int channel, int cla, int command,
224 int p1, int p2, int p3, String data) {
225 this.channel = channel;
226 this.cla = cla;
227 this.command = command;
228 this.p1 = p1;
229 this.p2 = p2;
230 this.p3 = p3;
231 this.data = data;
232 }
233 }
234
235 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700236 * A request object to use for transmitting data to an ICC.
237 */
238 private static final class ManualNetworkSelectionArgument {
239 public OperatorInfo operatorInfo;
240 public boolean persistSelection;
241
242 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
243 this.operatorInfo = operatorInfo;
244 this.persistSelection = persistSelection;
245 }
246 }
247
248 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
250 * request after sending. The main thread will notify the request when it is complete.
251 */
252 private static final class MainThreadRequest {
253 /** The argument to use for the request */
254 public Object argument;
255 /** The result of the request that is run on the main thread */
256 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800257 // The subscriber id that this request applies to. Defaults to
258 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
259 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
261 public MainThreadRequest(Object argument) {
262 this.argument = argument;
263 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264
265 public MainThreadRequest(Object argument, Integer subId) {
266 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800267 if (subId != null) {
268 this.subId = subId;
269 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 }
272
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800273 private static final class IncomingThirdPartyCallArgs {
274 public final ComponentName component;
275 public final String callId;
276 public final String callerDisplayName;
277
278 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
279 String callerDisplayName) {
280 this.component = component;
281 this.callId = callId;
282 this.callerDisplayName = callerDisplayName;
283 }
284 }
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 /**
287 * A handler that processes messages on the main thread in the phone process. Since many
288 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
289 * inbound binder threads to the main thread in the phone process. The Binder thread
290 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
291 * on, which will be notified when the operation completes and will contain the result of the
292 * request.
293 *
294 * <p>If a MainThreadRequest object is provided in the msg.obj field,
295 * note that request.result must be set to something non-null for the calling thread to
296 * unblock.
297 */
298 private final class MainThreadHandler extends Handler {
299 @Override
300 public void handleMessage(Message msg) {
301 MainThreadRequest request;
302 Message onCompleted;
303 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800304 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700305 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
307 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700308 case CMD_HANDLE_USSD_REQUEST: {
309 request = (MainThreadRequest) msg.obj;
310 final Phone phone = getPhoneFromRequest(request);
311 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
312 String ussdRequest = ussdObject.first;
313 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700314
315 if (!isUssdApiAllowed(request.subId)) {
316 // Carrier does not support use of this API, return failure.
317 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
318 UssdResponse response = new UssdResponse(ussdRequest, null);
319 Bundle returnData = new Bundle();
320 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
321 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
322
323 request.result = true;
324 synchronized (request) {
325 request.notifyAll();
326 }
327 return;
328 }
329
Tyler Gunn52dcf772017-04-26 11:30:31 -0700330 try {
331 request.result = phone != null ?
332 phone.handleUssdRequest(ussdRequest, wrappedCallback)
333 : false;
334 } catch (CallStateException cse) {
335 request.result = false;
336 }
pkanwar32d516d2016-10-14 19:37:38 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
342 }
343
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 final Phone phone = getPhoneFromRequest(request);
347 request.result = phone != null ?
348 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
349 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
357 case CMD_HANDLE_NEIGHBORING_CELL:
358 request = (MainThreadRequest) msg.obj;
359 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
360 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700361 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 break;
363
364 case EVENT_NEIGHBORING_CELL_DONE:
365 ar = (AsyncResult) msg.obj;
366 request = (MainThreadRequest) ar.userObj;
367 if (ar.exception == null && ar.result != null) {
368 request.result = ar.result;
369 } else {
370 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800371 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373 // Wake up the requesting thread
374 synchronized (request) {
375 request.notifyAll();
376 }
377 break;
378
379 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700380 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800381 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700382 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 case CMD_END_CALL:
386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700389 Phone phone = getPhone(end_subId);
390 if (phone == null) {
391 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
392 break;
393 }
394 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
396 // CDMA: If the user presses the Power button we treat it as
397 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700398 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
400 // GSM: End the call as per the Phone state
401 hungUp = PhoneUtils.hangup(mCM);
402 } else {
403 throw new IllegalStateException("Unexpected phone type: " + phoneType);
404 }
405 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
406 request.result = hungUp;
407 // Wake up the requesting thread
408 synchronized (request) {
409 request.notifyAll();
410 }
411 break;
412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 if (uiccCard == null) {
418 loge("iccTransmitApduLogicalChannel: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
420 synchronized (request) {
421 request.notifyAll();
422 }
423 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
425 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument.channel, iccArgument.cla, iccArgument.command,
428 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 break;
432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 ar = (AsyncResult) msg.obj;
435 request = (MainThreadRequest) ar.userObj;
436 if (ar.exception == null && ar.result != null) {
437 request.result = ar.result;
438 } else {
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
440 if (ar.result == null) {
441 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800442 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800444 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 } else {
446 loge("iccTransmitApduLogicalChannel: Unknown exception");
447 }
448 }
449 synchronized (request) {
450 request.notifyAll();
451 }
452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
455 request = (MainThreadRequest) msg.obj;
456 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800457 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 if (uiccCard == null) {
459 loge("iccTransmitApduBasicChannel: No UICC");
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 synchronized (request) {
462 request.notifyAll();
463 }
464 } else {
465 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
466 request);
467 uiccCard.iccTransmitApduBasicChannel(
468 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
469 iccArgument.p3, iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduBasicChannel: Empty response");
482 } else if (ar.exception instanceof CommandException) {
483 loge("iccTransmitApduBasicChannel: CommandException: " +
484 ar.exception);
485 } else {
486 loge("iccTransmitApduBasicChannel: Unknown exception");
487 }
488 }
489 synchronized (request) {
490 request.notifyAll();
491 }
492 break;
493
494 case CMD_EXCHANGE_SIM_IO:
495 request = (MainThreadRequest) msg.obj;
496 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 if (uiccCard == null) {
499 loge("iccExchangeSimIO: No UICC");
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
501 synchronized (request) {
502 request.notifyAll();
503 }
504 } else {
505 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
506 request);
507 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
508 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
509 iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_EXCHANGE_SIM_IO_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6f, 0, (byte[])null);
520 }
521 synchronized (request) {
522 request.notifyAll();
523 }
524 break;
525
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 case CMD_SEND_ENVELOPE:
527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("sendEnvelopeWithStatus: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 synchronized (request) {
533 request.notifyAll();
534 }
535 } else {
536 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
537 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
538 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 break;
540
541 case EVENT_SEND_ENVELOPE_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("sendEnvelopeWithStatus: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("sendEnvelopeWithStatus: CommandException: " +
552 ar.exception);
553 } else {
554 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
555 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 }
557 synchronized (request) {
558 request.notifyAll();
559 }
560 break;
561
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 case CMD_OPEN_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800565 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800568 request.result = new IccOpenLogicalChannelResponse(-1,
569 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 synchronized (request) {
571 request.notifyAll();
572 }
573 } else {
574 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
576 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
580 case EVENT_OPEN_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 int[] result = (int[]) ar.result;
586 int channelId = result[0];
587 byte[] selectResponse = null;
588 if (result.length > 1) {
589 selectResponse = new byte[result.length - 1];
590 for (int i = 1; i < result.length; ++i) {
591 selectResponse[i - 1] = (byte) result[i];
592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.result == null) {
598 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 if (ar.exception != null) {
601 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
602 }
603
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700605 if (ar.exception instanceof CommandException) {
606 CommandException.Error error =
607 ((CommandException) (ar.exception)).getCommandError();
608 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700610 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(
615 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700617 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 synchronized (request) {
619 request.notifyAll();
620 }
621 break;
622
623 case CMD_CLOSE_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccCloseLogicalChannel: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
629 synchronized (request) {
630 request.notifyAll();
631 }
632 } else {
633 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
634 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800639 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
640 break;
641
642 case CMD_NV_READ_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
645 mPhone.nvReadItem((Integer) request.argument, onCompleted);
646 break;
647
648 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800654 request.result = "";
655 if (ar.result == null) {
656 loge("nvReadItem: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("nvReadItem: CommandException: " +
659 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800661 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
663 }
664 synchronized (request) {
665 request.notifyAll();
666 }
667 break;
668
Jake Hambye994d462014-02-03 13:10:13 -0800669 case CMD_NV_WRITE_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
672 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
673 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
674 break;
675
676 case EVENT_NV_WRITE_ITEM_DONE:
677 handleNullReturnEvent(msg, "nvWriteItem");
678 break;
679
680 case CMD_NV_WRITE_CDMA_PRL:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
683 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
684 break;
685
686 case EVENT_NV_WRITE_CDMA_PRL_DONE:
687 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
688 break;
689
690 case CMD_NV_RESET_CONFIG:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
693 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
694 break;
695
696 case EVENT_NV_RESET_CONFIG_DONE:
697 handleNullReturnEvent(msg, "nvResetConfig");
698 break;
699
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 case CMD_GET_PREFERRED_NETWORK_TYPE:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result; // Integer
711 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800712 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 if (ar.result == null) {
714 loge("getPreferredNetworkType: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("getPreferredNetworkType: CommandException: " +
717 ar.exception);
718 } else {
719 loge("getPreferredNetworkType: Unknown exception");
720 }
721 }
722 synchronized (request) {
723 request.notifyAll();
724 }
725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 case CMD_SET_VOICEMAIL_NUMBER:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
741 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800742 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
743 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800744 break;
745
746 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
747 handleNullReturnEvent(msg, "setVoicemailNumber");
748 break;
749
Stuart Scott54788802015-03-30 13:18:01 -0700750 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
753 request);
754 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
755 break;
756
757 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
758 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
759 break;
760
Shishir Agrawal302c8692015-06-19 13:49:39 -0700761 case CMD_PERFORM_NETWORK_SCAN:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
764 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
765 break;
766
767 case EVENT_PERFORM_NETWORK_SCAN_DONE:
768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
770 CellNetworkScanResult cellScanResult;
771 if (ar.exception == null && ar.result != null) {
772 cellScanResult = new CellNetworkScanResult(
773 CellNetworkScanResult.STATUS_SUCCESS,
774 (List<OperatorInfo>) ar.result);
775 } else {
776 if (ar.result == null) {
777 loge("getCellNetworkScanResults: Empty response");
778 }
779 if (ar.exception != null) {
780 loge("getCellNetworkScanResults: Exception: " + ar.exception);
781 }
782 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
783 if (ar.exception instanceof CommandException) {
784 CommandException.Error error =
785 ((CommandException) (ar.exception)).getCommandError();
786 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
788 } else if (error == CommandException.Error.GENERIC_FAILURE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
790 }
791 }
792 cellScanResult = new CellNetworkScanResult(errorCode, null);
793 }
794 request.result = cellScanResult;
795 synchronized (request) {
796 request.notifyAll();
797 }
798 break;
799
800 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
801 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700802 ManualNetworkSelectionArgument selArg =
803 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
805 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
807 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 break;
809
810 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
811 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
812 break;
813
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700814 case CMD_GET_MODEM_ACTIVITY_INFO:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700817 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 break;
819
820 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 if (ar.result == null) {
827 loge("queryModemActivityInfo: Empty response");
828 } else if (ar.exception instanceof CommandException) {
829 loge("queryModemActivityInfo: CommandException: " +
830 ar.exception);
831 } else {
832 loge("queryModemActivityInfo: Unknown exception");
833 }
834 }
Amit Mahajand4766222016-01-28 15:28:28 -0800835 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
836 if (request.result == null) {
837 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
838 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 synchronized (request) {
840 request.notifyAll();
841 }
842 break;
843
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 case CMD_SET_ALLOWED_CARRIERS:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
847 mPhone.setAllowedCarriers(
848 (List<CarrierIdentifier>) request.argument,
849 onCompleted);
850 break;
851
852 case EVENT_SET_ALLOWED_CARRIERS_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("setAllowedCarriers: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " +
862 ar.exception);
863 } else {
864 loge("setAllowedCarriers: Unknown exception");
865 }
866 }
867 // Result cannot be null. Return -1 on error.
868 if (request.result == null) {
869 request.result = new int[]{-1};
870 }
871 synchronized (request) {
872 request.notifyAll();
873 }
874 break;
875
876 case CMD_GET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
879 mPhone.getAllowedCarriers(onCompleted);
880 break;
881
882 case EVENT_GET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
888 if (ar.result == null) {
889 loge("getAllowedCarriers: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("getAllowedCarriers: CommandException: " +
892 ar.exception);
893 } else {
894 loge("getAllowedCarriers: Unknown exception");
895 }
896 }
897 // Result cannot be null. Return empty list of CarrierIdentifier.
898 if (request.result == null) {
899 request.result = new ArrayList<CarrierIdentifier>(0);
900 }
901 synchronized (request) {
902 request.notifyAll();
903 }
904 break;
905
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result;
911 } else {
912 request.result = new IllegalArgumentException(
913 "Failed to retrieve Forbidden Plmns");
914 if (ar.result == null) {
915 loge("getForbiddenPlmns: Empty response");
916 } else {
917 loge("getForbiddenPlmns: Unknown exception");
918 }
919 }
920 synchronized (request) {
921 request.notifyAll();
922 }
923 break;
924
925 case CMD_GET_FORBIDDEN_PLMNS:
926 request = (MainThreadRequest) msg.obj;
927 uiccCard = getUiccCardFromRequest(request);
928 if (uiccCard == null) {
929 loge("getForbiddenPlmns() UiccCard is null");
930 request.result = new IllegalArgumentException(
931 "getForbiddenPlmns() UiccCard is null");
932 synchronized (request) {
933 request.notifyAll();
934 }
935 break;
936 }
937 Integer appType = (Integer) request.argument;
938 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
939 if (uiccApp == null) {
940 loge("getForbiddenPlmns() no app with specified type -- "
941 + appType);
942 request.result = new IllegalArgumentException("Failed to get UICC App");
943 synchronized (request) {
944 request.notifyAll();
945 }
946 break;
947 } else {
948 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
949 + " specified type -- " + appType);
950 }
951 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
952 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
953 onCompleted);
954 break;
955
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000956 case CMD_SWITCH_SLOTS:
957 request = (MainThreadRequest) msg.obj;
958 int[] physicalSlots = (int[]) request.argument;
959 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
960 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
961 break;
962
963 case EVENT_SWITCH_SLOTS_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 request.result = (ar.exception == null);
967 synchronized (request) {
968 request.notifyAll();
969 }
970 break;
971
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972 default:
973 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
974 break;
975 }
976 }
Jake Hambye994d462014-02-03 13:10:13 -0800977
978 private void handleNullReturnEvent(Message msg, String command) {
979 AsyncResult ar = (AsyncResult) msg.obj;
980 MainThreadRequest request = (MainThreadRequest) ar.userObj;
981 if (ar.exception == null) {
982 request.result = true;
983 } else {
984 request.result = false;
985 if (ar.exception instanceof CommandException) {
986 loge(command + ": CommandException: " + ar.exception);
987 } else {
988 loge(command + ": Unknown exception");
989 }
990 }
991 synchronized (request) {
992 request.notifyAll();
993 }
994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 }
996
997 /**
998 * Posts the specified command to be executed on the main thread,
999 * waits for the request to complete, and returns the result.
1000 * @see #sendRequestAsync
1001 */
1002 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001003 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001004 }
1005
1006 /**
1007 * Posts the specified command to be executed on the main thread,
1008 * waits for the request to complete, and returns the result.
1009 * @see #sendRequestAsync
1010 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001011 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1013 throw new RuntimeException("This method will deadlock if called from the main thread.");
1014 }
1015
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001016 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001017 Message msg = mMainThreadHandler.obtainMessage(command, request);
1018 msg.sendToTarget();
1019
1020 // Wait for the request to complete
1021 synchronized (request) {
1022 while (request.result == null) {
1023 try {
1024 request.wait();
1025 } catch (InterruptedException e) {
1026 // Do nothing, go back and wait until the request is complete
1027 }
1028 }
1029 }
1030 return request.result;
1031 }
1032
1033 /**
1034 * Asynchronous ("fire and forget") version of sendRequest():
1035 * Posts the specified command to be executed on the main thread, and
1036 * returns immediately.
1037 * @see #sendRequest
1038 */
1039 private void sendRequestAsync(int command) {
1040 mMainThreadHandler.sendEmptyMessage(command);
1041 }
1042
1043 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001044 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1045 * @see {@link #sendRequest(int,Object)}
1046 */
1047 private void sendRequestAsync(int command, Object argument) {
1048 MainThreadRequest request = new MainThreadRequest(argument);
1049 Message msg = mMainThreadHandler.obtainMessage(command, request);
1050 msg.sendToTarget();
1051 }
1052
1053 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 * Initialize the singleton PhoneInterfaceManager instance.
1055 * This is only done once, at startup, from PhoneApp.onCreate().
1056 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001057 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 synchronized (PhoneInterfaceManager.class) {
1059 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001060 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 } else {
1062 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1063 }
1064 return sInstance;
1065 }
1066 }
1067
1068 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 mApp = app;
1071 mPhone = phone;
1072 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001073 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1075 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001076 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001077 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001078 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001079 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 publish();
1082 }
1083
1084 private void publish() {
1085 if (DBG) log("publish: " + this);
1086
1087 ServiceManager.addService("phone", this);
1088 }
1089
Stuart Scott584921c2015-01-15 17:10:34 -08001090 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001091 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1092 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001093 }
1094
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001095 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1096 Phone phone = getPhoneFromRequest(request);
1097 return phone == null ? null :
1098 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1099 }
1100
Wink Saville36469e72014-06-11 15:17:00 -07001101 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001102 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001103 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 //
1106 // Implementation of the ITelephony interface.
1107 //
1108
1109 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001110 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001111 }
1112
Wink Savilleb564aae2014-10-23 10:18:09 -07001113 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 if (DBG) log("dial: " + number);
1115 // No permission check needed here: This is just a wrapper around the
1116 // ACTION_DIAL intent, which is available to any app since it puts up
1117 // the UI before it does anything.
1118
1119 String url = createTelUrl(number);
1120 if (url == null) {
1121 return;
1122 }
1123
1124 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001125 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1127 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1129 mApp.startActivity(intent);
1130 }
1131 }
1132
1133 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001134 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001135 }
1136
Wink Savilleb564aae2014-10-23 10:18:09 -07001137 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 if (DBG) log("call: " + number);
1139
1140 // This is just a wrapper around the ACTION_CALL intent, but we still
1141 // need to do a permission check since we're calling startActivity()
1142 // from the context of the phone app.
1143 enforceCallPermission();
1144
1145 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1146 != AppOpsManager.MODE_ALLOWED) {
1147 return;
1148 }
1149
1150 String url = createTelUrl(number);
1151 if (url == null) {
1152 return;
1153 }
1154
Wink Saville08874612014-08-31 19:19:58 -07001155 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001156 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001157 if (slist != null) {
1158 for (SubscriptionInfo subInfoRecord : slist) {
1159 if (subInfoRecord.getSubscriptionId() == subId) {
1160 isValid = true;
1161 break;
1162 }
Wink Saville08874612014-08-31 19:19:58 -07001163 }
1164 }
1165 if (isValid == false) {
1166 return;
1167 }
1168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001170 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1172 mApp.startActivity(intent);
1173 }
1174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 /**
1176 * End a call based on call state
1177 * @return true is a call was ended
1178 */
1179 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001180 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
1183 /**
1184 * End a call based on the call state of the subId
1185 * @return true is a call was ended
1186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001187 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001189 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
1192 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001193 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001194 }
1195
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 if (DBG) log("answerRingingCall...");
1198 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1199 // but that can probably wait till the big TelephonyManager API overhaul.
1200 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1201 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001202 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 }
1204
1205 /**
1206 * Make the actual telephony calls to implement answerRingingCall().
1207 * This should only be called from the main thread of the Phone app.
1208 * @see #answerRingingCall
1209 *
1210 * TODO: it would be nice to return true if we answered the call, or
1211 * false if there wasn't actually a ringing incoming call, or some
1212 * other error occurred. (In other words, pass back the return value
1213 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1214 * But that would require calling this method via sendRequest() rather
1215 * than sendRequestAsync(), and right now we don't actually *need* that
1216 * return value, so let's just return void for now.
1217 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001219 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001221 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1222 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 if (hasActiveCall && hasHoldingCall) {
1224 // Both lines are in use!
1225 // TODO: provide a flag to let the caller specify what
1226 // policy to use if both lines are in use. (The current
1227 // behavior is hardwired to "answer incoming, end ongoing",
1228 // which is how the CALL button is specced to behave.)
1229 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1230 return;
1231 } else {
1232 // answerCall() will automatically hold the current active
1233 // call, if there is one.
1234 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1235 return;
1236 }
1237 } else {
1238 // No call was ringing.
1239 return;
1240 }
1241 }
1242
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001244 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001246 public void silenceRinger() {
1247 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 }
1249
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001250 @Override
1251 public boolean isOffhook(String callingPackage) {
1252 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1257 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1258 return false;
1259 }
1260
Sanket Padawe356d7632015-06-22 14:03:32 -07001261 final Phone phone = getPhone(subId);
1262 if (phone != null) {
1263 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1264 } else {
1265 return false;
1266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isRinging(String callingPackage) {
1271 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1276 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1277 return false;
1278 }
1279
Sanket Padawe356d7632015-06-22 14:03:32 -07001280 final Phone phone = getPhone(subId);
1281 if (phone != null) {
1282 return (phone.getState() == PhoneConstants.State.RINGING);
1283 } else {
1284 return false;
1285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isIdle(String callingPackage) {
1290 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1295 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1296 return false;
1297 }
1298
Sanket Padawe356d7632015-06-22 14:03:32 -07001299 final Phone phone = getPhone(subId);
1300 if (phone != null) {
1301 return (phone.getState() == PhoneConstants.State.IDLE);
1302 } else {
1303 return false;
1304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 }
1306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1314 }
1315
1316 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1323 }
1324
1325 /** {@hide} */
1326 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
1329
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001332 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 checkSimPin.start();
1334 return checkSimPin.unlockSim(null, pin);
1335 }
1336
Wink Saville9de0f752013-10-22 19:04:03 -07001337 /** {@hide} */
1338 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001344 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 checkSimPuk.start();
1346 return checkSimPuk.unlockSim(puk, pin);
1347 }
1348
1349 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001350 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 * a synchronous one.
1352 */
1353 private static class UnlockSim extends Thread {
1354
1355 private final IccCard mSimCard;
1356
1357 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001358 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1359 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
1361 // For replies from SimCard interface
1362 private Handler mHandler;
1363
1364 // For async handler to identify request type
1365 private static final int SUPPLY_PIN_COMPLETE = 100;
1366
1367 public UnlockSim(IccCard simCard) {
1368 mSimCard = simCard;
1369 }
1370
1371 @Override
1372 public void run() {
1373 Looper.prepare();
1374 synchronized (UnlockSim.this) {
1375 mHandler = new Handler() {
1376 @Override
1377 public void handleMessage(Message msg) {
1378 AsyncResult ar = (AsyncResult) msg.obj;
1379 switch (msg.what) {
1380 case SUPPLY_PIN_COMPLETE:
1381 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1382 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001383 mRetryCount = msg.arg1;
1384 if (ar.exception != null) {
1385 if (ar.exception instanceof CommandException &&
1386 ((CommandException)(ar.exception)).getCommandError()
1387 == CommandException.Error.PASSWORD_INCORRECT) {
1388 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1389 } else {
1390 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1391 }
1392 } else {
1393 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mDone = true;
1396 UnlockSim.this.notifyAll();
1397 }
1398 break;
1399 }
1400 }
1401 };
1402 UnlockSim.this.notifyAll();
1403 }
1404 Looper.loop();
1405 }
1406
1407 /*
1408 * Use PIN or PUK to unlock SIM card
1409 *
1410 * If PUK is null, unlock SIM card with PIN
1411 *
1412 * If PUK is not null, unlock SIM card with PUK and set PIN code
1413 */
Wink Saville9de0f752013-10-22 19:04:03 -07001414 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415
1416 while (mHandler == null) {
1417 try {
1418 wait();
1419 } catch (InterruptedException e) {
1420 Thread.currentThread().interrupt();
1421 }
1422 }
1423 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1424
1425 if (puk == null) {
1426 mSimCard.supplyPin(pin, callback);
1427 } else {
1428 mSimCard.supplyPuk(puk, pin, callback);
1429 }
1430
1431 while (!mDone) {
1432 try {
1433 Log.d(LOG_TAG, "wait for done");
1434 wait();
1435 } catch (InterruptedException e) {
1436 // Restore the interrupted status
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001441 int[] resultArray = new int[2];
1442 resultArray[0] = mResult;
1443 resultArray[1] = mRetryCount;
1444 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 }
1446 }
1447
1448 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001450
1451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 // No permission check needed here: this call is harmless, and it's
1455 // needed for the ServiceState.requestStateUpdate() call (which is
1456 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001457 final Phone phone = getPhone(subId);
1458 if (phone != null) {
1459 phone.updateServiceLocation();
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001463 @Override
1464 public boolean isRadioOn(String callingPackage) {
1465 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1470 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1471 return false;
1472 }
1473 return isRadioOnForSubscriber(subId);
1474 }
1475
1476 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1480 } else {
1481 return false;
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
1485 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
Wink Saville36469e72014-06-11 15:17:00 -07001489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 final Phone phone = getPhone(subId);
1493 if (phone != null) {
1494 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1495 }
Wink Saville36469e72014-06-11 15:17:00 -07001496 }
1497
1498 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001503 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001504 final Phone phone = getPhone(subId);
1505 if (phone == null) {
1506 return false;
1507 }
1508 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001509 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 return true;
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001515 public boolean needMobileRadioShutdown() {
1516 /*
1517 * If any of the Radios are available, it will need to be
1518 * shutdown. So return true if any Radio is available.
1519 */
1520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1521 Phone phone = PhoneFactory.getPhone(i);
1522 if (phone != null && phone.isRadioAvailable()) return true;
1523 }
1524 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1525 return false;
1526 }
1527
1528 public void shutdownMobileRadios() {
1529 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1530 logv("Shutting down Phone " + i);
1531 shutdownRadioUsingPhoneId(i);
1532 }
1533 }
1534
1535 private void shutdownRadioUsingPhoneId(int phoneId) {
1536 enforceModifyPermission();
1537 Phone phone = PhoneFactory.getPhone(phoneId);
1538 if (phone != null && phone.isRadioAvailable()) {
1539 phone.shutdownRadio();
1540 }
1541 }
1542
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001544 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001545 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1546 if (defaultPhone != null) {
1547 defaultPhone.setRadioPower(turnOn);
1548 return true;
1549 } else {
1550 loge("There's no default phone.");
1551 return false;
1552 }
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 phone.setRadioPower(turnOn);
1560 return true;
1561 } else {
1562 return false;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville36469e72014-06-11 15:17:00 -07001566 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 public boolean enableDataConnectivity() {
1569 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001570 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001573 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 return true;
1575 } else {
1576 return false;
1577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Wink Saville36469e72014-06-11 15:17:00 -07001580 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 public boolean disableDataConnectivity() {
1583 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001584 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 final Phone phone = getPhone(subId);
1586 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001587 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 return true;
1589 } else {
1590 return false;
1591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 }
1593
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001595 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 final Phone phone = getPhone(subId);
1597 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001598 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 } else {
1600 return false;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
1603
1604 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001606 }
1607
pkanwarae03a6b2016-11-06 20:37:09 -08001608 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001609 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1611 return;
1612 }
1613 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1614 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1615 };
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1620 return false;
1621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001626 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001629 public int getCallStateForSlot(int slotIndex) {
1630 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001631 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001632 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
1634
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001637 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001639 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001641 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 }
1644
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001647 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 if (phone != null) {
1649 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1650 } else {
1651 return TelephonyManager.DATA_ACTIVITY_NONE;
1652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001656 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001657 mPhone.getContext().getSystemService(AppOpsManager.class)
1658 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001659 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001660 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001661 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001664 if (DBG_LOC) log("getCellLocation: is active user");
1665 Bundle data = new Bundle();
1666 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1667 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 return null;
1669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001671 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1672 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1673 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001677 public String getNetworkCountryIsoForPhone(int phoneId) {
1678 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1679 // registered cell info, so return a NULL country instead.
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1683 if (TelephonyManager.NETWORK_TYPE_IWLAN
1684 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1685 return "";
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
1689 }
1690 return TelephonyManager.getTelephonyProperty(
1691 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1692 }
1693
1694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001696 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001700 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 mApp.enforceCallingOrSelfPermission(
1702 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 final Phone phone = getPhone(subId);
1704 if (phone != null) {
1705 phone.enableLocationUpdates();
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 @Override
1710 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001711 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001712 }
1713
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 mApp.enforceCallingOrSelfPermission(
1717 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.disableLocationUpdates();
1721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 }
1723
1724 @Override
1725 @SuppressWarnings("unchecked")
1726 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001727 mPhone.getContext().getSystemService(AppOpsManager.class)
1728 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001729 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001730 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001731 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
1733
1734 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1735 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1736 return null;
1737 }
Svetoslav64fad262015-04-14 14:35:21 -07001738
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001739 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001741 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001743 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1744 try {
1745 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1746 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1747 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1748 } catch (RuntimeException e) {
1749 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001751 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
1754
1755 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001756 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001757 mPhone.getContext().getSystemService(AppOpsManager.class)
1758 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001760 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001761 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 if (DBG_LOC) log("getAllCellInfo: is active user");
1765 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1766 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1767 for (Phone phone : PhoneFactory.getPhones()) {
1768 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1769 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001771 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001776 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001777 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1778 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001782 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001783 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1784 return null;
1785 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001786 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 return phone == null ? null : phone.getImei();
1788 }
1789
1790 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001791 public String getMeidForSlot(int slotIndex, String callingPackage) {
1792 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1793 return null;
1794 }
1795 Phone phone = PhoneFactory.getPhone(slotIndex);
1796 return phone == null ? null : phone.getMeid();
1797 }
1798
1799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001801 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1802 return null;
1803 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001804 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 return phone == null ? null : phone.getDeviceSvn();
1806 }
1807
fionaxuf32acdf2017-11-27 22:51:16 -08001808 @Override
1809 public int getSubscriptionCarrierId(int subId) {
1810 final Phone phone = getPhone(subId);
1811 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1812 }
1813
1814 @Override
1815 public String getSubscriptionCarrierName(int subId) {
1816 final Phone phone = getPhone(subId);
1817 return phone == null ? null : phone.getCarrierName();
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 //
1821 // Internal helper methods.
1822 //
1823
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001824 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1826 *
1827 * @throws SecurityException if the caller does not have the required permission
1828 */
1829 private void enforceModifyPermission() {
1830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1831 }
1832
1833 /**
Junda Liua2e36012014-07-09 18:30:01 -07001834 * Make sure either system app or the caller has carrier privilege.
1835 *
1836 * @throws SecurityException if the caller does not have the required permission/privilege
1837 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001838 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001839 int permission = mApp.checkCallingOrSelfPermission(
1840 android.Manifest.permission.MODIFY_PHONE_STATE);
1841 if (permission == PackageManager.PERMISSION_GRANTED) {
1842 return;
1843 }
1844
1845 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001846 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001847 }
1848
1849 /**
1850 * Make sure the caller has carrier privilege.
1851 *
1852 * @throws SecurityException if the caller does not have the required permission
1853 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001854 private void enforceCarrierPrivilege(int subId) {
1855 if (getCarrierPrivilegeStatus(subId) !=
1856 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001857 loge("No Carrier Privilege.");
1858 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001859 }
1860 }
1861
1862 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 * Make sure the caller has the CALL_PHONE permission.
1864 *
1865 * @throws SecurityException if the caller does not have the required permission
1866 */
1867 private void enforceCallPermission() {
1868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1869 }
1870
Stuart Scott8eef64f2015-04-08 15:13:54 -07001871 private void enforceConnectivityInternalPermission() {
1872 mApp.enforceCallingOrSelfPermission(
1873 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1874 "ConnectivityService");
1875 }
1876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 private String createTelUrl(String number) {
1878 if (TextUtils.isEmpty(number)) {
1879 return null;
1880 }
1881
Jake Hambye994d462014-02-03 13:10:13 -08001882 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001889 private static void logv(String msg) {
1890 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Ihab Awadf9e92732013-12-05 18:02:52 -08001893 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001899 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001903 public int getActivePhoneTypeForSlot(int slotIndex) {
1904 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 if (phone == null) {
1906 return PhoneConstants.PHONE_TYPE_NONE;
1907 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001908 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
1912 /**
1913 * Returns the CDMA ERI icon index to display
1914 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 @Override
1916 public int getCdmaEriIconIndex(String callingPackage) {
1917 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001918 }
1919
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001921 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1922 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1923 return -1;
1924 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 final Phone phone = getPhone(subId);
1926 if (phone != null) {
1927 return phone.getCdmaEriIconIndex();
1928 } else {
1929 return -1;
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 /**
1934 * Returns the CDMA ERI icon mode,
1935 * 0 - ON
1936 * 1 - FLASHING
1937 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001938 @Override
1939 public int getCdmaEriIconMode(String callingPackage) {
1940 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1945 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1946 return -1;
1947 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 return phone.getCdmaEriIconMode();
1951 } else {
1952 return -1;
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
1956 /**
1957 * Returns the CDMA ERI text,
1958 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 @Override
1960 public String getCdmaEriText(String callingPackage) {
1961 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001962 }
1963
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1966 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1967 return null;
1968 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 final Phone phone = getPhone(subId);
1970 if (phone != null) {
1971 return phone.getCdmaEriText();
1972 } else {
1973 return null;
1974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
1977 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001978 * Returns the CDMA MDN.
1979 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001982 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1985 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001986 } else {
1987 return null;
1988 }
1989 }
1990
1991 /**
1992 * Returns the CDMA MIN.
1993 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001995 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001996 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 final Phone phone = getPhone(subId);
1998 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1999 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002000 } else {
2001 return null;
2002 }
2003 }
2004
2005 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 * Returns true if CDMA provisioning needs to run.
2007 */
2008 public boolean needsOtaServiceProvisioning() {
2009 return mPhone.needsOtaServiceProvisioning();
2010 }
2011
2012 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002013 * Sets the voice mail number of a given subId.
2014 */
2015 @Override
2016 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002017 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002018 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2019 new Pair<String, String>(alphaTag, number), new Integer(subId));
2020 return success;
2021 }
2022
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002024 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2025 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2026 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2027 if (!TextUtils.equals(callingPackage, systemDialer)) {
2028 throw new SecurityException("caller must be system dialer");
2029 }
2030 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2031 if (phoneAccountHandle == null){
2032 return null;
2033 }
2034 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2035 }
2036
2037 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002038 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2040 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2041 return null;
2042 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002043 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2044 }
2045
2046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002047 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2048 VisualVoicemailSmsFilterSettings settings) {
2049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002050 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2052 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002059 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 }
2061
2062 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2064 String callingPackage, int subId) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002067 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 }
2069
2070 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002071 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002073 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002074 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2075 }
2076
2077 @Override
2078 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2079 String number, int port, String text, PendingIntent sentIntent) {
2080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002081 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002082 enforceSendSmsPermission();
2083 // Make the calls as the phone process.
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2087 if (port == 0) {
2088 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2089 sentIntent, null, false);
2090 } else {
2091 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2092 smsManager.sendDataMessageWithSelfPermissions(number, null,
2093 (short) port, data, sentIntent, null);
2094 }
2095 } finally {
2096 Binder.restoreCallingIdentity(identity);
2097 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002098 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002099 /**
fionaxu0152e512016-11-14 13:36:14 -08002100 * Sets the voice activation state of a given subId.
2101 */
2102 @Override
2103 public void setVoiceActivationState(int subId, int activationState) {
2104 enforceModifyPermissionOrCarrierPrivilege(subId);
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.setVoiceActivationState(activationState);
2108 } else {
2109 loge("setVoiceActivationState fails with invalid subId: " + subId);
2110 }
2111 }
2112
2113 /**
2114 * Sets the data activation state of a given subId.
2115 */
2116 @Override
2117 public void setDataActivationState(int subId, int activationState) {
2118 enforceModifyPermissionOrCarrierPrivilege(subId);
2119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setDataActivationState(activationState);
2122 } else {
2123 loge("setVoiceActivationState fails with invalid subId: " + subId);
2124 }
2125 }
2126
2127 /**
2128 * Returns the voice activation state of a given subId.
2129 */
2130 @Override
2131 public int getVoiceActivationState(int subId, String callingPackage) {
2132 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2133 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2134 }
2135 final Phone phone = getPhone(subId);
2136 if (phone != null) {
2137 return phone.getVoiceActivationState();
2138 } else {
2139 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2140 }
2141 }
2142
2143 /**
2144 * Returns the data activation state of a given subId.
2145 */
2146 @Override
2147 public int getDataActivationState(int subId, String callingPackage) {
2148 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2149 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2150 }
2151 final Phone phone = getPhone(subId);
2152 if (phone != null) {
2153 return phone.getDataActivationState();
2154 } else {
2155 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2156 }
2157 }
2158
2159 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 * Returns the unread count of voicemails
2161 */
2162 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002163 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002164 }
2165
2166 /**
2167 * Returns the unread count of voicemails for a subId
2168 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002169 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002170 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 final Phone phone = getPhone(subId);
2172 if (phone != null) {
2173 return phone.getVoiceMessageCount();
2174 } else {
2175 return 0;
2176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
2179 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002180 * returns true, if the device is in a state where both voice and data
2181 * are supported simultaneously. This can change based on location or network condition.
2182 */
2183 @Override
2184 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2185 final Phone phone = getPhone(subId);
2186 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2187 }
2188
2189 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002190 * Send the dialer code if called from the current default dialer or the caller has
2191 * carrier privilege.
2192 * @param inputCode The dialer code to send
2193 */
2194 @Override
2195 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2197 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2198 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2199 enforceCarrierPrivilege(getDefaultSubscription());
2200 }
2201 mPhone.sendDialerSpecialCode(inputCode);
2202 }
2203
2204 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002205 * Returns the data network type.
2206 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 *
2208 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2209 */
2210 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002211 public int getNetworkType() {
2212 final Phone phone = getPhone(getDefaultSubscription());
2213 if (phone != null) {
2214 return phone.getServiceState().getDataNetworkType();
2215 } else {
2216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2217 }
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
2220 /**
2221 * Returns the network type for a subId
2222 */
2223 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2225 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2227 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002228
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 return phone.getServiceState().getDataNetworkType();
2232 } else {
2233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
2237 /**
2238 * Returns the data network type
2239 */
2240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002241 public int getDataNetworkType(String callingPackage) {
2242 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002243 }
2244
2245 /**
2246 * Returns the data network type for a subId
2247 */
2248 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002249 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2250 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
2253
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 final Phone phone = getPhone(subId);
2255 if (phone != null) {
2256 return phone.getServiceState().getDataNetworkType();
2257 } else {
2258 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
2262 /**
Wink Saville36469e72014-06-11 15:17:00 -07002263 * Returns the Voice network type for a subId
2264 */
2265 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002266 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2267 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2269 }
2270
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 final Phone phone = getPhone(subId);
2272 if (phone != null) {
2273 return phone.getServiceState().getVoiceNetworkType();
2274 } else {
2275 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
2280 * @return true if a ICC card is present
2281 */
2282 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002283 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002284 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2285 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002286 }
2287
2288 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002289 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002290 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002292 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2293 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002294 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002295 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002296 } else {
2297 return false;
2298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
2301 /**
2302 * Return if the current radio is LTE on CDMA. This
2303 * is a tri-state return value as for a period of time
2304 * the mode may be unknown.
2305 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002308 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 @Override
2311 public int getLteOnCdmaMode(String callingPackage) {
2312 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2317 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2318 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2319 }
2320
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 final Phone phone = getPhone(subId);
2322 if (phone == null) {
2323 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2324 } else {
2325 return phone.getLteOnCdmaMode();
2326 }
Wink Saville36469e72014-06-11 15:17:00 -07002327 }
2328
2329 public void setPhone(Phone phone) {
2330 mPhone = phone;
2331 }
2332
2333 /**
2334 * {@hide}
2335 * Returns Default subId, 0 in the case of single standby.
2336 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002338 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Shishir Agrawala9f32182016-04-12 12:00:16 -07002341 private int getSlotForDefaultSubscription() {
2342 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2343 }
2344
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002346 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002348
2349 /**
2350 * @see android.telephony.TelephonyManager.WifiCallingChoices
2351 */
2352 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002353 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2354 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002355 }
2356
2357 /**
2358 * @see android.telephony.TelephonyManager.WifiCallingChoices
2359 */
2360 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002361 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2362 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2363 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002364 }
2365
Sailesh Nepald1e68152013-12-12 19:08:02 -08002366 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002367 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002368 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002369 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002370
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002372 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2373 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002374 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375
Derek Tan740e1672017-06-27 14:56:27 -07002376 if (TextUtils.equals(ISDR_AID, aid)) {
2377 // Only allows LPA to open logical channel to ISD-R.
2378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2379 ComponentInfo bestComponent =
2380 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2381 if (bestComponent == null
2382 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2383 loge("The calling package is not allowed to access ISD-R.");
2384 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2385 }
2386 }
2387
2388 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002389 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002390 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002391 if (DBG) log("iccOpenLogicalChannel: " + response);
2392 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002393 }
2394
2395 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 public boolean iccCloseLogicalChannel(int subId, int channel) {
2397 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400 if (channel < 0) {
2401 return false;
2402 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002403 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002404 if (DBG) log("iccCloseLogicalChannel: " + success);
2405 return success;
2406 }
2407
2408 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002411 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412
2413 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2415 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002416 " data=" + data);
2417 }
2418
2419 if (channel < 0) {
2420 return "";
2421 }
2422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002423 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2426
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427 // Append the returned status code to the end of the response payload.
2428 String s = Integer.toHexString(
2429 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002430 if (response.payload != null) {
2431 s = IccUtils.bytesToHexString(response.payload) + s;
2432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002433 return s;
2434 }
Jake Hambye994d462014-02-03 13:10:13 -08002435
Evan Charltonc66da362014-05-16 14:06:40 -07002436 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002437 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2438 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002440
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002441 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2442 && TextUtils.equals(ISDR_AID, data)) {
2443 // Only allows LPA to select ISD-R.
2444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2445 ComponentInfo bestComponent =
2446 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2447 if (bestComponent == null
2448 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2449 loge("The calling package is not allowed to select ISD-R.");
2450 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2451 }
2452 }
2453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002454 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002455 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2456 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457 }
2458
2459 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002461 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 // Append the returned status code to the end of the response payload.
2464 String s = Integer.toHexString(
2465 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002466 if (response.payload != null) {
2467 s = IccUtils.bytesToHexString(response.payload) + s;
2468 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 return s;
2470 }
2471
2472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002475 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476
2477 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002478 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002479 p1 + " " + p2 + " " + p3 + ":" + filePath);
2480 }
2481
2482 IccIoResult response =
2483 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2485 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486
2487 if (DBG) {
2488 log("Exchange SIM_IO [R]" + response);
2489 }
2490
2491 byte[] result = null;
2492 int length = 2;
2493 if (response.payload != null) {
2494 length = 2 + response.payload.length;
2495 result = new byte[length];
2496 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2497 } else {
2498 result = new byte[length];
2499 }
2500
2501 result[length - 1] = (byte) response.sw2;
2502 result[length - 2] = (byte) response.sw1;
2503 return result;
2504 }
2505
Nathan Haroldb3014052017-01-25 15:57:32 -08002506 /**
2507 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2508 * on a particular subscription
2509 */
2510 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2512 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002513 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2514 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2515 return null;
2516 }
2517 Object response = sendRequest(
2518 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2519 if (response instanceof String[]) {
2520 return (String[]) response;
2521 }
2522 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2523 return null;
2524 }
2525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002527 public String sendEnvelopeWithStatus(int subId, String content) {
2528 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002529
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002530 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002531 if (response.payload == null) {
2532 return "";
2533 }
2534
2535 // Append the returned status code to the end of the response payload.
2536 String s = Integer.toHexString(
2537 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2538 s = IccUtils.bytesToHexString(response.payload) + s;
2539 return s;
2540 }
2541
Jake Hambye994d462014-02-03 13:10:13 -08002542 /**
2543 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2544 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2545 *
2546 * @param itemID the ID of the item to read
2547 * @return the NV item as a String, or null on error.
2548 */
2549 @Override
2550 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002551 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002552 if (DBG) log("nvReadItem: item " + itemID);
2553 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2554 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2555 return value;
2556 }
2557
2558 /**
2559 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2560 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2561 *
2562 * @param itemID the ID of the item to read
2563 * @param itemValue the value to write, as a String
2564 * @return true on success; false on any failure
2565 */
2566 @Override
2567 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002568 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002569 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2570 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2571 new Pair<Integer, String>(itemID, itemValue));
2572 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2573 return success;
2574 }
2575
2576 /**
2577 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2578 * Used for device configuration by some CDMA operators.
2579 *
2580 * @param preferredRoamingList byte array containing the new PRL
2581 * @return true on success; false on any failure
2582 */
2583 @Override
2584 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002585 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002586 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2587 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2588 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2589 return success;
2590 }
2591
2592 /**
2593 * Perform the specified type of NV config reset.
2594 * Used for device configuration by some CDMA operators.
2595 *
2596 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2597 * @return true on success; false on any failure
2598 */
2599 @Override
2600 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002601 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002602 if (DBG) log("nvResetConfig: type " + resetType);
2603 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2604 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2605 return success;
2606 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002607
2608 /**
Wink Saville36469e72014-06-11 15:17:00 -07002609 * {@hide}
2610 * Returns Default sim, 0 in the case of single standby.
2611 */
2612 public int getDefaultSim() {
2613 //TODO Need to get it from Telephony Devcontroller
2614 return 0;
2615 }
2616
Svet Ganovb320e182015-04-16 12:30:10 -07002617 public String[] getPcscfAddress(String apnType, String callingPackage) {
2618 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2619 return new String[0];
2620 }
2621
2622
ram87fca6f2014-07-18 18:58:44 +05302623 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Brad Ebinger51f743a2017-01-23 13:50:20 -08002626 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002627 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2628 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002629 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002630 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002631 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002632 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002633 }
2634
2635 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002636 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2637 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002638 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002639 public void disableIms(int slotId) {
2640 enforceModifyPermission();
2641 PhoneFactory.getImsResolver().disableIms(slotId);
2642 }
2643
2644 /**
2645 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2646 * feature or {@link null} if the service is not available. If the feature is available, the
2647 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2648 */
2649 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002650 IImsServiceFeatureCallback callback) {
2651 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002652 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002653 }
2654
2655 /**
2656 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2657 * feature during emergency calling or {@link null} if the service is not available. If the
2658 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2659 * listener for feature updates.
2660 */
2661 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2662 enforceModifyPermission();
2663 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002664 }
2665
Brad Ebinger7e934f52017-12-14 14:26:15 -08002666 /**
2667 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2668 * specified.
2669 */
2670 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2671 enforceModifyPermission();
2672 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2673 }
2674
Brad Ebingera12246d2018-01-16 09:39:35 -08002675 /**
2676 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2677 * specified.
2678 */
2679 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2680 enforceModifyPermission();
2681 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2682 }
2683
Wink Saville36469e72014-06-11 15:17:00 -07002684 public void setImsRegistrationState(boolean registered) {
2685 enforceModifyPermission();
2686 mPhone.setImsRegistrationState(registered);
2687 }
2688
2689 /**
Stuart Scott54788802015-03-30 13:18:01 -07002690 * Set the network selection mode to automatic.
2691 *
2692 */
2693 @Override
2694 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002695 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002696 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2697 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2698 }
2699
2700 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002701 * Set the network selection mode to manual with the selected carrier.
2702 */
2703 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002704 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002705 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002706 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002707 OperatorInfo operator = new OperatorInfo(
2708 /* operatorAlphaLong */ "",
2709 /* operatorAlphaShort */ "",
2710 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002711 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002712 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2713 persistSelection);
2714 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002715 }
2716
2717 /**
2718 * Scans for available networks.
2719 */
2720 @Override
2721 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002722 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002723 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2724 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2725 CMD_PERFORM_NETWORK_SCAN, null, subId);
2726 return result;
2727 }
2728
2729 /**
yinxub1bed742017-04-17 11:45:04 -07002730 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002731 *
yinxub1bed742017-04-17 11:45:04 -07002732 * @param subId id of the subscription
2733 * @param request contains the radio access networks with bands/channels to scan
2734 * @param messenger callback messenger for scan results or errors
2735 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002736 * @return the id of the requested scan which can be used to stop the scan.
2737 */
2738 @Override
2739 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2740 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002741 enforceModifyPermissionOrCarrierPrivilege(subId);
2742 return mNetworkScanRequestTracker.startNetworkScan(
2743 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002744 }
2745
2746 /**
2747 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002748 *
2749 * @param subId id of the subscription
2750 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002751 */
2752 @Override
2753 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002754 enforceModifyPermissionOrCarrierPrivilege(subId);
2755 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002756 }
2757
2758 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002759 * Get the calculated preferred network type.
2760 * Used for debugging incorrect network type.
2761 *
2762 * @return the preferred network type, defined in RILConstants.java.
2763 */
2764 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002765 public int getCalculatedPreferredNetworkType(String callingPackage) {
2766 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2767 return RILConstants.PREFERRED_NETWORK_MODE;
2768 }
2769
Amit Mahajan43330e02014-11-18 11:54:45 -08002770 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002771 }
2772
2773 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002774 * Get the preferred network type.
2775 * Used for device configuration by some CDMA operators.
2776 *
2777 * @return the preferred network type, defined in RILConstants.java.
2778 */
2779 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002780 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002781 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002782 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002783 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002784 int networkType = (result != null ? result[0] : -1);
2785 if (DBG) log("getPreferredNetworkType: " + networkType);
2786 return networkType;
2787 }
2788
2789 /**
2790 * Set the preferred network type.
2791 * Used for device configuration by some CDMA operators.
2792 *
2793 * @param networkType the preferred network type, defined in RILConstants.java.
2794 * @return true on success; false on any failure.
2795 */
2796 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002797 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002798 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002799 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2800 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002801 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002802 if (success) {
2803 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002804 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002805 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002806 return success;
2807 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002808
2809 /**
Junda Liu475951f2014-11-07 16:45:03 -08002810 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2811 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2812 * tethering.
2813 *
2814 * @return 0: Not required. 1: required. 2: Not set.
2815 * @hide
2816 */
2817 @Override
2818 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002819 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002820 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2821 Settings.Global.TETHER_DUN_REQUIRED, 2);
2822 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2823 // config_tether_apndata.
2824 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2825 dunRequired = 1;
2826 }
2827 return dunRequired;
2828 }
2829
2830 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002831 * Set mobile data enabled
2832 * Used by the user through settings etc to turn on/off mobile data
2833 *
2834 * @param enable {@code true} turn turn data on, else {@code false}
2835 */
2836 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002837 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002838 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002839 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002840 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002841 Phone phone = PhoneFactory.getPhone(phoneId);
2842 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002843 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2844 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002845 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002846 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002847 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002848 }
2849
2850 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002851 * Get the user enabled state of Mobile Data.
2852 *
2853 * TODO: remove and use isUserDataEnabled.
2854 * This can't be removed now because some vendor codes
2855 * calls through ITelephony directly while they should
2856 * use TelephonyManager.
2857 *
2858 * @return true on enabled
2859 */
2860 @Override
2861 public boolean getDataEnabled(int subId) {
2862 return isUserDataEnabled(subId);
2863 }
2864
2865 /**
2866 * Get whether mobile data is enabled per user setting.
2867 *
2868 * There are other factors deciding whether mobile data is actually enabled, but they are
2869 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002870 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002871 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002872 *
2873 * @return {@code true} if data is enabled else {@code false}
2874 */
2875 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002876 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002877 try {
2878 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2879 null);
2880 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002881 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002882 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002883 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002884 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002885 Phone phone = PhoneFactory.getPhone(phoneId);
2886 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002887 boolean retVal = phone.isUserDataEnabled();
2888 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002889 return retVal;
2890 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002891 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2892 return false;
2893 }
2894 }
2895
2896 /**
2897 * Get whether mobile data is enabled.
2898 *
2899 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2900 * whether mobile data is actually enabled.
2901 *
2902 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2903 *
2904 * @return {@code true} if data is enabled else {@code false}
2905 */
2906 @Override
2907 public boolean isDataEnabled(int subId) {
2908 try {
2909 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2910 null);
2911 } catch (Exception e) {
2912 enforceModifyPermissionOrCarrierPrivilege(subId);
2913 }
2914 int phoneId = mSubscriptionController.getPhoneId(subId);
2915 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2916 Phone phone = PhoneFactory.getPhone(phoneId);
2917 if (phone != null) {
2918 boolean retVal = phone.isDataEnabled();
2919 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2920 return retVal;
2921 } else {
2922 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002923 return false;
2924 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002925 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002926
2927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002928 public int getCarrierPrivilegeStatus(int subId) {
2929 final Phone phone = getPhone(subId);
2930 if (phone == null) {
2931 loge("getCarrierPrivilegeStatus: Invalid subId");
2932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2933 }
2934 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002935 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002936 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002937 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2938 }
2939 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002940 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002941 }
Junda Liu29340342014-07-10 15:23:27 -07002942
2943 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002944 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002945 if (TextUtils.isEmpty(pkgName))
2946 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002947 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002948 if (card == null) {
2949 loge("checkCarrierPrivilegesForPackage: No UICC");
2950 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2951 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002952 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2953 }
2954
2955 @Override
2956 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002957 if (TextUtils.isEmpty(pkgName))
2958 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002959 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2960 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2961 UiccCard card = UiccController.getInstance().getUiccCard(i);
2962 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002963 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002964 continue;
2965 }
2966
2967 result = card.getCarrierPrivilegeStatus(
2968 mPhone.getContext().getPackageManager(), pkgName);
2969 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2970 break;
2971 }
2972 }
2973
2974 return result;
Junda Liu29340342014-07-10 15:23:27 -07002975 }
Derek Tan89e89d42014-07-08 17:00:10 -07002976
2977 @Override
Junda Liue64de782015-04-16 17:19:16 -07002978 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2979 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2980 loge("phoneId " + phoneId + " is not valid.");
2981 return null;
2982 }
2983 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002984 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002985 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002986 return null ;
2987 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002988 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002989 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002990 }
2991
Amith Yamasani6e118872016-02-19 12:53:51 -08002992 @Override
2993 public List<String> getPackagesWithCarrierPrivileges() {
2994 PackageManager pm = mPhone.getContext().getPackageManager();
2995 List<String> privilegedPackages = new ArrayList<>();
2996 List<PackageInfo> packages = null;
2997 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2998 UiccCard card = UiccController.getInstance().getUiccCard(i);
2999 if (card == null) {
3000 // No UICC in that slot.
3001 continue;
3002 }
3003 if (card.hasCarrierPrivilegeRules()) {
3004 if (packages == null) {
3005 // Only check packages in user 0 for now
3006 packages = pm.getInstalledPackagesAsUser(
3007 PackageManager.MATCH_DISABLED_COMPONENTS
3008 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3009 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3010 }
3011 for (int p = packages.size() - 1; p >= 0; p--) {
3012 PackageInfo pkgInfo = packages.get(p);
3013 if (pkgInfo != null && pkgInfo.packageName != null
3014 && card.getCarrierPrivilegeStatus(pkgInfo)
3015 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3016 privilegedPackages.add(pkgInfo.packageName);
3017 }
3018 }
3019 }
3020 }
3021 return privilegedPackages;
3022 }
3023
Wink Savilleb564aae2014-10-23 10:18:09 -07003024 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003025 final Phone phone = getPhone(subId);
3026 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003027 if (card == null) {
3028 loge("getIccId: No UICC");
3029 return null;
3030 }
3031 String iccId = card.getIccId();
3032 if (TextUtils.isEmpty(iccId)) {
3033 loge("getIccId: ICC ID is null or empty.");
3034 return null;
3035 }
3036 return iccId;
3037 }
3038
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003039 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003040 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3041 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003042 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003043
Jeff Sharkey85190e62014-12-05 09:40:12 -08003044 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 final Phone phone = getPhone(subId);
3046 if (phone == null) {
3047 return false;
3048 }
3049 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003050
3051 if (DBG_MERGE) {
3052 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3053 + subscriberId + " to " + number);
3054 }
3055
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003056 if (TextUtils.isEmpty(iccId)) {
3057 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003058 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003059
Jeff Sharkey85190e62014-12-05 09:40:12 -08003060 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3061
3062 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003063 if (alphaTag == null) {
3064 editor.remove(alphaTagPrefKey);
3065 } else {
3066 editor.putString(alphaTagPrefKey, alphaTag);
3067 }
3068
Jeff Sharkey85190e62014-12-05 09:40:12 -08003069 // Record both the line number and IMSI for this ICCID, since we need to
3070 // track all merged IMSIs based on line number
3071 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3072 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003073 if (number == null) {
3074 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003075 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003076 } else {
3077 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003078 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003079 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003080
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003081 editor.commit();
3082 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003083 }
3084
3085 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003086 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003087 // This is open to apps with WRITE_SMS.
3088 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003089 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003090 return null;
3091 }
Derek Tan97ebb422014-09-05 16:55:38 -07003092
3093 String iccId = getIccId(subId);
3094 if (iccId != null) {
3095 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003096 if (DBG_MERGE) {
3097 log("getLine1NumberForDisplay returning " +
3098 mTelephonySharedPreferences.getString(numberPrefKey, null));
3099 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003100 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003101 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003102 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003103 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003104 }
3105
3106 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003107 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3108 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3109 return null;
3110 }
Derek Tan97ebb422014-09-05 16:55:38 -07003111
3112 String iccId = getIccId(subId);
3113 if (iccId != null) {
3114 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003115 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003116 }
Derek Tan97ebb422014-09-05 16:55:38 -07003117 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003118 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003119
3120 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003121 public String[] getMergedSubscriberIds(String callingPackage) {
3122 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3123 return null;
3124 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003125 final Context context = mPhone.getContext();
3126 final TelephonyManager tele = TelephonyManager.from(context);
3127 final SubscriptionManager sub = SubscriptionManager.from(context);
3128
3129 // Figure out what subscribers are currently active
3130 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003131 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3132 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final int[] subIds = sub.getActiveSubscriptionIdList();
3136 for (int subId : subIds) {
3137 activeSubscriberIds.add(tele.getSubscriberId(subId));
3138 }
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003141 }
3142
3143 // First pass, find a number override for an active subscriber
3144 String mergeNumber = null;
3145 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3146 for (String key : prefs.keySet()) {
3147 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3148 final String subscriberId = (String) prefs.get(key);
3149 if (activeSubscriberIds.contains(subscriberId)) {
3150 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3151 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3152 mergeNumber = (String) prefs.get(numberKey);
3153 if (DBG_MERGE) {
3154 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3155 + " for active subscriber " + subscriberId);
3156 }
3157 if (!TextUtils.isEmpty(mergeNumber)) {
3158 break;
3159 }
3160 }
3161 }
3162 }
3163
3164 // Shortcut when no active merged subscribers
3165 if (TextUtils.isEmpty(mergeNumber)) {
3166 return null;
3167 }
3168
3169 // Second pass, find all subscribers under that line override
3170 final ArraySet<String> result = new ArraySet<>();
3171 for (String key : prefs.keySet()) {
3172 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3173 final String number = (String) prefs.get(key);
3174 if (mergeNumber.equals(number)) {
3175 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3176 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3177 final String subscriberId = (String) prefs.get(subscriberKey);
3178 if (!TextUtils.isEmpty(subscriberId)) {
3179 result.add(subscriberId);
3180 }
3181 }
3182 }
3183 }
3184
3185 final String[] resultArray = result.toArray(new String[result.size()]);
3186 Arrays.sort(resultArray);
3187 if (DBG_MERGE) {
3188 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3189 }
3190 return resultArray;
3191 }
3192
3193 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003194 public boolean setOperatorBrandOverride(int subId, String brand) {
3195 enforceCarrierPrivilege(subId);
3196 final Phone phone = getPhone(subId);
3197 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003198 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003199
3200 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003201 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003202 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3203 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003204 enforceCarrierPrivilege(subId);
3205 final Phone phone = getPhone(subId);
3206 if (phone == null) {
3207 return false;
3208 }
3209 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003210 cdmaNonRoamingList);
3211 }
3212
3213 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003214 public void setRadioCapability(RadioAccessFamily[] rafs) {
3215 try {
3216 ProxyController.getInstance().setRadioCapability(rafs);
3217 } catch (RuntimeException e) {
3218 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3219 }
3220 }
3221
3222 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003223 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3224 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3225 return RadioAccessFamily.RAF_UNKNOWN;
3226 }
3227
Wink Saville5d475dd2014-10-17 15:00:58 -07003228 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3229 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003230
3231 @Override
3232 public void enableVideoCalling(boolean enable) {
3233 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003234 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003235 }
3236
3237 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003238 public boolean isVideoCallingEnabled(String callingPackage) {
3239 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3240 return false;
3241 }
3242
Andrew Lee77527ac2014-10-21 16:57:39 -07003243 // Check the user preference and the system-level IMS setting. Even if the user has
3244 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3245 // In the long run, we may instead need to check if there exists a connection service
3246 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003247 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3248 return imsManager.isVtEnabledByPlatform()
3249 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3250 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003251 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003252
Andrew Leea1239f22015-03-02 17:44:07 -08003253 @Override
3254 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003255 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003256 }
3257
3258 @Override
3259 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003260 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003261 }
3262
Andrew Lee9431b832015-03-09 18:46:45 -07003263 @Override
3264 public boolean isTtyModeSupported() {
3265 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3266 TelephonyManager telephonyManager =
3267 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003268 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003269 }
3270
3271 @Override
3272 public boolean isHearingAidCompatibilitySupported() {
3273 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3274 }
3275
Hall Liu73714012018-01-22 19:15:32 -08003276 public boolean isRttSupported() {
3277 boolean isCarrierSupported =
3278 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3279 boolean isDeviceSupported =
3280 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3281 return isCarrierSupported && isDeviceSupported;
3282 }
3283
Sanket Padawe7310cc72015-01-14 09:53:20 -08003284 /**
3285 * Returns the unique device ID of phone, for example, the IMEI for
3286 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3287 *
3288 * <p>Requires Permission:
3289 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3290 */
3291 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003292 public String getDeviceId(String callingPackage) {
3293 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3294 return null;
3295 }
3296
Sanket Padawe7310cc72015-01-14 09:53:20 -08003297 final Phone phone = PhoneFactory.getPhone(0);
3298 if (phone != null) {
3299 return phone.getDeviceId();
3300 } else {
3301 return null;
3302 }
3303 }
3304
Ping Sun014fe8e2016-03-02 19:16:45 +08003305 /**
3306 * {@hide}
3307 * Returns the IMS Registration Status on a particular subid
3308 *
3309 * @param subId
3310 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003311 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003312 Phone phone = getPhone(subId);
3313 if (phone != null) {
3314 return phone.isImsRegistered();
3315 } else {
3316 return false;
3317 }
3318 }
3319
Santos Cordon7a1885b2015-02-03 11:15:19 -08003320 @Override
3321 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3322 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3323 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003324
Brad Ebingere21f25f2018-02-08 16:11:32 -08003325 /**
3326 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003327 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003328 public boolean isWifiCallingAvailable(int subId) {
3329 Phone phone = getPhone(subId);
3330 if (phone != null) {
3331 return phone.isWifiCallingEnabled();
3332 } else {
3333 return false;
3334 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003335 }
3336
Brad Ebingere21f25f2018-02-08 16:11:32 -08003337 /**
3338 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003339 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003340 public boolean isVolteAvailable(int subId) {
3341 Phone phone = getPhone(subId);
3342 if (phone != null) {
3343 return phone.isVolteEnabled();
3344 } else {
3345 return false;
3346 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003347 }
Svet Ganovb320e182015-04-16 12:30:10 -07003348
Brad Ebingere21f25f2018-02-08 16:11:32 -08003349 /**
3350 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003351 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003352 public boolean isVideoTelephonyAvailable(int subId) {
3353 Phone phone = getPhone(subId);
3354 if (phone != null) {
3355 return phone.isVideoEnabled();
3356 } else {
3357 return false;
3358 }
3359 }
3360
3361 /**
3362 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3363 * defined in {@link ImsRegistrationImplBase}.
3364 */
3365 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3366 Phone phone = getPhone(subId);
3367 if (phone != null) {
3368 return phone.getImsRegistrationTech();
3369 } else {
3370 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3371 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003372 }
3373
Svet Ganovb320e182015-04-16 12:30:10 -07003374 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003375 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003376 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003377 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3378
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003379 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003380 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003381 } catch (SecurityException e) {
3382 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3383 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003384 }
Svet Ganovb320e182015-04-16 12:30:10 -07003385
3386 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3387 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3388 return false;
3389 }
3390
3391 return true;
3392 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003393
Makoto Onukifee69342015-06-29 14:44:50 -07003394 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003395 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003396 */
3397 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003398 // Default SMS app can always read it.
3399 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3400 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3401 return true;
3402 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003403
Makoto Onukie4072d12015-08-03 15:12:23 -07003404 try {
3405 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003406 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003407 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003408 // Can be read with READ_SMS too.
3409 try {
3410 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3411 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3412 if (opCode != AppOpsManager.OP_NONE) {
3413 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3414 == AppOpsManager.MODE_ALLOWED;
3415 } else {
3416 return true;
3417 }
3418 } catch (SecurityException readSmsSecurityException) {
3419 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003420 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003421 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003423 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003424 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003425 if (opCode != AppOpsManager.OP_NONE) {
3426 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3427 == AppOpsManager.MODE_ALLOWED;
3428 } else {
3429 return true;
3430 }
3431 } catch (SecurityException readPhoneNumberSecurityException) {
3432 }
3433
3434 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3435 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3436 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003437 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003438 }
3439
Stuart Scott8eef64f2015-04-08 15:13:54 -07003440 @Override
3441 public void factoryReset(int subId) {
3442 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003443 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3444 return;
3445 }
3446
Svet Ganovcc087f82015-05-12 20:35:54 -07003447 final long identity = Binder.clearCallingIdentity();
3448 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003449 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3450 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003451 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003452 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003453 // Set network selection mode to automatic
3454 setNetworkSelectionModeAutomatic(subId);
3455 // Set preferred mobile network type to the best available
3456 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3457 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003458 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003459 }
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003462 }
3463 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003464
3465 @Override
3466 public String getLocaleFromDefaultSim() {
3467 // We query all subscriptions instead of just the active ones, because
3468 // this might be called early on in the provisioning flow when the
3469 // subscriptions potentially aren't active yet.
3470 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3471 if (slist == null || slist.isEmpty()) {
3472 return null;
3473 }
3474
3475 // This function may be called very early, say, from the setup wizard, at
3476 // which point we won't have a default subscription set. If that's the case
3477 // we just choose the first, which will be valid in "most cases".
3478 final int defaultSubId = getDefaultSubscription();
3479 SubscriptionInfo info = null;
3480 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3481 info = slist.get(0);
3482 } else {
3483 for (SubscriptionInfo item : slist) {
3484 if (item.getSubscriptionId() == defaultSubId) {
3485 info = item;
3486 break;
3487 }
3488 }
3489
3490 if (info == null) {
3491 return null;
3492 }
3493 }
3494
3495 // Try and fetch the locale from the carrier properties or from the SIM language
3496 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003497 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003498 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003499 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003500 if (defaultPhone != null) {
3501 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3502 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003503 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003504 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3505 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003506 } else {
3507 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003508 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003509 }
3510 }
3511
Narayan Kamath011676f2015-07-29 12:04:08 +01003512 // The SIM language preferences only store a language (e.g. fr = French), not an
3513 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3514 // the SIM and carrier preferences does not include a country we add the country
3515 // determined from the SIM MCC to provide an exact locale.
3516 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003517 if (mccLocale != null) {
3518 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3519 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003520 }
3521
Tony Hill183b2de2015-06-24 14:53:58 +01003522 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003523 return null;
3524 }
3525
3526 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 return mSubscriptionController.getAllSubInfoList(
3530 mPhone.getContext().getOpPackageName());
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
3534 }
3535
3536 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 return mSubscriptionController.getActiveSubscriptionInfoList(
3540 mPhone.getContext().getOpPackageName());
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003545
3546 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003547 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3548 * representing the state of the modem.
3549 *
3550 * NOTE: This clears the modem state, so there should only every be one caller.
3551 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003552 */
3553 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003554 public void requestModemActivityInfo(ResultReceiver result) {
3555 enforceModifyPermission();
3556
3557 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3558 Bundle bundle = new Bundle();
3559 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3560 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003561 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003562
3563 /**
3564 * {@hide}
3565 * Returns the service state information on specified subscription.
3566 */
3567 @Override
3568 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3569
3570 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3571 return null;
3572 }
3573
3574 final Phone phone = getPhone(subId);
3575 if (phone == null) {
3576 return null;
3577 }
3578
3579 return phone.getServiceState();
3580 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003581
3582 /**
3583 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3584 *
3585 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3586 * voicemail ringtone.
3587 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3588 * PhoneAccount.
3589 */
3590 @Override
3591 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003592 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003593 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003594 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003595 }
3596
fionaxu7ed723d2017-05-30 18:58:54 -07003597 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003598 }
3599
3600 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003601 * Sets the per-account voicemail ringtone.
3602 *
3603 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3604 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3605 *
3606 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3607 * voicemail ringtone.
3608 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3609 * PhoneAccount.
3610 */
3611 @Override
3612 public void setVoicemailRingtoneUri(String callingPackage,
3613 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3615 if (!TextUtils.equals(callingPackage,
3616 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3617 enforceModifyPermissionOrCarrierPrivilege(
3618 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3619 }
3620 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3621 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003622 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003623 }
fionaxu7ed723d2017-05-30 18:58:54 -07003624 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003625 }
3626
3627 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003628 * Returns whether vibration is set for voicemail notification in Phone settings.
3629 *
3630 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3631 * voicemail vibration setting.
3632 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3633 */
3634 @Override
3635 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003636 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003637 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003638 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003639 }
3640
fionaxu7ed723d2017-05-30 18:58:54 -07003641 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003642 }
3643
Youhan Wange64578a2016-05-02 15:32:42 -07003644 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003645 * Sets the per-account voicemail vibration.
3646 *
3647 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3648 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3649 *
3650 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3651 * voicemail vibration setting.
3652 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3653 * specific PhoneAccount.
3654 */
3655 @Override
3656 public void setVoicemailVibrationEnabled(String callingPackage,
3657 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3659 if (!TextUtils.equals(callingPackage,
3660 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3661 enforceModifyPermissionOrCarrierPrivilege(
3662 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3663 }
3664
3665 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3666 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003667 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003668 }
fionaxu7ed723d2017-05-30 18:58:54 -07003669 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003670 }
3671
3672 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003673 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3674 *
3675 * @throws SecurityException if the caller does not have the required permission
3676 */
3677 private void enforceReadPrivilegedPermission() {
3678 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3679 null);
3680 }
3681
3682 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003683 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3684 * permission.
3685 *
3686 * @throws SecurityException if the caller does not have the required permission
3687 */
3688 private void enforceSendSmsPermission() {
3689 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3690 }
3691
3692 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003693 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003694 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003695 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003696 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003697 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003698 ComponentName componentName =
3699 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3700 if(componentName == null) {
3701 throw new SecurityException("Caller not current active visual voicemail package[null]");
3702 }
3703 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003704 if (!callingPackage.equals(vvmPackage)) {
3705 throw new SecurityException("Caller not current active visual voicemail package[" +
3706 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003707 }
3708 }
3709
3710 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003711 * Return the application ID for the app type.
3712 *
3713 * @param subId the subscription ID that this request applies to.
3714 * @param appType the uicc app type.
3715 * @return Application ID for specificied app type, or null if no uicc.
3716 */
3717 @Override
3718 public String getAidForAppType(int subId, int appType) {
3719 enforceReadPrivilegedPermission();
3720 Phone phone = getPhone(subId);
3721 if (phone == null) {
3722 return null;
3723 }
3724 String aid = null;
3725 try {
3726 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3727 .getApplicationByType(appType).getAid();
3728 } catch (Exception e) {
3729 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3730 }
3731 return aid;
3732 }
3733
Youhan Wang4001d252016-05-11 10:29:41 -07003734 /**
3735 * Return the Electronic Serial Number.
3736 *
3737 * @param subId the subscription ID that this request applies to.
3738 * @return ESN or null if error.
3739 */
3740 @Override
3741 public String getEsn(int subId) {
3742 enforceReadPrivilegedPermission();
3743 Phone phone = getPhone(subId);
3744 if (phone == null) {
3745 return null;
3746 }
3747 String esn = null;
3748 try {
3749 esn = phone.getEsn();
3750 } catch (Exception e) {
3751 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3752 }
3753 return esn;
3754 }
3755
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003756 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003757 * Return the Preferred Roaming List Version.
3758 *
3759 * @param subId the subscription ID that this request applies to.
3760 * @return PRLVersion or null if error.
3761 */
3762 @Override
3763 public String getCdmaPrlVersion(int subId) {
3764 enforceReadPrivilegedPermission();
3765 Phone phone = getPhone(subId);
3766 if (phone == null) {
3767 return null;
3768 }
3769 String cdmaPrlVersion = null;
3770 try {
3771 cdmaPrlVersion = phone.getCdmaPrlVersion();
3772 } catch (Exception e) {
3773 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3774 }
3775 return cdmaPrlVersion;
3776 }
3777
3778 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003779 * Get snapshot of Telephony histograms
3780 * @return List of Telephony histograms
3781 * @hide
3782 */
3783 @Override
3784 public List<TelephonyHistogram> getTelephonyHistograms() {
3785 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3786 return RIL.getTelephonyRILTimingHistograms();
3787 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003788
3789 /**
3790 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003791 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003792 * Require system privileges. In the future we may add this to carrier APIs.
3793 *
3794 * @return The number of carriers set successfully, should match length of carriers
3795 */
3796 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003797 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003798 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003799
Meng Wang9b7c4e92017-02-17 11:41:27 -08003800 if (carriers == null) {
3801 throw new NullPointerException("carriers cannot be null");
3802 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003803
3804 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003805 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3806 return retVal[0];
3807 }
3808
3809 /**
3810 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003811 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003812 * Require system privileges. In the future we may add this to carrier APIs.
3813 *
3814 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3815 * means all carriers are allowed.
3816 */
3817 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003818 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003819 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003820 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003821 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3822 }
3823
fionaxu59545b42016-05-25 15:53:37 -07003824 /**
3825 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3826 * @param subId the subscription ID that this action applies to.
3827 * @param enabled control enable or disable metered apns.
3828 * {@hide}
3829 */
3830 @Override
3831 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3832 enforceModifyPermission();
3833 final Phone phone = getPhone(subId);
3834 if (phone == null) {
3835 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3836 return;
3837 }
3838 try {
3839 phone.carrierActionSetMeteredApnsEnabled(enabled);
3840 } catch (Exception e) {
3841 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3842 }
3843 }
3844
3845 /**
3846 * Action set from carrier signalling broadcast receivers to enable/disable radio
3847 * @param subId the subscription ID that this action applies to.
3848 * @param enabled control enable or disable radio.
3849 * {@hide}
3850 */
3851 @Override
3852 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3853 enforceModifyPermission();
3854 final Phone phone = getPhone(subId);
3855 if (phone == null) {
3856 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3857 return;
3858 }
3859 try {
3860 phone.carrierActionSetRadioEnabled(enabled);
3861 } catch (Exception e) {
3862 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3863 }
3864 }
3865
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003866 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003867 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3868 * network status based on which carrier apps could apply actions accordingly,
3869 * enable/disable default url handler for example.
3870 *
3871 * @param subId the subscription ID that this action applies to.
3872 * @param report control start/stop reporting the default network status.
3873 * {@hide}
3874 */
3875 @Override
3876 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3877 enforceModifyPermission();
3878 final Phone phone = getPhone(subId);
3879 if (phone == null) {
3880 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3881 return;
3882 }
3883 try {
3884 phone.carrierActionReportDefaultNetworkStatus(report);
3885 } catch (Exception e) {
3886 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3887 }
3888 }
3889
3890 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003891 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3892 * bug report is being generated.
3893 */
3894 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003895 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003896 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3897 != PackageManager.PERMISSION_GRANTED) {
3898 writer.println("Permission Denial: can't dump Phone from pid="
3899 + Binder.getCallingPid()
3900 + ", uid=" + Binder.getCallingUid()
3901 + "without permission "
3902 + android.Manifest.permission.DUMP);
3903 return;
3904 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003905 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003906 }
Jack Yueb89b242016-06-22 13:27:47 -07003907
3908 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003909 * Get aggregated video call data usage since boot.
3910 *
3911 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3912 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003913 * {@hide}
3914 */
3915 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003916 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003917 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3918 null);
3919
Jack Yu84291ec2017-05-26 16:07:50 -07003920 // NetworkStatsService keeps tracking the active network interface and identity. It
3921 // records the delta with the corresponding network identity. We just return the total video
3922 // call data usage snapshot since boot.
3923 Phone phone = getPhone(subId);
3924 if (phone != null) {
3925 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003926 }
Jack Yu84291ec2017-05-26 16:07:50 -07003927 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003928 }
Jack Yu75ab2952016-07-08 14:29:33 -07003929
3930 /**
3931 * Policy control of data connection. Usually used when data limit is passed.
3932 * @param enabled True if enabling the data, otherwise disabling.
3933 * @param subId Subscription index
3934 * {@hide}
3935 */
3936 @Override
3937 public void setPolicyDataEnabled(boolean enabled, int subId) {
3938 enforceModifyPermission();
3939 Phone phone = getPhone(subId);
3940 if (phone != null) {
3941 phone.setPolicyDataEnabled(enabled);
3942 }
3943 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003944
3945 /**
3946 * Get Client request stats
3947 * @return List of Client Request Stats
3948 * @hide
3949 */
3950 @Override
3951 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3952 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3953 return null;
3954 }
3955
3956 Phone phone = getPhone(subId);
3957 if (phone != null) {
3958 return phone.getClientRequestStats();
3959 }
3960
3961 return null;
3962 }
3963
3964 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3965 if (workSource != null) {
3966 return workSource;
3967 }
3968
3969 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3970 workSource = new WorkSource(uid, packageName);
3971 return workSource;
3972 }
Jack Yueb4124c2017-02-16 15:32:43 -08003973
3974 /**
Grace Chen70990072017-03-24 17:21:30 -07003975 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003976 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003977 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003978 * @param state State of SIM (power down, power up, pass through)
3979 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3980 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3981 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003982 *
3983 **/
3984 @Override
Grace Chen70990072017-03-24 17:21:30 -07003985 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003986 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003987 Phone phone = PhoneFactory.getPhone(slotIndex);
3988
Jack Yueb4124c2017-02-16 15:32:43 -08003989 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003990 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003991 }
3992 }
Shuo Qiandd210312017-04-12 22:11:33 +00003993
Tyler Gunn65d45c22017-06-05 11:22:26 -07003994 private boolean isUssdApiAllowed(int subId) {
3995 CarrierConfigManager configManager =
3996 (CarrierConfigManager) mPhone.getContext().getSystemService(
3997 Context.CARRIER_CONFIG_SERVICE);
3998 if (configManager == null) {
3999 return false;
4000 }
4001 PersistableBundle pb = configManager.getConfigForSubId(subId);
4002 if (pb == null) {
4003 return false;
4004 }
4005 return pb.getBoolean(
4006 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4007 }
4008
Shuo Qiandd210312017-04-12 22:11:33 +00004009 /**
4010 * Check if phone is in emergency callback mode
4011 * @return true if phone is in emergency callback mode
4012 * @param subId sub id
4013 */
4014 public boolean getEmergencyCallbackMode(int subId) {
4015 final Phone phone = getPhone(subId);
4016 if (phone != null) {
4017 return phone.isInEcm();
4018 } else {
4019 return false;
4020 }
4021 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004022
4023 /**
4024 * Get the current signal strength information for the given subscription.
4025 * Because this information is not updated when the device is in a low power state
4026 * it should not be relied-upon to be current.
4027 * @param subId Subscription index
4028 * @return the most recent cached signal strength info from the modem
4029 */
4030 @Override
4031 public SignalStrength getSignalStrength(int subId) {
4032 Phone p = getPhone(subId);
4033 if (p == null) {
4034 return null;
4035 }
4036
4037 return p.getSignalStrength();
4038 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004039
4040 @Override
4041 public UiccSlotInfo[] getUiccSlotsInfo() {
4042 enforceReadPrivilegedPermission();
4043
4044 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4045 if (slots == null) return null;
4046 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4047 for (int i = 0; i < slots.length; i++) {
4048 UiccSlot slot = slots[i];
4049
4050 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4051
4052 int cardState = 0;
4053 switch (slot.getCardState()) {
4054 case CARDSTATE_ABSENT:
4055 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4056 break;
4057 case CARDSTATE_PRESENT:
4058 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4059 break;
4060 case CARDSTATE_ERROR:
4061 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4062 break;
4063 case CARDSTATE_RESTRICTED:
4064 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4065 break;
4066 default:
4067 break;
4068
4069 }
4070
Qingxi Li63668902018-01-31 13:43:27 -08004071 infos[i] = new UiccSlotInfo(
4072 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004073 }
4074 return infos;
4075 }
4076
4077 @Override
4078 public boolean switchSlots(int[] physicalSlots) {
4079 enforceModifyPermission();
4080 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004082}