blob: 1666174ac5da188584d4aa89597e8d14a03a7e04 [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;
Jack Yu8e4fdc22018-04-13 14:05:37 -070094import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010095import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070096import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080099import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700100import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700101import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700103import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700104import com.android.internal.telephony.RILConstants;
Jack Yu8e4fdc22018-04-13 14:05:37 -0700105import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800106import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800107import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700108import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.uicc.IccIoResult;
110import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800111import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700112import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800113import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800115import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700117import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800118import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700119import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800120import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700121import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700122import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700124import java.io.FileDescriptor;
125import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800126import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800129import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132
133/**
134 * Implementation of the ITelephony interface.
135 */
Santos Cordon117fee72014-05-16 17:56:12 -0700136public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137 private static final String LOG_TAG = "PhoneInterfaceManager";
138 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
139 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141
142 // Message codes used with mMainThreadHandler
143 private static final int CMD_HANDLE_PIN_MMI = 1;
144 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
145 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
146 private static final int CMD_ANSWER_RINGING_CALL = 4;
147 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700148 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
149 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150 private static final int CMD_OPEN_CHANNEL = 9;
151 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
152 private static final int CMD_CLOSE_CHANNEL = 11;
153 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800154 private static final int CMD_NV_READ_ITEM = 13;
155 private static final int EVENT_NV_READ_ITEM_DONE = 14;
156 private static final int CMD_NV_WRITE_ITEM = 15;
157 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
158 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
159 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
160 private static final int CMD_NV_RESET_CONFIG = 19;
161 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800162 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
163 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
164 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
165 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800166 private static final int CMD_SEND_ENVELOPE = 25;
167 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian74b16b12018-04-27 01:32:07 +0000168 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
169 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700170 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
171 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
172 private static final int CMD_EXCHANGE_SIM_IO = 31;
173 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800174 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
175 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700176 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700178 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
179 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700180 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
181 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
182 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
183 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700184 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
185 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
186 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
187 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700188 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
190 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191 private static final int CMD_SWITCH_SLOTS = 50;
192 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800194 // Parameters of select command.
195 private static final int SELECT_COMMAND = 0xA4;
196 private static final int SELECT_P1 = 0x04;
197 private static final int SELECT_P2 = 0;
198 private static final int SELECT_P3 = 0x10;
199
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 /** The singleton instance. */
201 private static PhoneInterfaceManager sInstance;
202
Wink Saville3ab207e2014-11-20 13:07:20 -0800203 private PhoneGlobals mApp;
204 private Phone mPhone;
205 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700206 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private AppOpsManager mAppOps;
208 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800209 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800210 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211
Derek Tan97ebb422014-09-05 16:55:38 -0700212 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
213 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700215
Derek Tan740e1672017-06-27 14:56:27 -0700216 // The AID of ISD-R.
217 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
218
yinxub1bed742017-04-17 11:45:04 -0700219 private NetworkScanRequestTracker mNetworkScanRequestTracker;
220
Derek Tan89e89d42014-07-08 17:00:10 -0700221 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700222 * A request object to use for transmitting data to an ICC.
223 */
224 private static final class IccAPDUArgument {
225 public int channel, cla, command, p1, p2, p3;
226 public String data;
227
228 public IccAPDUArgument(int channel, int cla, int command,
229 int p1, int p2, int p3, String data) {
230 this.channel = channel;
231 this.cla = cla;
232 this.command = command;
233 this.p1 = p1;
234 this.p2 = p2;
235 this.p3 = p3;
236 this.data = data;
237 }
238 }
239
240 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700241 * A request object to use for transmitting data to an ICC.
242 */
243 private static final class ManualNetworkSelectionArgument {
244 public OperatorInfo operatorInfo;
245 public boolean persistSelection;
246
247 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
248 this.operatorInfo = operatorInfo;
249 this.persistSelection = persistSelection;
250 }
251 }
252
253 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
255 * request after sending. The main thread will notify the request when it is complete.
256 */
257 private static final class MainThreadRequest {
258 /** The argument to use for the request */
259 public Object argument;
260 /** The result of the request that is run on the main thread */
261 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800262 // The subscriber id that this request applies to. Defaults to
263 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
264 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
266 public MainThreadRequest(Object argument) {
267 this.argument = argument;
268 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800269
270 public MainThreadRequest(Object argument, Integer subId) {
271 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800272 if (subId != null) {
273 this.subId = subId;
274 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 }
277
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800278 private static final class IncomingThirdPartyCallArgs {
279 public final ComponentName component;
280 public final String callId;
281 public final String callerDisplayName;
282
283 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
284 String callerDisplayName) {
285 this.component = component;
286 this.callId = callId;
287 this.callerDisplayName = callerDisplayName;
288 }
289 }
290
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 /**
292 * A handler that processes messages on the main thread in the phone process. Since many
293 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
294 * inbound binder threads to the main thread in the phone process. The Binder thread
295 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
296 * on, which will be notified when the operation completes and will contain the result of the
297 * request.
298 *
299 * <p>If a MainThreadRequest object is provided in the msg.obj field,
300 * note that request.result must be set to something non-null for the calling thread to
301 * unblock.
302 */
303 private final class MainThreadHandler extends Handler {
304 @Override
305 public void handleMessage(Message msg) {
306 MainThreadRequest request;
307 Message onCompleted;
308 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800309 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700310 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
312 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700313 case CMD_HANDLE_USSD_REQUEST: {
314 request = (MainThreadRequest) msg.obj;
315 final Phone phone = getPhoneFromRequest(request);
316 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
317 String ussdRequest = ussdObject.first;
318 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700319
320 if (!isUssdApiAllowed(request.subId)) {
321 // Carrier does not support use of this API, return failure.
322 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
323 UssdResponse response = new UssdResponse(ussdRequest, null);
324 Bundle returnData = new Bundle();
325 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
326 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
327
328 request.result = true;
329 synchronized (request) {
330 request.notifyAll();
331 }
332 return;
333 }
334
Tyler Gunn52dcf772017-04-26 11:30:31 -0700335 try {
336 request.result = phone != null ?
337 phone.handleUssdRequest(ussdRequest, wrappedCallback)
338 : false;
339 } catch (CallStateException cse) {
340 request.result = false;
341 }
pkanwar32d516d2016-10-14 19:37:38 -0700342 // Wake up the requesting thread
343 synchronized (request) {
344 request.notifyAll();
345 }
346 break;
347 }
348
Yorke Lee716f67e2015-06-17 15:39:16 -0700349 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700351 final Phone phone = getPhoneFromRequest(request);
352 request.result = phone != null ?
353 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
354 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 // Wake up the requesting thread
356 synchronized (request) {
357 request.notifyAll();
358 }
359 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
362 case CMD_HANDLE_NEIGHBORING_CELL:
363 request = (MainThreadRequest) msg.obj;
364 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
365 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700366 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 break;
368
369 case EVENT_NEIGHBORING_CELL_DONE:
370 ar = (AsyncResult) msg.obj;
371 request = (MainThreadRequest) ar.userObj;
372 if (ar.exception == null && ar.result != null) {
373 request.result = ar.result;
374 } else {
375 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800376 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 }
378 // Wake up the requesting thread
379 synchronized (request) {
380 request.notifyAll();
381 }
382 break;
383
384 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700385 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800386 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700387 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800388 request.result = ""; // dummy result for notifying the waiting thread
389 // Wake up the requesting thread
390 synchronized (request) {
391 request.notifyAll();
392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 break;
394
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 case CMD_END_CALL:
396 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800397 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700398 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700399 Phone phone = getPhone(end_subId);
400 if (phone == null) {
401 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
402 break;
403 }
404 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
406 // CDMA: If the user presses the Power button we treat it as
407 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700408 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
410 // GSM: End the call as per the Phone state
411 hungUp = PhoneUtils.hangup(mCM);
412 } else {
413 throw new IllegalStateException("Unexpected phone type: " + phoneType);
414 }
415 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
416 request.result = hungUp;
417 // Wake up the requesting thread
418 synchronized (request) {
419 request.notifyAll();
420 }
421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 if (uiccCard == null) {
428 loge("iccTransmitApduLogicalChannel: No UICC");
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
430 synchronized (request) {
431 request.notifyAll();
432 }
433 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
435 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 iccArgument.channel, iccArgument.cla, iccArgument.command,
438 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 break;
442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 ar = (AsyncResult) msg.obj;
445 request = (MainThreadRequest) ar.userObj;
446 if (ar.exception == null && ar.result != null) {
447 request.result = ar.result;
448 } else {
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
450 if (ar.result == null) {
451 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800452 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800454 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 } else {
456 loge("iccTransmitApduLogicalChannel: Unknown exception");
457 }
458 }
459 synchronized (request) {
460 request.notifyAll();
461 }
462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
465 request = (MainThreadRequest) msg.obj;
466 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 if (uiccCard == null) {
469 loge("iccTransmitApduBasicChannel: No UICC");
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 synchronized (request) {
472 request.notifyAll();
473 }
474 } else {
475 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
476 request);
477 uiccCard.iccTransmitApduBasicChannel(
478 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
479 iccArgument.p3, iccArgument.data, onCompleted);
480 }
481 break;
482
483 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
488 } else {
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("iccTransmitApduBasicChannel: Empty response");
492 } else if (ar.exception instanceof CommandException) {
493 loge("iccTransmitApduBasicChannel: CommandException: " +
494 ar.exception);
495 } else {
496 loge("iccTransmitApduBasicChannel: Unknown exception");
497 }
498 }
499 synchronized (request) {
500 request.notifyAll();
501 }
502 break;
503
504 case CMD_EXCHANGE_SIM_IO:
505 request = (MainThreadRequest) msg.obj;
506 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 if (uiccCard == null) {
509 loge("iccExchangeSimIO: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 synchronized (request) {
512 request.notifyAll();
513 }
514 } else {
515 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
516 request);
517 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
518 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
519 iccArgument.data, onCompleted);
520 }
521 break;
522
523 case EVENT_EXCHANGE_SIM_IO_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
528 } else {
529 request.result = new IccIoResult(0x6f, 0, (byte[])null);
530 }
531 synchronized (request) {
532 request.notifyAll();
533 }
534 break;
535
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 case CMD_SEND_ENVELOPE:
537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("sendEnvelopeWithStatus: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 synchronized (request) {
543 request.notifyAll();
544 }
545 } else {
546 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
547 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
551 case EVENT_SEND_ENVELOPE_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("sendEnvelopeWithStatus: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("sendEnvelopeWithStatus: CommandException: " +
562 ar.exception);
563 } else {
564 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 }
567 synchronized (request) {
568 request.notifyAll();
569 }
570 break;
571
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 case CMD_OPEN_CHANNEL:
573 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800574 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 if (uiccCard == null) {
577 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800578 request.result = new IccOpenLogicalChannelResponse(-1,
579 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 synchronized (request) {
581 request.notifyAll();
582 }
583 } else {
584 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
586 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
590 case EVENT_OPEN_CHANNEL_DONE:
591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 int[] result = (int[]) ar.result;
596 int channelId = result[0];
597 byte[] selectResponse = null;
598 if (result.length > 1) {
599 selectResponse = new byte[result.length - 1];
600 for (int i = 1; i < result.length; ++i) {
601 selectResponse[i - 1] = (byte) result[i];
602 }
603 }
604 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 if (ar.result == null) {
608 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 if (ar.exception != null) {
611 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
612 }
613
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700614 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700615 if (ar.exception instanceof CommandException) {
616 CommandException.Error error =
617 ((CommandException) (ar.exception)).getCommandError();
618 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700620 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 }
623 }
624 openChannelResp = new IccOpenLogicalChannelResponse(
625 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700627 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 synchronized (request) {
629 request.notifyAll();
630 }
631 break;
632
633 case CMD_CLOSE_CHANNEL:
634 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800635 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 if (uiccCard == null) {
637 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900638 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 synchronized (request) {
640 request.notifyAll();
641 }
642 } else {
643 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
644 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
645 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800649 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
650 break;
651
652 case CMD_NV_READ_ITEM:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
655 mPhone.nvReadItem((Integer) request.argument, onCompleted);
656 break;
657
658 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 ar = (AsyncResult) msg.obj;
660 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800661 if (ar.exception == null && ar.result != null) {
662 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 request.result = "";
665 if (ar.result == null) {
666 loge("nvReadItem: Empty response");
667 } else if (ar.exception instanceof CommandException) {
668 loge("nvReadItem: CommandException: " +
669 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800671 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
673 }
674 synchronized (request) {
675 request.notifyAll();
676 }
677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
683 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
684 break;
685
686 case EVENT_NV_WRITE_ITEM_DONE:
687 handleNullReturnEvent(msg, "nvWriteItem");
688 break;
689
690 case CMD_NV_WRITE_CDMA_PRL:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
693 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
694 break;
695
696 case EVENT_NV_WRITE_CDMA_PRL_DONE:
697 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
698 break;
699
700 case CMD_NV_RESET_CONFIG:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
703 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
704 break;
705
706 case EVENT_NV_RESET_CONFIG_DONE:
707 handleNullReturnEvent(msg, "nvResetConfig");
708 break;
709
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 case CMD_GET_PREFERRED_NETWORK_TYPE:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
717 ar = (AsyncResult) msg.obj;
718 request = (MainThreadRequest) ar.userObj;
719 if (ar.exception == null && ar.result != null) {
720 request.result = ar.result; // Integer
721 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800722 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 if (ar.result == null) {
724 loge("getPreferredNetworkType: Empty response");
725 } else if (ar.exception instanceof CommandException) {
726 loge("getPreferredNetworkType: CommandException: " +
727 ar.exception);
728 } else {
729 loge("getPreferredNetworkType: Unknown exception");
730 }
731 }
732 synchronized (request) {
733 request.notifyAll();
734 }
735 break;
736
737 case CMD_SET_PREFERRED_NETWORK_TYPE:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
740 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700741 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
745 handleNullReturnEvent(msg, "setPreferredNetworkType");
746 break;
747
Shuo Qian74b16b12018-04-27 01:32:07 +0000748 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
749 request = (MainThreadRequest)msg.obj;
750 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
751 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
752 break;
753
754 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
755 ar = (AsyncResult)msg.obj;
756 request = (MainThreadRequest)ar.userObj;
757 request.result = ar;
758 synchronized (request) {
759 request.notifyAll();
760 }
761 break;
762
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 case CMD_SET_VOICEMAIL_NUMBER:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
766 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800767 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
768 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 break;
770
771 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
772 handleNullReturnEvent(msg, "setVoicemailNumber");
773 break;
774
Stuart Scott54788802015-03-30 13:18:01 -0700775 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
778 request);
779 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
780 break;
781
782 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
783 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
784 break;
785
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 case CMD_PERFORM_NETWORK_SCAN:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
789 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
790 break;
791
792 case EVENT_PERFORM_NETWORK_SCAN_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 CellNetworkScanResult cellScanResult;
796 if (ar.exception == null && ar.result != null) {
797 cellScanResult = new CellNetworkScanResult(
798 CellNetworkScanResult.STATUS_SUCCESS,
799 (List<OperatorInfo>) ar.result);
800 } else {
801 if (ar.result == null) {
802 loge("getCellNetworkScanResults: Empty response");
803 }
804 if (ar.exception != null) {
805 loge("getCellNetworkScanResults: Exception: " + ar.exception);
806 }
807 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
810 ((CommandException) (ar.exception)).getCommandError();
811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
813 } else if (error == CommandException.Error.GENERIC_FAILURE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
815 }
816 }
817 cellScanResult = new CellNetworkScanResult(errorCode, null);
818 }
819 request.result = cellScanResult;
820 synchronized (request) {
821 request.notifyAll();
822 }
823 break;
824
825 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
826 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700827 ManualNetworkSelectionArgument selArg =
828 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
830 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
832 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
836 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
837 break;
838
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 case CMD_GET_MODEM_ACTIVITY_INFO:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700842 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 break;
844
845 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
848 if (ar.exception == null && ar.result != null) {
849 request.result = ar.result;
850 } else {
851 if (ar.result == null) {
852 loge("queryModemActivityInfo: Empty response");
853 } else if (ar.exception instanceof CommandException) {
854 loge("queryModemActivityInfo: CommandException: " +
855 ar.exception);
856 } else {
857 loge("queryModemActivityInfo: Unknown exception");
858 }
859 }
Amit Mahajand4766222016-01-28 15:28:28 -0800860 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
861 if (request.result == null) {
862 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700864 synchronized (request) {
865 request.notifyAll();
866 }
867 break;
868
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 case CMD_SET_ALLOWED_CARRIERS:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
872 mPhone.setAllowedCarriers(
873 (List<CarrierIdentifier>) request.argument,
874 onCompleted);
875 break;
876
877 case EVENT_SET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
883 if (ar.result == null) {
884 loge("setAllowedCarriers: Empty response");
885 } else if (ar.exception instanceof CommandException) {
886 loge("setAllowedCarriers: CommandException: " +
887 ar.exception);
888 } else {
889 loge("setAllowedCarriers: Unknown exception");
890 }
891 }
892 // Result cannot be null. Return -1 on error.
893 if (request.result == null) {
894 request.result = new int[]{-1};
895 }
896 synchronized (request) {
897 request.notifyAll();
898 }
899 break;
900
901 case CMD_GET_ALLOWED_CARRIERS:
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
904 mPhone.getAllowedCarriers(onCompleted);
905 break;
906
907 case EVENT_GET_ALLOWED_CARRIERS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result;
912 } else {
913 if (ar.result == null) {
914 loge("getAllowedCarriers: Empty response");
915 } else if (ar.exception instanceof CommandException) {
916 loge("getAllowedCarriers: CommandException: " +
917 ar.exception);
918 } else {
919 loge("getAllowedCarriers: Unknown exception");
920 }
921 }
922 // Result cannot be null. Return empty list of CarrierIdentifier.
923 if (request.result == null) {
924 request.result = new ArrayList<CarrierIdentifier>(0);
925 }
926 synchronized (request) {
927 request.notifyAll();
928 }
929 break;
930
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 request.result = new IllegalArgumentException(
938 "Failed to retrieve Forbidden Plmns");
939 if (ar.result == null) {
940 loge("getForbiddenPlmns: Empty response");
941 } else {
942 loge("getForbiddenPlmns: Unknown exception");
943 }
944 }
945 synchronized (request) {
946 request.notifyAll();
947 }
948 break;
949
950 case CMD_GET_FORBIDDEN_PLMNS:
951 request = (MainThreadRequest) msg.obj;
952 uiccCard = getUiccCardFromRequest(request);
953 if (uiccCard == null) {
954 loge("getForbiddenPlmns() UiccCard is null");
955 request.result = new IllegalArgumentException(
956 "getForbiddenPlmns() UiccCard is null");
957 synchronized (request) {
958 request.notifyAll();
959 }
960 break;
961 }
962 Integer appType = (Integer) request.argument;
963 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
964 if (uiccApp == null) {
965 loge("getForbiddenPlmns() no app with specified type -- "
966 + appType);
967 request.result = new IllegalArgumentException("Failed to get UICC App");
968 synchronized (request) {
969 request.notifyAll();
970 }
971 break;
972 } else {
973 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
974 + " specified type -- " + appType);
975 }
976 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
977 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
978 onCompleted);
979 break;
980
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000981 case CMD_SWITCH_SLOTS:
982 request = (MainThreadRequest) msg.obj;
983 int[] physicalSlots = (int[]) request.argument;
984 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
985 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
986 break;
987
988 case EVENT_SWITCH_SLOTS_DONE:
989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
991 request.result = (ar.exception == null);
992 synchronized (request) {
993 request.notifyAll();
994 }
995 break;
996
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700997 default:
998 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
999 break;
1000 }
1001 }
Jake Hambye994d462014-02-03 13:10:13 -08001002
1003 private void handleNullReturnEvent(Message msg, String command) {
1004 AsyncResult ar = (AsyncResult) msg.obj;
1005 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1006 if (ar.exception == null) {
1007 request.result = true;
1008 } else {
1009 request.result = false;
1010 if (ar.exception instanceof CommandException) {
1011 loge(command + ": CommandException: " + ar.exception);
1012 } else {
1013 loge(command + ": Unknown exception");
1014 }
1015 }
1016 synchronized (request) {
1017 request.notifyAll();
1018 }
1019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001020 }
1021
1022 /**
1023 * Posts the specified command to be executed on the main thread,
1024 * waits for the request to complete, and returns the result.
1025 * @see #sendRequestAsync
1026 */
1027 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001028 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001029 }
1030
1031 /**
1032 * Posts the specified command to be executed on the main thread,
1033 * waits for the request to complete, and returns the result.
1034 * @see #sendRequestAsync
1035 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001036 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001037 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1038 throw new RuntimeException("This method will deadlock if called from the main thread.");
1039 }
1040
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001041 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 Message msg = mMainThreadHandler.obtainMessage(command, request);
1043 msg.sendToTarget();
1044
1045 // Wait for the request to complete
1046 synchronized (request) {
1047 while (request.result == null) {
1048 try {
1049 request.wait();
1050 } catch (InterruptedException e) {
1051 // Do nothing, go back and wait until the request is complete
1052 }
1053 }
1054 }
1055 return request.result;
1056 }
1057
1058 /**
1059 * Asynchronous ("fire and forget") version of sendRequest():
1060 * Posts the specified command to be executed on the main thread, and
1061 * returns immediately.
1062 * @see #sendRequest
1063 */
1064 private void sendRequestAsync(int command) {
1065 mMainThreadHandler.sendEmptyMessage(command);
1066 }
1067
1068 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001069 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1070 * @see {@link #sendRequest(int,Object)}
1071 */
1072 private void sendRequestAsync(int command, Object argument) {
1073 MainThreadRequest request = new MainThreadRequest(argument);
1074 Message msg = mMainThreadHandler.obtainMessage(command, request);
1075 msg.sendToTarget();
1076 }
1077
1078 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 * Initialize the singleton PhoneInterfaceManager instance.
1080 * This is only done once, at startup, from PhoneApp.onCreate().
1081 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001082 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 synchronized (PhoneInterfaceManager.class) {
1084 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001085 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 } else {
1087 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1088 }
1089 return sInstance;
1090 }
1091 }
1092
1093 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001094 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 mApp = app;
1096 mPhone = phone;
1097 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001098 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001099 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1100 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001101 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001102 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001103 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001104 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001105
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 publish();
1107 }
1108
1109 private void publish() {
1110 if (DBG) log("publish: " + this);
1111
1112 ServiceManager.addService("phone", this);
1113 }
1114
Stuart Scott584921c2015-01-15 17:10:34 -08001115 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001116 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1117 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001118 }
1119
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001120 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1121 Phone phone = getPhoneFromRequest(request);
1122 return phone == null ? null :
1123 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1124 }
1125
Wink Saville36469e72014-06-11 15:17:00 -07001126 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001127 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001128 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 //
1131 // Implementation of the ITelephony interface.
1132 //
1133
1134 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001135 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001136 }
1137
Wink Savilleb564aae2014-10-23 10:18:09 -07001138 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 if (DBG) log("dial: " + number);
1140 // No permission check needed here: This is just a wrapper around the
1141 // ACTION_DIAL intent, which is available to any app since it puts up
1142 // the UI before it does anything.
1143
1144 String url = createTelUrl(number);
1145 if (url == null) {
1146 return;
1147 }
1148
1149 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001150 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001151 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1152 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1153 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1154 mApp.startActivity(intent);
1155 }
1156 }
1157
1158 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001159 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001160 }
1161
Wink Savilleb564aae2014-10-23 10:18:09 -07001162 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 if (DBG) log("call: " + number);
1164
1165 // This is just a wrapper around the ACTION_CALL intent, but we still
1166 // need to do a permission check since we're calling startActivity()
1167 // from the context of the phone app.
1168 enforceCallPermission();
1169
1170 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1171 != AppOpsManager.MODE_ALLOWED) {
1172 return;
1173 }
1174
1175 String url = createTelUrl(number);
1176 if (url == null) {
1177 return;
1178 }
1179
Wink Saville08874612014-08-31 19:19:58 -07001180 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001181 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001182 if (slist != null) {
1183 for (SubscriptionInfo subInfoRecord : slist) {
1184 if (subInfoRecord.getSubscriptionId() == subId) {
1185 isValid = true;
1186 break;
1187 }
Wink Saville08874612014-08-31 19:19:58 -07001188 }
1189 }
1190 if (isValid == false) {
1191 return;
1192 }
1193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001195 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1197 mApp.startActivity(intent);
1198 }
1199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 /**
1201 * End a call based on call state
1202 * @return true is a call was ended
1203 */
1204 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001205 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001206 }
1207
1208 /**
1209 * End a call based on the call state of the subId
1210 * @return true is a call was ended
1211 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001212 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001214 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 }
1216
1217 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001218 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001219 }
1220
Wink Savilleb564aae2014-10-23 10:18:09 -07001221 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (DBG) log("answerRingingCall...");
1223 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1224 // but that can probably wait till the big TelephonyManager API overhaul.
1225 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1226 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001227 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 }
1229
1230 /**
1231 * Make the actual telephony calls to implement answerRingingCall().
1232 * This should only be called from the main thread of the Phone app.
1233 * @see #answerRingingCall
1234 *
1235 * TODO: it would be nice to return true if we answered the call, or
1236 * false if there wasn't actually a ringing incoming call, or some
1237 * other error occurred. (In other words, pass back the return value
1238 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1239 * But that would require calling this method via sendRequest() rather
1240 * than sendRequestAsync(), and right now we don't actually *need* that
1241 * return value, so let's just return void for now.
1242 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001243 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001244 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001246 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1247 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 if (hasActiveCall && hasHoldingCall) {
1249 // Both lines are in use!
1250 // TODO: provide a flag to let the caller specify what
1251 // policy to use if both lines are in use. (The current
1252 // behavior is hardwired to "answer incoming, end ongoing",
1253 // which is how the CALL button is specced to behave.)
1254 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1255 return;
1256 } else {
1257 // answerCall() will automatically hold the current active
1258 // call, if there is one.
1259 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1260 return;
1261 }
1262 } else {
1263 // No call was ringing.
1264 return;
1265 }
1266 }
1267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001269 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001271 public void silenceRinger() {
1272 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 }
1274
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001275 @Override
1276 public boolean isOffhook(String callingPackage) {
1277 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 @Override
1281 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001283 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 return false;
1285 }
1286
Sanket Padawe356d7632015-06-22 14:03:32 -07001287 final Phone phone = getPhone(subId);
1288 if (phone != null) {
1289 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1290 } else {
1291 return false;
1292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 }
1294
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001295 @Override
1296 public boolean isRinging(String callingPackage) {
1297 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001298 }
1299
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001300 @Override
1301 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001303 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 return false;
1305 }
1306
Sanket Padawe356d7632015-06-22 14:03:32 -07001307 final Phone phone = getPhone(subId);
1308 if (phone != null) {
1309 return (phone.getState() == PhoneConstants.State.RINGING);
1310 } else {
1311 return false;
1312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 }
1314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001315 @Override
1316 public boolean isIdle(String callingPackage) {
1317 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 @Override
1321 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001323 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001324 return false;
1325 }
1326
Sanket Padawe356d7632015-06-22 14:03:32 -07001327 final Phone phone = getPhone(subId);
1328 if (phone != null) {
1329 return (phone.getState() == PhoneConstants.State.IDLE);
1330 } else {
1331 return false;
1332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001336 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001337 }
1338
Wink Savilleb564aae2014-10-23 10:18:09 -07001339 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001340 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001341 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1342 }
1343
1344 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001345 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Wink Savilleb564aae2014-10-23 10:18:09 -07001348 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001349 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001350 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1351 }
1352
1353 /** {@hide} */
1354 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001356 }
1357
Wink Savilleb564aae2014-10-23 10:18:09 -07001358 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001360 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 checkSimPin.start();
1362 return checkSimPin.unlockSim(null, pin);
1363 }
1364
Wink Saville9de0f752013-10-22 19:04:03 -07001365 /** {@hide} */
1366 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001367 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001368 }
1369
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001372 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 checkSimPuk.start();
1374 return checkSimPuk.unlockSim(puk, pin);
1375 }
1376
1377 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001378 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 * a synchronous one.
1380 */
1381 private static class UnlockSim extends Thread {
1382
1383 private final IccCard mSimCard;
1384
1385 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001386 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1387 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388
1389 // For replies from SimCard interface
1390 private Handler mHandler;
1391
1392 // For async handler to identify request type
1393 private static final int SUPPLY_PIN_COMPLETE = 100;
1394
1395 public UnlockSim(IccCard simCard) {
1396 mSimCard = simCard;
1397 }
1398
1399 @Override
1400 public void run() {
1401 Looper.prepare();
1402 synchronized (UnlockSim.this) {
1403 mHandler = new Handler() {
1404 @Override
1405 public void handleMessage(Message msg) {
1406 AsyncResult ar = (AsyncResult) msg.obj;
1407 switch (msg.what) {
1408 case SUPPLY_PIN_COMPLETE:
1409 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1410 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001411 mRetryCount = msg.arg1;
1412 if (ar.exception != null) {
1413 if (ar.exception instanceof CommandException &&
1414 ((CommandException)(ar.exception)).getCommandError()
1415 == CommandException.Error.PASSWORD_INCORRECT) {
1416 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1417 } else {
1418 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1419 }
1420 } else {
1421 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423 mDone = true;
1424 UnlockSim.this.notifyAll();
1425 }
1426 break;
1427 }
1428 }
1429 };
1430 UnlockSim.this.notifyAll();
1431 }
1432 Looper.loop();
1433 }
1434
1435 /*
1436 * Use PIN or PUK to unlock SIM card
1437 *
1438 * If PUK is null, unlock SIM card with PIN
1439 *
1440 * If PUK is not null, unlock SIM card with PUK and set PIN code
1441 */
Wink Saville9de0f752013-10-22 19:04:03 -07001442 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443
1444 while (mHandler == null) {
1445 try {
1446 wait();
1447 } catch (InterruptedException e) {
1448 Thread.currentThread().interrupt();
1449 }
1450 }
1451 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1452
1453 if (puk == null) {
1454 mSimCard.supplyPin(pin, callback);
1455 } else {
1456 mSimCard.supplyPuk(puk, pin, callback);
1457 }
1458
1459 while (!mDone) {
1460 try {
1461 Log.d(LOG_TAG, "wait for done");
1462 wait();
1463 } catch (InterruptedException e) {
1464 // Restore the interrupted status
1465 Thread.currentThread().interrupt();
1466 }
1467 }
1468 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001469 int[] resultArray = new int[2];
1470 resultArray[0] = mResult;
1471 resultArray[1] = mRetryCount;
1472 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 }
1474 }
1475
1476 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001477 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001478
1479 }
1480
Wink Savilleb564aae2014-10-23 10:18:09 -07001481 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 // No permission check needed here: this call is harmless, and it's
1483 // needed for the ServiceState.requestStateUpdate() call (which is
1484 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 final Phone phone = getPhone(subId);
1486 if (phone != null) {
1487 phone.updateServiceLocation();
1488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001491 @Override
1492 public boolean isRadioOn(String callingPackage) {
1493 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001494 }
1495
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001496 @Override
1497 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001499 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001500 return false;
1501 }
1502 return isRadioOnForSubscriber(subId);
1503 }
1504
1505 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001506 final Phone phone = getPhone(subId);
1507 if (phone != null) {
1508 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1509 } else {
1510 return false;
1511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 }
1513
1514 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 }
Wink Saville36469e72014-06-11 15:17:00 -07001518
Wink Savilleb564aae2014-10-23 10:18:09 -07001519 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001521 final Phone phone = getPhone(subId);
1522 if (phone != null) {
1523 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1524 }
Wink Saville36469e72014-06-11 15:17:00 -07001525 }
1526
1527 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001529 }
1530
Wink Savilleb564aae2014-10-23 10:18:09 -07001531 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001532 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001533 final Phone phone = getPhone(subId);
1534 if (phone == null) {
1535 return false;
1536 }
1537 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001538 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 }
1541 return true;
1542 }
Wink Saville36469e72014-06-11 15:17:00 -07001543
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001544 public boolean needMobileRadioShutdown() {
1545 /*
1546 * If any of the Radios are available, it will need to be
1547 * shutdown. So return true if any Radio is available.
1548 */
1549 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1550 Phone phone = PhoneFactory.getPhone(i);
1551 if (phone != null && phone.isRadioAvailable()) return true;
1552 }
1553 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1554 return false;
1555 }
1556
1557 public void shutdownMobileRadios() {
1558 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1559 logv("Shutting down Phone " + i);
1560 shutdownRadioUsingPhoneId(i);
1561 }
1562 }
1563
1564 private void shutdownRadioUsingPhoneId(int phoneId) {
1565 enforceModifyPermission();
1566 Phone phone = PhoneFactory.getPhone(phoneId);
1567 if (phone != null && phone.isRadioAvailable()) {
1568 phone.shutdownRadio();
1569 }
1570 }
1571
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001573 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001574 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1575 if (defaultPhone != null) {
1576 defaultPhone.setRadioPower(turnOn);
1577 return true;
1578 } else {
1579 loge("There's no default phone.");
1580 return false;
1581 }
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Wink Savilleb564aae2014-10-23 10:18:09 -07001584 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 final Phone phone = getPhone(subId);
1587 if (phone != null) {
1588 phone.setRadioPower(turnOn);
1589 return true;
1590 } else {
1591 return false;
1592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
1594
Wink Saville36469e72014-06-11 15:17:00 -07001595 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 public boolean enableDataConnectivity() {
1598 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001599 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001602 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 return true;
1604 } else {
1605 return false;
1606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 }
1608
Wink Saville36469e72014-06-11 15:17:00 -07001609 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 public boolean disableDataConnectivity() {
1612 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001613 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001616 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 return true;
1618 } else {
1619 return false;
1620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001624 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 final Phone phone = getPhone(subId);
1626 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001627 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 } else {
1629 return false;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
1633 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001634 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001635 }
1636
pkanwarae03a6b2016-11-06 20:37:09 -08001637 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001638 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1640 return;
1641 }
1642 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1643 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1644 };
1645
Wink Savilleb564aae2014-10-23 10:18:09 -07001646 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1649 return false;
1650 }
Wink Saville36469e72014-06-11 15:17:00 -07001651 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001655 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001656 }
1657
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001658 public int getCallStateForSlot(int slotIndex) {
1659 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001660 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001661 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663
Sanket Padawe356d7632015-06-22 14:03:32 -07001664 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001666 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001668 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001670 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001676 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 if (phone != null) {
1678 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1679 } else {
1680 return TelephonyManager.DATA_ACTIVITY_NONE;
1681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
1684 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001685 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001686 mPhone.getContext().getSystemService(AppOpsManager.class)
1687 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001688 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001689 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001690 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001693 if (DBG_LOC) log("getCellLocation: is active user");
1694 Bundle data = new Bundle();
1695 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1696 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 return null;
1698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001700 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1701 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1702 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001703 }
1704
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001706 public String getNetworkCountryIsoForPhone(int phoneId) {
1707 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1708 // registered cell info, so return a NULL country instead.
1709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu8e4fdc22018-04-13 14:05:37 -07001712 // Todo: fix this when we can get the actual cellular network info when the device
1713 // is on IWLAN.
Jonathan Basseri03923952017-07-19 12:22:35 -07001714 if (TelephonyManager.NETWORK_TYPE_IWLAN
1715 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1716 return "";
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
1720 }
Jack Yu8e4fdc22018-04-13 14:05:37 -07001721
1722 Phone phone = PhoneFactory.getPhone(phoneId);
1723 if (phone != null) {
1724 ServiceStateTracker sst = phone.getServiceStateTracker();
1725 if (sst != null) {
1726 LocaleTracker lt = sst.getLocaleTracker();
1727 if (lt != null) {
1728 return lt.getCurrentCountry();
1729 }
1730 }
1731 }
1732 return "";
Jonathan Basseri03923952017-07-19 12:22:35 -07001733 }
1734
1735 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001738 }
1739
Sanket Padawe356d7632015-06-22 14:03:32 -07001740 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001741 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 mApp.enforceCallingOrSelfPermission(
1743 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 final Phone phone = getPhone(subId);
1745 if (phone != null) {
1746 phone.enableLocationUpdates();
1747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750 @Override
1751 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 mApp.enforceCallingOrSelfPermission(
1758 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.disableLocationUpdates();
1762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
1765 @Override
1766 @SuppressWarnings("unchecked")
1767 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001768 mPhone.getContext().getSystemService(AppOpsManager.class)
1769 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001771 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001772 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
1775 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1776 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1777 return null;
1778 }
Svetoslav64fad262015-04-14 14:35:21 -07001779
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001780 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1785 try {
1786 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1787 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1788 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1789 } catch (RuntimeException e) {
1790 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001792 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
1795
1796 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001797 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001798 mPhone.getContext().getSystemService(AppOpsManager.class)
1799 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001800 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001801 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001802 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
1804
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001805 if (DBG_LOC) log("getAllCellInfo: is active user");
1806 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1807 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1808 for (Phone phone : PhoneFactory.getPhones()) {
1809 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1810 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001812 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001815 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001817 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001818 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1819 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 }
1821
Shishir Agrawala9f32182016-04-12 12:00:16 -07001822 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001823 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001824 Phone phone = PhoneFactory.getPhone(slotIndex);
1825 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001826 return null;
1827 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001828 int subId = phone.getSubId();
1829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1830 mApp, subId, callingPackage, "getImeiForSlot")) {
1831 return null;
1832 }
1833 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001834 }
1835
1836 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001837 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001838 Phone phone = PhoneFactory.getPhone(slotIndex);
1839 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001840 return null;
1841 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001842 int subId = phone.getSubId();
1843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1844 mApp, subId, callingPackage, "getMeidForSlot")) {
1845 return null;
1846 }
1847 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001848 }
1849
1850 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001851 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001852 Phone phone = PhoneFactory.getPhone(slotIndex);
1853 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001854 return null;
1855 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001856 int subId = phone.getSubId();
1857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1858 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1859 return null;
1860 }
1861 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001862 }
1863
fionaxuf32acdf2017-11-27 22:51:16 -08001864 @Override
1865 public int getSubscriptionCarrierId(int subId) {
1866 final Phone phone = getPhone(subId);
1867 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1868 }
1869
1870 @Override
1871 public String getSubscriptionCarrierName(int subId) {
1872 final Phone phone = getPhone(subId);
1873 return phone == null ? null : phone.getCarrierName();
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 //
1877 // Internal helper methods.
1878 //
1879
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001880 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1882 *
1883 * @throws SecurityException if the caller does not have the required permission
1884 */
1885 private void enforceModifyPermission() {
1886 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1887 }
1888
1889 /**
1890 * Make sure the caller has the CALL_PHONE permission.
1891 *
1892 * @throws SecurityException if the caller does not have the required permission
1893 */
1894 private void enforceCallPermission() {
1895 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1896 }
1897
Stuart Scott8eef64f2015-04-08 15:13:54 -07001898 private void enforceConnectivityInternalPermission() {
1899 mApp.enforceCallingOrSelfPermission(
1900 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1901 "ConnectivityService");
1902 }
1903
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 private String createTelUrl(String number) {
1905 if (TextUtils.isEmpty(number)) {
1906 return null;
1907 }
1908
Jake Hambye994d462014-02-03 13:10:13 -08001909 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
Ihab Awadf9e92732013-12-05 18:02:52 -08001912 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1914 }
1915
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001916 private static void logv(String msg) {
1917 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1918 }
1919
Ihab Awadf9e92732013-12-05 18:02:52 -08001920 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1922 }
1923
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001926 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001930 public int getActivePhoneTypeForSlot(int slotIndex) {
1931 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001932 if (phone == null) {
1933 return PhoneConstants.PHONE_TYPE_NONE;
1934 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001935 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 /**
1940 * Returns the CDMA ERI icon index to display
1941 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001942 @Override
1943 public int getCdmaEriIconIndex(String callingPackage) {
1944 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001945 }
1946
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001948 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001950 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 return -1;
1952 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
1955 return phone.getCdmaEriIconIndex();
1956 } else {
1957 return -1;
1958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
1961 /**
1962 * Returns the CDMA ERI icon mode,
1963 * 0 - ON
1964 * 1 - FLASHING
1965 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 @Override
1967 public int getCdmaEriIconMode(String callingPackage) {
1968 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001972 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001974 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001975 return -1;
1976 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 final Phone phone = getPhone(subId);
1978 if (phone != null) {
1979 return phone.getCdmaEriIconMode();
1980 } else {
1981 return -1;
1982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
1985 /**
1986 * Returns the CDMA ERI text,
1987 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 @Override
1989 public String getCdmaEriText(String callingPackage) {
1990 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001991 }
1992
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001994 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001996 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001997 return null;
1998 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 final Phone phone = getPhone(subId);
2000 if (phone != null) {
2001 return phone.getCdmaEriText();
2002 } else {
2003 return null;
2004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 }
2006
2007 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002008 * Returns the CDMA MDN.
2009 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002011 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2013 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002014 final Phone phone = getPhone(subId);
2015 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2016 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002017 } else {
2018 return null;
2019 }
2020 }
2021
2022 /**
2023 * Returns the CDMA MIN.
2024 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002025 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002026 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2028 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 final Phone phone = getPhone(subId);
2030 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2031 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002032 } else {
2033 return null;
2034 }
2035 }
2036
2037 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 * Returns true if CDMA provisioning needs to run.
2039 */
2040 public boolean needsOtaServiceProvisioning() {
2041 return mPhone.needsOtaServiceProvisioning();
2042 }
2043
2044 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002045 * Sets the voice mail number of a given subId.
2046 */
2047 @Override
2048 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002049 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002050 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2051 new Pair<String, String>(alphaTag, number), new Integer(subId));
2052 return success;
2053 }
2054
Ta-wei Yen87c49842016-05-13 21:19:52 -07002055 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002056 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2058 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2059 if (!TextUtils.equals(callingPackage, systemDialer)) {
2060 throw new SecurityException("caller must be system dialer");
2061 }
2062 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2063 if (phoneAccountHandle == null){
2064 return null;
2065 }
2066 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2067 }
2068
2069 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002070 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002073 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002074 return null;
2075 }
Jeff Davidson87b3c102018-03-15 17:16:18 -07002076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 return RemoteVvmTaskManager
2079 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002083 }
2084
2085 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002086 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2087 VisualVoicemailSmsFilterSettings settings) {
2088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002089 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002090 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2091 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002092 }
2093
2094 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002095 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002098 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002099 }
2100
2101 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002102 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2103 String callingPackage, int subId) {
2104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002105 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002106 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002107 }
2108
2109 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002110 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002111 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002112 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002113 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2114 }
2115
2116 @Override
2117 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2118 String number, int port, String text, PendingIntent sentIntent) {
2119 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002120 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002121 enforceSendSmsPermission();
2122 // Make the calls as the phone process.
2123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2126 if (port == 0) {
2127 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2128 sentIntent, null, false);
2129 } else {
2130 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2131 smsManager.sendDataMessageWithSelfPermissions(number, null,
2132 (short) port, data, sentIntent, null);
2133 }
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
2136 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002137 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002138 /**
fionaxu0152e512016-11-14 13:36:14 -08002139 * Sets the voice activation state of a given subId.
2140 */
2141 @Override
2142 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2144 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002145 final Phone phone = getPhone(subId);
2146 if (phone != null) {
2147 phone.setVoiceActivationState(activationState);
2148 } else {
2149 loge("setVoiceActivationState fails with invalid subId: " + subId);
2150 }
2151 }
2152
2153 /**
2154 * Sets the data activation state of a given subId.
2155 */
2156 @Override
2157 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2159 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002160 final Phone phone = getPhone(subId);
2161 if (phone != null) {
2162 phone.setDataActivationState(activationState);
2163 } else {
2164 loge("setVoiceActivationState fails with invalid subId: " + subId);
2165 }
2166 }
2167
2168 /**
2169 * Returns the voice activation state of a given subId.
2170 */
2171 @Override
2172 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002173 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002174 final Phone phone = getPhone(subId);
2175 if (phone != null) {
2176 return phone.getVoiceActivationState();
2177 } else {
2178 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2179 }
2180 }
2181
2182 /**
2183 * Returns the data activation state of a given subId.
2184 */
2185 @Override
2186 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002187 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002188 final Phone phone = getPhone(subId);
2189 if (phone != null) {
2190 return phone.getDataActivationState();
2191 } else {
2192 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2193 }
2194 }
2195
2196 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 * Returns the unread count of voicemails
2198 */
2199 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002200 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002201 }
2202
2203 /**
2204 * Returns the unread count of voicemails for a subId
2205 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 final Phone phone = getPhone(subId);
2209 if (phone != null) {
2210 return phone.getVoiceMessageCount();
2211 } else {
2212 return 0;
2213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
2216 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002217 * returns true, if the device is in a state where both voice and data
2218 * are supported simultaneously. This can change based on location or network condition.
2219 */
2220 @Override
2221 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2222 final Phone phone = getPhone(subId);
2223 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2224 }
2225
2226 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002227 * Send the dialer code if called from the current default dialer or the caller has
2228 * carrier privilege.
2229 * @param inputCode The dialer code to send
2230 */
2231 @Override
2232 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2233 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2234 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2235 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2237 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002238 }
2239 mPhone.sendDialerSpecialCode(inputCode);
2240 }
2241
2242 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002243 * Returns the data network type.
2244 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 *
2246 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2247 */
2248 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002249 public int getNetworkType() {
2250 final Phone phone = getPhone(getDefaultSubscription());
2251 if (phone != null) {
2252 return phone.getServiceState().getDataNetworkType();
2253 } else {
2254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2255 }
Wink Saville36469e72014-06-11 15:17:00 -07002256 }
2257
2258 /**
2259 * Returns the network type for a subId
2260 */
2261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002264 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2266 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002267
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 return phone.getServiceState().getDataNetworkType();
2271 } else {
2272 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 }
2275
2276 /**
2277 * Returns the data network type
2278 */
2279 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 public int getDataNetworkType(String callingPackage) {
2281 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002282 }
2283
2284 /**
2285 * Returns the data network type for a subId
2286 */
2287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002290 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2292 }
2293
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 final Phone phone = getPhone(subId);
2295 if (phone != null) {
2296 return phone.getServiceState().getDataNetworkType();
2297 } else {
2298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 /**
Wink Saville36469e72014-06-11 15:17:00 -07002303 * Returns the Voice network type for a subId
2304 */
2305 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002306 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002308 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002309 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2310 }
2311
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 final Phone phone = getPhone(subId);
2313 if (phone != null) {
2314 return phone.getServiceState().getVoiceNetworkType();
2315 } else {
2316 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
2320 /**
2321 * @return true if a ICC card is present
2322 */
2323 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002324 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002325 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2326 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002327 }
2328
2329 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002330 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002331 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002332 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002333 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2334 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002335 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002337 } else {
2338 return false;
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
2342 /**
2343 * Return if the current radio is LTE on CDMA. This
2344 * is a tri-state return value as for a period of time
2345 * the mode may be unknown.
2346 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002349 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002351 @Override
2352 public int getLteOnCdmaMode(String callingPackage) {
2353 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002354 }
2355
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002357 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002359 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002360 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2361 }
2362
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 final Phone phone = getPhone(subId);
2364 if (phone == null) {
2365 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2366 } else {
2367 return phone.getLteOnCdmaMode();
2368 }
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
2371 public void setPhone(Phone phone) {
2372 mPhone = phone;
2373 }
2374
2375 /**
2376 * {@hide}
2377 * Returns Default subId, 0 in the case of single standby.
2378 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002379 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002380 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Shishir Agrawala9f32182016-04-12 12:00:16 -07002383 private int getSlotForDefaultSubscription() {
2384 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2385 }
2386
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002388 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002390
2391 /**
2392 * @see android.telephony.TelephonyManager.WifiCallingChoices
2393 */
2394 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002395 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2396 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002397 }
2398
2399 /**
2400 * @see android.telephony.TelephonyManager.WifiCallingChoices
2401 */
2402 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002403 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2404 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2405 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002406 }
2407
Sailesh Nepald1e68152013-12-12 19:08:02 -08002408 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002409 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002410 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002411 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002412
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002414 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2415 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2417 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418
Derek Tan740e1672017-06-27 14:56:27 -07002419 if (TextUtils.equals(ISDR_AID, aid)) {
2420 // Only allows LPA to open logical channel to ISD-R.
2421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2422 ComponentInfo bestComponent =
2423 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2424 if (bestComponent == null
2425 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2426 loge("The calling package is not allowed to access ISD-R.");
2427 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2428 }
2429 }
2430
2431 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002432 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002433 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002434 if (DBG) log("iccOpenLogicalChannel: " + response);
2435 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436 }
2437
2438 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2441 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002442
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002443 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002444 if (channel < 0) {
2445 return false;
2446 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002448 if (DBG) log("iccCloseLogicalChannel: " + success);
2449 return success;
2450 }
2451
2452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002454 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2456 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002457
2458 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2460 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002461 " data=" + data);
2462 }
2463
2464 if (channel < 0) {
2465 return "";
2466 }
2467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002470 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2471
Shishir Agrawal566b7612013-10-28 14:41:00 -07002472 // Append the returned status code to the end of the response payload.
2473 String s = Integer.toHexString(
2474 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002475 if (response.payload != null) {
2476 s = IccUtils.bytesToHexString(response.payload) + s;
2477 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002478 return s;
2479 }
Jake Hambye994d462014-02-03 13:10:13 -08002480
Evan Charltonc66da362014-05-16 14:06:40 -07002481 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002482 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2483 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2485 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002487 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2488 && TextUtils.equals(ISDR_AID, data)) {
2489 // Only allows LPA to select ISD-R.
2490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2491 ComponentInfo bestComponent =
2492 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2493 if (bestComponent == null
2494 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2495 loge("The calling package is not allowed to select ISD-R.");
2496 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2497 }
2498 }
2499
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002500 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002501 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2502 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002503 }
2504
2505 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002506 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002507 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2508
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002509 // Append the returned status code to the end of the response payload.
2510 String s = Integer.toHexString(
2511 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002512 if (response.payload != null) {
2513 s = IccUtils.bytesToHexString(response.payload) + s;
2514 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515 return s;
2516 }
2517
2518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002520 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2522 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002523
2524 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002526 p1 + " " + p2 + " " + p3 + ":" + filePath);
2527 }
2528
2529 IccIoResult response =
2530 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002531 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2532 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002533
2534 if (DBG) {
2535 log("Exchange SIM_IO [R]" + response);
2536 }
2537
2538 byte[] result = null;
2539 int length = 2;
2540 if (response.payload != null) {
2541 length = 2 + response.payload.length;
2542 result = new byte[length];
2543 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2544 } else {
2545 result = new byte[length];
2546 }
2547
2548 result[length - 1] = (byte) response.sw2;
2549 result[length - 2] = (byte) response.sw1;
2550 return result;
2551 }
2552
Nathan Haroldb3014052017-01-25 15:57:32 -08002553 /**
2554 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2555 * on a particular subscription
2556 */
2557 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002558 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002559 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2560 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002561 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2562 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2563 return null;
2564 }
2565 Object response = sendRequest(
2566 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2567 if (response instanceof String[]) {
2568 return (String[]) response;
2569 }
2570 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2571 return null;
2572 }
2573
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002575 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2577 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002578
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002579 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002580 if (response.payload == null) {
2581 return "";
2582 }
2583
2584 // Append the returned status code to the end of the response payload.
2585 String s = Integer.toHexString(
2586 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2587 s = IccUtils.bytesToHexString(response.payload) + s;
2588 return s;
2589 }
2590
Jake Hambye994d462014-02-03 13:10:13 -08002591 /**
2592 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2593 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2594 *
2595 * @param itemID the ID of the item to read
2596 * @return the NV item as a String, or null on error.
2597 */
2598 @Override
2599 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2601 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002602 if (DBG) log("nvReadItem: item " + itemID);
2603 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2604 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2605 return value;
2606 }
2607
2608 /**
2609 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2610 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2611 *
2612 * @param itemID the ID of the item to read
2613 * @param itemValue the value to write, as a String
2614 * @return true on success; false on any failure
2615 */
2616 @Override
2617 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002620 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2621 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2622 new Pair<Integer, String>(itemID, itemValue));
2623 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2624 return success;
2625 }
2626
2627 /**
2628 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2629 * Used for device configuration by some CDMA operators.
2630 *
2631 * @param preferredRoamingList byte array containing the new PRL
2632 * @return true on success; false on any failure
2633 */
2634 @Override
2635 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2637 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002638 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2639 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2640 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2641 return success;
2642 }
2643
2644 /**
2645 * Perform the specified type of NV config reset.
2646 * Used for device configuration by some CDMA operators.
2647 *
2648 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2649 * @return true on success; false on any failure
2650 */
2651 @Override
2652 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2654 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002655 if (DBG) log("nvResetConfig: type " + resetType);
2656 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2657 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2658 return success;
2659 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002660
Svet Ganovb320e182015-04-16 12:30:10 -07002661 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002663 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002664 return new String[0];
2665 }
2666
2667
ram87fca6f2014-07-18 18:58:44 +05302668 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002669 }
2670
Brad Ebinger51f743a2017-01-23 13:50:20 -08002671 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002672 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2673 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002674 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002675 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002676 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002677 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002678 }
2679
2680 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002681 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2682 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002683 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002684 public void disableIms(int slotId) {
2685 enforceModifyPermission();
2686 PhoneFactory.getImsResolver().disableIms(slotId);
2687 }
2688
2689 /**
2690 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2691 * feature or {@link null} if the service is not available. If the feature is available, the
2692 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2693 */
2694 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002695 IImsServiceFeatureCallback callback) {
2696 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002697 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002698 }
2699
2700 /**
2701 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2702 * feature during emergency calling or {@link null} if the service is not available. If the
2703 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2704 * listener for feature updates.
2705 */
2706 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2707 enforceModifyPermission();
2708 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002709 }
2710
Brad Ebinger7e934f52017-12-14 14:26:15 -08002711 /**
2712 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2713 * specified.
2714 */
2715 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2716 enforceModifyPermission();
2717 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2718 }
2719
Brad Ebingera12246d2018-01-16 09:39:35 -08002720 /**
2721 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2722 * specified.
2723 */
2724 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2725 enforceModifyPermission();
2726 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2727 }
2728
Brad Ebinger884c07b2018-02-15 16:17:40 -08002729 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002730 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2731 * available, false if the IMS resolver is idle.
2732 */
2733 public boolean isResolvingImsBinding() {
2734 enforceModifyPermission();
2735 return PhoneFactory.getImsResolver().isResolvingBinding();
2736 }
2737
Wink Saville36469e72014-06-11 15:17:00 -07002738 public void setImsRegistrationState(boolean registered) {
2739 enforceModifyPermission();
2740 mPhone.setImsRegistrationState(registered);
2741 }
2742
2743 /**
Stuart Scott54788802015-03-30 13:18:01 -07002744 * Set the network selection mode to automatic.
2745 *
2746 */
2747 @Override
2748 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2750 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002751 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2752 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2753 }
2754
2755 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002756 * Set the network selection mode to manual with the selected carrier.
2757 */
2758 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002759 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002760 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2762 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002763 OperatorInfo operator = new OperatorInfo(
2764 /* operatorAlphaLong */ "",
2765 /* operatorAlphaShort */ "",
2766 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002767 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002768 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2769 persistSelection);
2770 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002771 }
2772
2773 /**
2774 * Scans for available networks.
2775 */
2776 @Override
2777 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2779 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002780 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2781 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2782 CMD_PERFORM_NETWORK_SCAN, null, subId);
2783 return result;
2784 }
2785
2786 /**
yinxub1bed742017-04-17 11:45:04 -07002787 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002788 *
yinxub1bed742017-04-17 11:45:04 -07002789 * @param subId id of the subscription
2790 * @param request contains the radio access networks with bands/channels to scan
2791 * @param messenger callback messenger for scan results or errors
2792 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002793 * @return the id of the requested scan which can be used to stop the scan.
2794 */
2795 @Override
2796 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2797 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2799 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002800 return mNetworkScanRequestTracker.startNetworkScan(
2801 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002802 }
2803
2804 /**
2805 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002806 *
2807 * @param subId id of the subscription
2808 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002809 */
2810 @Override
2811 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2813 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002814 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002815 }
2816
2817 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002818 * Get the calculated preferred network type.
2819 * Used for debugging incorrect network type.
2820 *
2821 * @return the preferred network type, defined in RILConstants.java.
2822 */
2823 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002824 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002826 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002827 return RILConstants.PREFERRED_NETWORK_MODE;
2828 }
2829
Amit Mahajan43330e02014-11-18 11:54:45 -08002830 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002831 }
2832
2833 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002834 * Get the preferred network type.
2835 * Used for device configuration by some CDMA operators.
2836 *
2837 * @return the preferred network type, defined in RILConstants.java.
2838 */
2839 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002840 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002843 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002844 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002845 int networkType = (result != null ? result[0] : -1);
2846 if (DBG) log("getPreferredNetworkType: " + networkType);
2847 return networkType;
2848 }
2849
2850 /**
2851 * Set the preferred network type.
2852 * Used for device configuration by some CDMA operators.
2853 *
2854 * @param networkType the preferred network type, defined in RILConstants.java.
2855 * @return true on success; false on any failure.
2856 */
2857 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002858 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2860 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002861 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2862 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002863 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002864 if (success) {
2865 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002866 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002867 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002868 return success;
2869 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002870
2871 /**
Junda Liu475951f2014-11-07 16:45:03 -08002872 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2873 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2874 * tethering.
2875 *
2876 * @return 0: Not required. 1: required. 2: Not set.
2877 * @hide
2878 */
2879 @Override
2880 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002881 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002882 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2883 Settings.Global.TETHER_DUN_REQUIRED, 2);
2884 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2885 // config_tether_apndata.
2886 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2887 dunRequired = 1;
2888 }
2889 return dunRequired;
2890 }
2891
2892 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002893 * Set mobile data enabled
2894 * Used by the user through settings etc to turn on/off mobile data
2895 *
2896 * @param enable {@code true} turn turn data on, else {@code false}
2897 */
2898 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002899 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2901 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002902 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002903 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002904 Phone phone = PhoneFactory.getPhone(phoneId);
2905 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002906 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2907 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002908 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002909 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002910 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002911 }
2912
2913 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002914 * Get the user enabled state of Mobile Data.
2915 *
2916 * TODO: remove and use isUserDataEnabled.
2917 * This can't be removed now because some vendor codes
2918 * calls through ITelephony directly while they should
2919 * use TelephonyManager.
2920 *
2921 * @return true on enabled
2922 */
2923 @Override
2924 public boolean getDataEnabled(int subId) {
2925 return isUserDataEnabled(subId);
2926 }
2927
2928 /**
2929 * Get whether mobile data is enabled per user setting.
2930 *
2931 * There are other factors deciding whether mobile data is actually enabled, but they are
2932 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002933 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002934 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002935 *
2936 * @return {@code true} if data is enabled else {@code false}
2937 */
2938 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002939 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002940 try {
2941 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2942 null);
2943 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2945 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002946 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002947 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002948 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002949 Phone phone = PhoneFactory.getPhone(phoneId);
2950 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002951 boolean retVal = phone.isUserDataEnabled();
2952 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002953 return retVal;
2954 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002955 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2956 return false;
2957 }
2958 }
2959
2960 /**
2961 * Get whether mobile data is enabled.
2962 *
2963 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2964 * whether mobile data is actually enabled.
2965 *
2966 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2967 *
2968 * @return {@code true} if data is enabled else {@code false}
2969 */
2970 @Override
2971 public boolean isDataEnabled(int subId) {
2972 try {
2973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2974 null);
2975 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2977 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002978 }
2979 int phoneId = mSubscriptionController.getPhoneId(subId);
2980 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2981 Phone phone = PhoneFactory.getPhone(phoneId);
2982 if (phone != null) {
2983 boolean retVal = phone.isDataEnabled();
2984 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2985 return retVal;
2986 } else {
2987 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002988 return false;
2989 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002990 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002991
2992 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002993 public int getCarrierPrivilegeStatus(int subId) {
2994 final Phone phone = getPhone(subId);
2995 if (phone == null) {
2996 loge("getCarrierPrivilegeStatus: Invalid subId");
2997 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2998 }
2999 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003000 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003001 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003002 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3003 }
3004 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003005 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003006 }
Junda Liu29340342014-07-10 15:23:27 -07003007
3008 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003009 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3010 final Phone phone = getPhone(subId);
3011 if (phone == null) {
3012 loge("getCarrierPrivilegeStatus: Invalid subId");
3013 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3014 }
3015 UiccProfile profile =
3016 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3017 if (profile == null) {
3018 loge("getCarrierPrivilegeStatus: No UICC");
3019 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3020 }
3021 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3022 }
3023
3024 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003025 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003026 if (TextUtils.isEmpty(pkgName))
3027 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003028 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003029 if (card == null) {
3030 loge("checkCarrierPrivilegesForPackage: No UICC");
3031 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3032 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003033 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3034 }
3035
3036 @Override
3037 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003038 if (TextUtils.isEmpty(pkgName))
3039 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003040 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3041 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3042 UiccCard card = UiccController.getInstance().getUiccCard(i);
3043 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003044 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003045 continue;
3046 }
3047
3048 result = card.getCarrierPrivilegeStatus(
3049 mPhone.getContext().getPackageManager(), pkgName);
3050 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3051 break;
3052 }
3053 }
3054
3055 return result;
Junda Liu29340342014-07-10 15:23:27 -07003056 }
Derek Tan89e89d42014-07-08 17:00:10 -07003057
3058 @Override
Junda Liue64de782015-04-16 17:19:16 -07003059 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3060 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3061 loge("phoneId " + phoneId + " is not valid.");
3062 return null;
3063 }
3064 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003065 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003066 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003067 return null ;
3068 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003069 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003070 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003071 }
3072
Amith Yamasani6e118872016-02-19 12:53:51 -08003073 @Override
3074 public List<String> getPackagesWithCarrierPrivileges() {
3075 PackageManager pm = mPhone.getContext().getPackageManager();
3076 List<String> privilegedPackages = new ArrayList<>();
3077 List<PackageInfo> packages = null;
3078 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3079 UiccCard card = UiccController.getInstance().getUiccCard(i);
3080 if (card == null) {
3081 // No UICC in that slot.
3082 continue;
3083 }
3084 if (card.hasCarrierPrivilegeRules()) {
3085 if (packages == null) {
3086 // Only check packages in user 0 for now
3087 packages = pm.getInstalledPackagesAsUser(
3088 PackageManager.MATCH_DISABLED_COMPONENTS
3089 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3090 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3091 }
3092 for (int p = packages.size() - 1; p >= 0; p--) {
3093 PackageInfo pkgInfo = packages.get(p);
3094 if (pkgInfo != null && pkgInfo.packageName != null
3095 && card.getCarrierPrivilegeStatus(pkgInfo)
3096 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3097 privilegedPackages.add(pkgInfo.packageName);
3098 }
3099 }
3100 }
3101 }
3102 return privilegedPackages;
3103 }
3104
Wink Savilleb564aae2014-10-23 10:18:09 -07003105 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003106 final Phone phone = getPhone(subId);
3107 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003108 if (card == null) {
3109 loge("getIccId: No UICC");
3110 return null;
3111 }
3112 String iccId = card.getIccId();
3113 if (TextUtils.isEmpty(iccId)) {
3114 loge("getIccId: ICC ID is null or empty.");
3115 return null;
3116 }
3117 return iccId;
3118 }
3119
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003120 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003121 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3122 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003123 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3124 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003125
Jeff Sharkey85190e62014-12-05 09:40:12 -08003126 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003127 final Phone phone = getPhone(subId);
3128 if (phone == null) {
3129 return false;
3130 }
3131 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003132
3133 if (DBG_MERGE) {
3134 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3135 + subscriberId + " to " + number);
3136 }
3137
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003138 if (TextUtils.isEmpty(iccId)) {
3139 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003140 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003141
Jeff Sharkey85190e62014-12-05 09:40:12 -08003142 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3143
3144 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003145 if (alphaTag == null) {
3146 editor.remove(alphaTagPrefKey);
3147 } else {
3148 editor.putString(alphaTagPrefKey, alphaTag);
3149 }
3150
Jeff Sharkey85190e62014-12-05 09:40:12 -08003151 // Record both the line number and IMSI for this ICCID, since we need to
3152 // track all merged IMSIs based on line number
3153 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3154 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003155 if (number == null) {
3156 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003157 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003158 } else {
3159 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003160 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003161 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003162
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003163 editor.commit();
3164 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003165 }
3166
3167 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003168 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003169 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003171 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003172 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003173 return null;
3174 }
Derek Tan97ebb422014-09-05 16:55:38 -07003175
3176 String iccId = getIccId(subId);
3177 if (iccId != null) {
3178 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003179 if (DBG_MERGE) {
3180 log("getLine1NumberForDisplay returning " +
3181 mTelephonySharedPreferences.getString(numberPrefKey, null));
3182 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003183 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003184 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003185 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003186 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003187 }
3188
3189 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003190 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003192 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003193 return null;
3194 }
Derek Tan97ebb422014-09-05 16:55:38 -07003195
3196 String iccId = getIccId(subId);
3197 if (iccId != null) {
3198 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003199 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003200 }
Derek Tan97ebb422014-09-05 16:55:38 -07003201 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003202 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003203
3204 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003205 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003206 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3207 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003209 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3210 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003211 return null;
3212 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003213 final Context context = mPhone.getContext();
3214 final TelephonyManager tele = TelephonyManager.from(context);
3215 final SubscriptionManager sub = SubscriptionManager.from(context);
3216
3217 // Figure out what subscribers are currently active
3218 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003219 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3220 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final int[] subIds = sub.getActiveSubscriptionIdList();
3224 for (int subId : subIds) {
3225 activeSubscriberIds.add(tele.getSubscriberId(subId));
3226 }
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003229 }
3230
3231 // First pass, find a number override for an active subscriber
3232 String mergeNumber = null;
3233 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3234 for (String key : prefs.keySet()) {
3235 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3236 final String subscriberId = (String) prefs.get(key);
3237 if (activeSubscriberIds.contains(subscriberId)) {
3238 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3239 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3240 mergeNumber = (String) prefs.get(numberKey);
3241 if (DBG_MERGE) {
3242 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3243 + " for active subscriber " + subscriberId);
3244 }
3245 if (!TextUtils.isEmpty(mergeNumber)) {
3246 break;
3247 }
3248 }
3249 }
3250 }
3251
3252 // Shortcut when no active merged subscribers
3253 if (TextUtils.isEmpty(mergeNumber)) {
3254 return null;
3255 }
3256
3257 // Second pass, find all subscribers under that line override
3258 final ArraySet<String> result = new ArraySet<>();
3259 for (String key : prefs.keySet()) {
3260 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3261 final String number = (String) prefs.get(key);
3262 if (mergeNumber.equals(number)) {
3263 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3264 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3265 final String subscriberId = (String) prefs.get(subscriberKey);
3266 if (!TextUtils.isEmpty(subscriberId)) {
3267 result.add(subscriberId);
3268 }
3269 }
3270 }
3271 }
3272
3273 final String[] resultArray = result.toArray(new String[result.size()]);
3274 Arrays.sort(resultArray);
3275 if (DBG_MERGE) {
3276 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3277 }
3278 return resultArray;
3279 }
3280
3281 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003282 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003283 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3284 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003285 final Phone phone = getPhone(subId);
3286 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003287 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003288
3289 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003290 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003291 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3292 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003293 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003294 final Phone phone = getPhone(subId);
3295 if (phone == null) {
3296 return false;
3297 }
3298 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003299 cdmaNonRoamingList);
3300 }
3301
3302 @Override
Shuo Qian74b16b12018-04-27 01:32:07 +00003303 @Deprecated
3304 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3305 enforceModifyPermission();
3306
3307 int returnValue = 0;
3308 try {
3309 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3310 if(result.exception == null) {
3311 if (result.result != null) {
3312 byte[] responseData = (byte[])(result.result);
3313 if(responseData.length > oemResp.length) {
3314 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3315 responseData.length + "bytes. Buffer Size is " +
3316 oemResp.length + "bytes.");
3317 }
3318 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3319 returnValue = responseData.length;
3320 }
3321 } else {
3322 CommandException ex = (CommandException) result.exception;
3323 returnValue = ex.getCommandError().ordinal();
3324 if(returnValue > 0) returnValue *= -1;
3325 }
3326 } catch (RuntimeException e) {
3327 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3328 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3329 if(returnValue > 0) returnValue *= -1;
3330 }
3331
3332 return returnValue;
3333 }
3334
3335 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003336 public void setRadioCapability(RadioAccessFamily[] rafs) {
3337 try {
3338 ProxyController.getInstance().setRadioCapability(rafs);
3339 } catch (RuntimeException e) {
3340 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3341 }
3342 }
3343
3344 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003345 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003346 Phone phone = PhoneFactory.getPhone(phoneId);
3347 if (phone == null) {
3348 return RadioAccessFamily.RAF_UNKNOWN;
3349 }
3350 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003352 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003353 return RadioAccessFamily.RAF_UNKNOWN;
3354 }
3355
Wink Saville5d475dd2014-10-17 15:00:58 -07003356 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3357 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003358
3359 @Override
3360 public void enableVideoCalling(boolean enable) {
3361 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003362 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003363 }
3364
3365 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003366 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003368 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003369 return false;
3370 }
3371
Andrew Lee77527ac2014-10-21 16:57:39 -07003372 // Check the user preference and the system-level IMS setting. Even if the user has
3373 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3374 // In the long run, we may instead need to check if there exists a connection service
3375 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003376 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3377 return imsManager.isVtEnabledByPlatform()
3378 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3379 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003380 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003381
Andrew Leea1239f22015-03-02 17:44:07 -08003382 @Override
3383 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003384 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003385 }
3386
3387 @Override
3388 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003389 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003390 }
3391
Andrew Lee9431b832015-03-09 18:46:45 -07003392 @Override
3393 public boolean isTtyModeSupported() {
3394 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3395 TelephonyManager telephonyManager =
3396 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003397 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003398 }
3399
3400 @Override
3401 public boolean isHearingAidCompatibilitySupported() {
3402 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3403 }
3404
Hall Liu73714012018-01-22 19:15:32 -08003405 public boolean isRttSupported() {
3406 boolean isCarrierSupported =
3407 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3408 boolean isDeviceSupported =
3409 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3410 return isCarrierSupported && isDeviceSupported;
3411 }
3412
Hall Liub1585172018-04-06 16:23:39 -07003413 public boolean isRttEnabled() {
3414 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3415 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3416 }
3417
Sanket Padawe7310cc72015-01-14 09:53:20 -08003418 /**
3419 * Returns the unique device ID of phone, for example, the IMEI for
3420 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3421 *
3422 * <p>Requires Permission:
3423 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3424 */
3425 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003426 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003427 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003428 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003429 return null;
3430 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003431 int subId = phone.getSubId();
3432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3433 mApp, subId, callingPackage, "getDeviceId")) {
3434 return null;
3435 }
3436 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003437 }
3438
Ping Sun014fe8e2016-03-02 19:16:45 +08003439 /**
3440 * {@hide}
3441 * Returns the IMS Registration Status on a particular subid
3442 *
3443 * @param subId
3444 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003445 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003446 Phone phone = getPhone(subId);
3447 if (phone != null) {
3448 return phone.isImsRegistered();
3449 } else {
3450 return false;
3451 }
3452 }
3453
Santos Cordon7a1885b2015-02-03 11:15:19 -08003454 @Override
3455 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3456 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3457 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003458
Brad Ebingere21f25f2018-02-08 16:11:32 -08003459 /**
3460 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003461 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003462 public boolean isWifiCallingAvailable(int subId) {
3463 Phone phone = getPhone(subId);
3464 if (phone != null) {
3465 return phone.isWifiCallingEnabled();
3466 } else {
3467 return false;
3468 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003469 }
3470
Brad Ebingere21f25f2018-02-08 16:11:32 -08003471 /**
3472 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003473 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003474 public boolean isVolteAvailable(int subId) {
3475 Phone phone = getPhone(subId);
3476 if (phone != null) {
3477 return phone.isVolteEnabled();
3478 } else {
3479 return false;
3480 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003481 }
Svet Ganovb320e182015-04-16 12:30:10 -07003482
Brad Ebingere21f25f2018-02-08 16:11:32 -08003483 /**
3484 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003485 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003486 public boolean isVideoTelephonyAvailable(int subId) {
3487 Phone phone = getPhone(subId);
3488 if (phone != null) {
3489 return phone.isVideoEnabled();
3490 } else {
3491 return false;
3492 }
3493 }
3494
3495 /**
3496 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3497 * defined in {@link ImsRegistrationImplBase}.
3498 */
3499 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3500 Phone phone = getPhone(subId);
3501 if (phone != null) {
3502 return phone.getImsRegistrationTech();
3503 } else {
3504 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3505 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003506 }
3507
Stuart Scott8eef64f2015-04-08 15:13:54 -07003508 @Override
3509 public void factoryReset(int subId) {
3510 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003511 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3512 return;
3513 }
3514
Svet Ganovcc087f82015-05-12 20:35:54 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003517 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3518 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003519 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003520 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003521 // Set network selection mode to automatic
3522 setNetworkSelectionModeAutomatic(subId);
3523 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003524 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3525 mSubscriptionController.getPhoneId(subId),
3526 "ro.telephony.default_network",
3527 null);
3528 int networkType = !TextUtils.isEmpty(defaultNetwork)
3529 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3530 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003531 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003532 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003536 }
3537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003538
3539 @Override
3540 public String getLocaleFromDefaultSim() {
3541 // We query all subscriptions instead of just the active ones, because
3542 // this might be called early on in the provisioning flow when the
3543 // subscriptions potentially aren't active yet.
3544 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3545 if (slist == null || slist.isEmpty()) {
3546 return null;
3547 }
3548
3549 // This function may be called very early, say, from the setup wizard, at
3550 // which point we won't have a default subscription set. If that's the case
3551 // we just choose the first, which will be valid in "most cases".
3552 final int defaultSubId = getDefaultSubscription();
3553 SubscriptionInfo info = null;
3554 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3555 info = slist.get(0);
3556 } else {
3557 for (SubscriptionInfo item : slist) {
3558 if (item.getSubscriptionId() == defaultSubId) {
3559 info = item;
3560 break;
3561 }
3562 }
3563
3564 if (info == null) {
3565 return null;
3566 }
3567 }
3568
3569 // Try and fetch the locale from the carrier properties or from the SIM language
3570 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003571 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003572 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003573 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003574 if (defaultPhone != null) {
3575 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3576 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003577 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003578 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3579 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003580 } else {
3581 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003582 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003583 }
3584 }
3585
Narayan Kamath011676f2015-07-29 12:04:08 +01003586 // The SIM language preferences only store a language (e.g. fr = French), not an
3587 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3588 // the SIM and carrier preferences does not include a country we add the country
3589 // determined from the SIM MCC to provide an exact locale.
3590 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003591 if (mccLocale != null) {
3592 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3593 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003594 }
3595
Tony Hill183b2de2015-06-24 14:53:58 +01003596 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003597 return null;
3598 }
3599
3600 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 return mSubscriptionController.getAllSubInfoList(
3604 mPhone.getContext().getOpPackageName());
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
3609
3610 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 return mSubscriptionController.getActiveSubscriptionInfoList(
3614 mPhone.getContext().getOpPackageName());
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
3617 }
3618 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003619
3620 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003621 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3622 * representing the state of the modem.
3623 *
3624 * NOTE: This clears the modem state, so there should only every be one caller.
3625 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003626 */
3627 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003628 public void requestModemActivityInfo(ResultReceiver result) {
3629 enforceModifyPermission();
3630
3631 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3632 Bundle bundle = new Bundle();
3633 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3634 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003635 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003636
3637 /**
3638 * {@hide}
3639 * Returns the service state information on specified subscription.
3640 */
3641 @Override
3642 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3643
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003645 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003646 return null;
3647 }
3648
3649 final Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 return null;
3652 }
3653
3654 return phone.getServiceState();
3655 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003656
3657 /**
3658 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3659 *
3660 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3661 * voicemail ringtone.
3662 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3663 * PhoneAccount.
3664 */
3665 @Override
3666 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003667 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003668 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003669 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003670 }
3671
fionaxu7ed723d2017-05-30 18:58:54 -07003672 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003673 }
3674
3675 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003676 * Sets the per-account voicemail ringtone.
3677 *
3678 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3679 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3680 *
3681 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3682 * voicemail ringtone.
3683 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3684 * PhoneAccount.
3685 */
3686 @Override
3687 public void setVoicemailRingtoneUri(String callingPackage,
3688 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3690 if (!TextUtils.equals(callingPackage,
3691 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3693 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3694 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003695 }
3696 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3697 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003698 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003699 }
fionaxu7ed723d2017-05-30 18:58:54 -07003700 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003701 }
3702
3703 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003704 * Returns whether vibration is set for voicemail notification in Phone settings.
3705 *
3706 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3707 * voicemail vibration setting.
3708 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3709 */
3710 @Override
3711 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003712 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003713 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003714 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003715 }
3716
fionaxu7ed723d2017-05-30 18:58:54 -07003717 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003718 }
3719
Youhan Wange64578a2016-05-02 15:32:42 -07003720 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003721 * Sets the per-account voicemail vibration.
3722 *
3723 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3724 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3725 *
3726 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3727 * voicemail vibration setting.
3728 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3729 * specific PhoneAccount.
3730 */
3731 @Override
3732 public void setVoicemailVibrationEnabled(String callingPackage,
3733 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3735 if (!TextUtils.equals(callingPackage,
3736 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3738 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3739 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003740 }
3741
3742 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3743 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003744 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003745 }
fionaxu7ed723d2017-05-30 18:58:54 -07003746 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003747 }
3748
3749 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003750 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3751 *
3752 * @throws SecurityException if the caller does not have the required permission
3753 */
3754 private void enforceReadPrivilegedPermission() {
3755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3756 null);
3757 }
3758
3759 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003760 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3761 * permission.
3762 *
3763 * @throws SecurityException if the caller does not have the required permission
3764 */
3765 private void enforceSendSmsPermission() {
3766 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3767 }
3768
3769 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003770 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003771 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003772 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003773 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003774 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003775 ComponentName componentName =
3776 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3777 if(componentName == null) {
3778 throw new SecurityException("Caller not current active visual voicemail package[null]");
3779 }
3780 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003781 if (!callingPackage.equals(vvmPackage)) {
3782 throw new SecurityException("Caller not current active visual voicemail package[" +
3783 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003784 }
3785 }
3786
3787 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003788 * Return the application ID for the app type.
3789 *
3790 * @param subId the subscription ID that this request applies to.
3791 * @param appType the uicc app type.
3792 * @return Application ID for specificied app type, or null if no uicc.
3793 */
3794 @Override
3795 public String getAidForAppType(int subId, int appType) {
3796 enforceReadPrivilegedPermission();
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 return null;
3800 }
3801 String aid = null;
3802 try {
3803 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3804 .getApplicationByType(appType).getAid();
3805 } catch (Exception e) {
3806 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3807 }
3808 return aid;
3809 }
3810
Youhan Wang4001d252016-05-11 10:29:41 -07003811 /**
3812 * Return the Electronic Serial Number.
3813 *
3814 * @param subId the subscription ID that this request applies to.
3815 * @return ESN or null if error.
3816 */
3817 @Override
3818 public String getEsn(int subId) {
3819 enforceReadPrivilegedPermission();
3820 Phone phone = getPhone(subId);
3821 if (phone == null) {
3822 return null;
3823 }
3824 String esn = null;
3825 try {
3826 esn = phone.getEsn();
3827 } catch (Exception e) {
3828 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3829 }
3830 return esn;
3831 }
3832
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003833 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003834 * Return the Preferred Roaming List Version.
3835 *
3836 * @param subId the subscription ID that this request applies to.
3837 * @return PRLVersion or null if error.
3838 */
3839 @Override
3840 public String getCdmaPrlVersion(int subId) {
3841 enforceReadPrivilegedPermission();
3842 Phone phone = getPhone(subId);
3843 if (phone == null) {
3844 return null;
3845 }
3846 String cdmaPrlVersion = null;
3847 try {
3848 cdmaPrlVersion = phone.getCdmaPrlVersion();
3849 } catch (Exception e) {
3850 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3851 }
3852 return cdmaPrlVersion;
3853 }
3854
3855 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003856 * Get snapshot of Telephony histograms
3857 * @return List of Telephony histograms
3858 * @hide
3859 */
3860 @Override
3861 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3863 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003864 return RIL.getTelephonyRILTimingHistograms();
3865 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003866
3867 /**
3868 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003869 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003870 * Require system privileges. In the future we may add this to carrier APIs.
3871 *
3872 * @return The number of carriers set successfully, should match length of carriers
3873 */
3874 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003875 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003876 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003877
Meng Wang9b7c4e92017-02-17 11:41:27 -08003878 if (carriers == null) {
3879 throw new NullPointerException("carriers cannot be null");
3880 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003881
3882 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003883 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3884 return retVal[0];
3885 }
3886
3887 /**
3888 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003889 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003890 * Require system privileges. In the future we may add this to carrier APIs.
3891 *
3892 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3893 * means all carriers are allowed.
3894 */
3895 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003896 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003897 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003898 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003899 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3900 }
3901
fionaxu59545b42016-05-25 15:53:37 -07003902 /**
3903 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3904 * @param subId the subscription ID that this action applies to.
3905 * @param enabled control enable or disable metered apns.
3906 * {@hide}
3907 */
3908 @Override
3909 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3910 enforceModifyPermission();
3911 final Phone phone = getPhone(subId);
3912 if (phone == null) {
3913 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3914 return;
3915 }
3916 try {
3917 phone.carrierActionSetMeteredApnsEnabled(enabled);
3918 } catch (Exception e) {
3919 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3920 }
3921 }
3922
3923 /**
3924 * Action set from carrier signalling broadcast receivers to enable/disable radio
3925 * @param subId the subscription ID that this action applies to.
3926 * @param enabled control enable or disable radio.
3927 * {@hide}
3928 */
3929 @Override
3930 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3931 enforceModifyPermission();
3932 final Phone phone = getPhone(subId);
3933 if (phone == null) {
3934 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3935 return;
3936 }
3937 try {
3938 phone.carrierActionSetRadioEnabled(enabled);
3939 } catch (Exception e) {
3940 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3941 }
3942 }
3943
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003944 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003945 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3946 * network status based on which carrier apps could apply actions accordingly,
3947 * enable/disable default url handler for example.
3948 *
3949 * @param subId the subscription ID that this action applies to.
3950 * @param report control start/stop reporting the default network status.
3951 * {@hide}
3952 */
3953 @Override
3954 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3955 enforceModifyPermission();
3956 final Phone phone = getPhone(subId);
3957 if (phone == null) {
3958 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3959 return;
3960 }
3961 try {
3962 phone.carrierActionReportDefaultNetworkStatus(report);
3963 } catch (Exception e) {
3964 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3965 }
3966 }
3967
3968 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003969 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3970 * bug report is being generated.
3971 */
3972 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003973 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003974 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3975 != PackageManager.PERMISSION_GRANTED) {
3976 writer.println("Permission Denial: can't dump Phone from pid="
3977 + Binder.getCallingPid()
3978 + ", uid=" + Binder.getCallingUid()
3979 + "without permission "
3980 + android.Manifest.permission.DUMP);
3981 return;
3982 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003983 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003984 }
Jack Yueb89b242016-06-22 13:27:47 -07003985
3986 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003987 * Get aggregated video call data usage since boot.
3988 *
3989 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3990 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003991 * {@hide}
3992 */
3993 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003994 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003995 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3996 null);
3997
Jack Yu84291ec2017-05-26 16:07:50 -07003998 // NetworkStatsService keeps tracking the active network interface and identity. It
3999 // records the delta with the corresponding network identity. We just return the total video
4000 // call data usage snapshot since boot.
4001 Phone phone = getPhone(subId);
4002 if (phone != null) {
4003 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004004 }
Jack Yu84291ec2017-05-26 16:07:50 -07004005 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004006 }
Jack Yu75ab2952016-07-08 14:29:33 -07004007
4008 /**
4009 * Policy control of data connection. Usually used when data limit is passed.
4010 * @param enabled True if enabling the data, otherwise disabling.
4011 * @param subId Subscription index
4012 * {@hide}
4013 */
4014 @Override
4015 public void setPolicyDataEnabled(boolean enabled, int subId) {
4016 enforceModifyPermission();
4017 Phone phone = getPhone(subId);
4018 if (phone != null) {
4019 phone.setPolicyDataEnabled(enabled);
4020 }
4021 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004022
4023 /**
4024 * Get Client request stats
4025 * @return List of Client Request Stats
4026 * @hide
4027 */
4028 @Override
4029 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004031 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004032 return null;
4033 }
4034
4035 Phone phone = getPhone(subId);
4036 if (phone != null) {
4037 return phone.getClientRequestStats();
4038 }
4039
4040 return null;
4041 }
4042
4043 private WorkSource getWorkSource(WorkSource workSource, int uid) {
4044 if (workSource != null) {
4045 return workSource;
4046 }
4047
4048 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
4049 workSource = new WorkSource(uid, packageName);
4050 return workSource;
4051 }
Jack Yueb4124c2017-02-16 15:32:43 -08004052
4053 /**
Grace Chen70990072017-03-24 17:21:30 -07004054 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004055 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004056 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004057 * @param state State of SIM (power down, power up, pass through)
4058 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4059 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4060 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004061 *
4062 **/
4063 @Override
Grace Chen70990072017-03-24 17:21:30 -07004064 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004065 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004066 Phone phone = PhoneFactory.getPhone(slotIndex);
4067
Jack Yueb4124c2017-02-16 15:32:43 -08004068 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004069 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004070 }
4071 }
Shuo Qiandd210312017-04-12 22:11:33 +00004072
Tyler Gunn65d45c22017-06-05 11:22:26 -07004073 private boolean isUssdApiAllowed(int subId) {
4074 CarrierConfigManager configManager =
4075 (CarrierConfigManager) mPhone.getContext().getSystemService(
4076 Context.CARRIER_CONFIG_SERVICE);
4077 if (configManager == null) {
4078 return false;
4079 }
4080 PersistableBundle pb = configManager.getConfigForSubId(subId);
4081 if (pb == null) {
4082 return false;
4083 }
4084 return pb.getBoolean(
4085 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4086 }
4087
Shuo Qiandd210312017-04-12 22:11:33 +00004088 /**
4089 * Check if phone is in emergency callback mode
4090 * @return true if phone is in emergency callback mode
4091 * @param subId sub id
4092 */
4093 public boolean getEmergencyCallbackMode(int subId) {
4094 final Phone phone = getPhone(subId);
4095 if (phone != null) {
4096 return phone.isInEcm();
4097 } else {
4098 return false;
4099 }
4100 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004101
4102 /**
4103 * Get the current signal strength information for the given subscription.
4104 * Because this information is not updated when the device is in a low power state
4105 * it should not be relied-upon to be current.
4106 * @param subId Subscription index
4107 * @return the most recent cached signal strength info from the modem
4108 */
4109 @Override
4110 public SignalStrength getSignalStrength(int subId) {
4111 Phone p = getPhone(subId);
4112 if (p == null) {
4113 return null;
4114 }
4115
4116 return p.getSignalStrength();
4117 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004118
4119 @Override
4120 public UiccSlotInfo[] getUiccSlotsInfo() {
4121 enforceReadPrivilegedPermission();
4122
4123 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4124 if (slots == null) return null;
4125 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4126 for (int i = 0; i < slots.length; i++) {
4127 UiccSlot slot = slots[i];
4128
4129 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4130
4131 int cardState = 0;
4132 switch (slot.getCardState()) {
4133 case CARDSTATE_ABSENT:
4134 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4135 break;
4136 case CARDSTATE_PRESENT:
4137 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4138 break;
4139 case CARDSTATE_ERROR:
4140 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4141 break;
4142 case CARDSTATE_RESTRICTED:
4143 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4144 break;
4145 default:
4146 break;
4147
4148 }
4149
Qingxi Li63668902018-01-31 13:43:27 -08004150 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004151 slot.isActive(),
4152 slot.isEuicc(),
4153 cardId,
4154 cardState,
4155 slot.getPhoneId(),
4156 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004157 }
4158 return infos;
4159 }
4160
4161 @Override
4162 public boolean switchSlots(int[] physicalSlots) {
4163 enforceModifyPermission();
4164 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4165 }
Jack Yue6146032018-02-27 15:30:01 -08004166
4167 @Override
4168 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4169 enforceModifyPermission();
4170 final Phone phone = getPhone(subId);
4171 if (phone == null) {
4172 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4173 return;
4174 }
4175
4176 phone.setRadioIndicationUpdateMode(filters, mode);
4177 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07004178
4179 @Override
4180 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4181 gid1, String gid2, String plmn, String spn) {
4182 enforceModifyPermission();
4183 final Phone phone = getPhone(subId);
4184 if (phone == null) {
4185 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4186 return;
4187 }
4188 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4189 }
4190
4191 @Override
4192 public int getCarrierIdListVersion(int subId) {
4193 enforceReadPrivilegedPermission();
4194 final Phone phone = getPhone(subId);
4195 if (phone == null) {
4196 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4197 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4198 }
4199 return phone.getCarrierIdListVersion();
4200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004201}