blob: abfa8d74e6f7da5d0ba48b503e029688aa7d6d81 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070060import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070062import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080063import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070064import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080065import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070066import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070068import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080070import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070071import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080072import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070074import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000076import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070078import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070079import android.telephony.cdma.CdmaCellLocation;
80import android.telephony.gsm.GsmCellLocation;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080081import android.telephony.ims.aidl.IImsConfig;
82import android.telephony.ims.aidl.IImsMmTelFeature;
83import android.telephony.ims.aidl.IImsRcsFeature;
84import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080085import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080091
Andrew Lee312e8172014-10-23 17:01:36 -070092import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080093import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070095import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070096import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800101import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700102import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100103import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700104import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700107import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800108import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700109import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700110import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700113import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700114import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700115import com.android.internal.telephony.SmsApplication;
116import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800117import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800118import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700119import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.uicc.IccIoResult;
121import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700123import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800124import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800126import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000127import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700128import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800131import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700132import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700133import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700135import java.io.FileDescriptor;
136import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800141import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100142import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145/**
146 * Implementation of the ITelephony interface.
147 */
Santos Cordon117fee72014-05-16 17:56:12 -0700148public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149 private static final String LOG_TAG = "PhoneInterfaceManager";
150 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
151 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
154 // Message codes used with mMainThreadHandler
155 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700156 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
157 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158 private static final int CMD_OPEN_CHANNEL = 9;
159 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
160 private static final int CMD_CLOSE_CHANNEL = 11;
161 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800162 private static final int CMD_NV_READ_ITEM = 13;
163 private static final int EVENT_NV_READ_ITEM_DONE = 14;
164 private static final int CMD_NV_WRITE_ITEM = 15;
165 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
166 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
167 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
168 private static final int CMD_NV_RESET_CONFIG = 19;
169 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800170 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
171 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
172 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
173 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800174 private static final int CMD_SEND_ENVELOPE = 25;
175 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000176 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
177 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700178 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
179 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
180 private static final int CMD_EXCHANGE_SIM_IO = 31;
181 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800182 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
183 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700184 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700186 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
187 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
189 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
190 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
191 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700192 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
193 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
194 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
195 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700196 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
198 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000199 private static final int CMD_SWITCH_SLOTS = 50;
200 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700201 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
202 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
203 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
204 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
205 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
206 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
207 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
208 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700209 private static final int CMD_GET_ALL_CELL_INFO = 60;
210 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
211 private static final int CMD_GET_CELL_LOCATION = 62;
212 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800214 // Parameters of select command.
215 private static final int SELECT_COMMAND = 0xA4;
216 private static final int SELECT_P1 = 0x04;
217 private static final int SELECT_P2 = 0;
218 private static final int SELECT_P3 = 0x10;
219
Pengquan Meng85728fb2018-03-12 16:31:21 -0700220 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
221 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
222 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 /** The singleton instance. */
225 private static PhoneInterfaceManager sInstance;
226
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private PhoneGlobals mApp;
228 private Phone mPhone;
229 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700230 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private AppOpsManager mAppOps;
232 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800233 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700235 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
Derek Tan97ebb422014-09-05 16:55:38 -0700237 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
238 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700240
Derek Tan740e1672017-06-27 14:56:27 -0700241 // The AID of ISD-R.
242 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
243
yinxub1bed742017-04-17 11:45:04 -0700244 private NetworkScanRequestTracker mNetworkScanRequestTracker;
245
David Kelly5e06a7f2018-03-12 14:10:59 +0000246 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
247 private static final int MANUFACTURER_CODE_LENGTH = 8;
248
Derek Tan89e89d42014-07-08 17:00:10 -0700249 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700250 * A request object to use for transmitting data to an ICC.
251 */
252 private static final class IccAPDUArgument {
253 public int channel, cla, command, p1, p2, p3;
254 public String data;
255
256 public IccAPDUArgument(int channel, int cla, int command,
257 int p1, int p2, int p3, String data) {
258 this.channel = channel;
259 this.cla = cla;
260 this.command = command;
261 this.p1 = p1;
262 this.p2 = p2;
263 this.p3 = p3;
264 this.data = data;
265 }
266 }
267
268 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700269 * A request object to use for transmitting data to an ICC.
270 */
271 private static final class ManualNetworkSelectionArgument {
272 public OperatorInfo operatorInfo;
273 public boolean persistSelection;
274
275 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
276 this.operatorInfo = operatorInfo;
277 this.persistSelection = persistSelection;
278 }
279 }
280
281 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
283 * request after sending. The main thread will notify the request when it is complete.
284 */
285 private static final class MainThreadRequest {
286 /** The argument to use for the request */
287 public Object argument;
288 /** The result of the request that is run on the main thread */
289 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800290 // The subscriber id that this request applies to. Defaults to
291 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
292 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
vagdeviaf9a5b92018-08-15 16:01:53 -0700294 public WorkSource workSource;
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 public MainThreadRequest(Object argument) {
297 this.argument = argument;
298 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800299
vagdeviaf9a5b92018-08-15 16:01:53 -0700300 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800301 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800302 if (subId != null) {
303 this.subId = subId;
304 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700305 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 }
308
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800309 private static final class IncomingThirdPartyCallArgs {
310 public final ComponentName component;
311 public final String callId;
312 public final String callerDisplayName;
313
314 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
315 String callerDisplayName) {
316 this.component = component;
317 this.callId = callId;
318 this.callerDisplayName = callerDisplayName;
319 }
320 }
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /**
323 * A handler that processes messages on the main thread in the phone process. Since many
324 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
325 * inbound binder threads to the main thread in the phone process. The Binder thread
326 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
327 * on, which will be notified when the operation completes and will contain the result of the
328 * request.
329 *
330 * <p>If a MainThreadRequest object is provided in the msg.obj field,
331 * note that request.result must be set to something non-null for the calling thread to
332 * unblock.
333 */
334 private final class MainThreadHandler extends Handler {
335 @Override
336 public void handleMessage(Message msg) {
337 MainThreadRequest request;
338 Message onCompleted;
339 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800340 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700341 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
343 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 case CMD_HANDLE_USSD_REQUEST: {
345 request = (MainThreadRequest) msg.obj;
346 final Phone phone = getPhoneFromRequest(request);
347 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
348 String ussdRequest = ussdObject.first;
349 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700350
Pengquan Menga1bb6272018-09-06 09:59:22 -0700351 if (!isUssdApiAllowed(request.subId)) {
352 // Carrier does not support use of this API, return failure.
353 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
354 UssdResponse response = new UssdResponse(ussdRequest, null);
355 Bundle returnData = new Bundle();
356 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
357 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700358
Pengquan Menga1bb6272018-09-06 09:59:22 -0700359 request.result = true;
360 notifyRequester(request);
361 return;
362 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700363
Pengquan Menga1bb6272018-09-06 09:59:22 -0700364 try {
365 request.result = phone != null
366 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
367 } catch (CallStateException cse) {
368 request.result = false;
369 }
370 // Wake up the requesting thread
371 notifyRequester(request);
372 break;
pkanwar32d516d2016-10-14 19:37:38 -0700373 }
374
Yorke Lee716f67e2015-06-17 15:39:16 -0700375 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700377 final Phone phone = getPhoneFromRequest(request);
378 request.result = phone != null ?
379 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
380 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700388 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800389 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700390 if (uiccCard == null) {
391 loge("iccTransmitApduLogicalChannel: No UICC");
392 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700393 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700394 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
396 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700397 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 iccArgument.channel, iccArgument.cla, iccArgument.command,
399 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700401 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 break;
403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 ar = (AsyncResult) msg.obj;
406 request = (MainThreadRequest) ar.userObj;
407 if (ar.exception == null && ar.result != null) {
408 request.result = ar.result;
409 } else {
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
411 if (ar.result == null) {
412 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800413 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800415 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 } else {
417 loge("iccTransmitApduLogicalChannel: Unknown exception");
418 }
419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
424 request = (MainThreadRequest) msg.obj;
425 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 if (uiccCard == null) {
428 loge("iccTransmitApduBasicChannel: No UICC");
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 } else {
432 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
433 request);
434 uiccCard.iccTransmitApduBasicChannel(
435 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
436 iccArgument.p3, iccArgument.data, onCompleted);
437 }
438 break;
439
440 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
441 ar = (AsyncResult) msg.obj;
442 request = (MainThreadRequest) ar.userObj;
443 if (ar.exception == null && ar.result != null) {
444 request.result = ar.result;
445 } else {
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 if (ar.result == null) {
448 loge("iccTransmitApduBasicChannel: Empty response");
449 } else if (ar.exception instanceof CommandException) {
450 loge("iccTransmitApduBasicChannel: CommandException: " +
451 ar.exception);
452 } else {
453 loge("iccTransmitApduBasicChannel: Unknown exception");
454 }
455 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 break;
458
459 case CMD_EXCHANGE_SIM_IO:
460 request = (MainThreadRequest) msg.obj;
461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 if (uiccCard == null) {
464 loge("iccExchangeSimIO: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 } else {
468 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
469 request);
470 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
471 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
472 iccArgument.data, onCompleted);
473 }
474 break;
475
476 case EVENT_EXCHANGE_SIM_IO_DONE:
477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6f, 0, (byte[])null);
483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
Derek Tan4d5e5c12014-02-04 11:54:58 -0800487 case CMD_SEND_ENVELOPE:
488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("sendEnvelopeWithStatus: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
496 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
497 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800498 break;
499
500 case EVENT_SEND_ENVELOPE_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("sendEnvelopeWithStatus: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("sendEnvelopeWithStatus: CommandException: " +
511 ar.exception);
512 } else {
513 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
514 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 break;
518
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 case CMD_OPEN_CHANNEL:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800522 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 if (uiccCard == null) {
524 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800525 request.result = new IccOpenLogicalChannelResponse(-1,
526 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800530 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
531 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 break;
534
535 case EVENT_OPEN_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 int[] result = (int[]) ar.result;
541 int channelId = result[0];
542 byte[] selectResponse = null;
543 if (result.length > 1) {
544 selectResponse = new byte[result.length - 1];
545 for (int i = 1; i < result.length; ++i) {
546 selectResponse[i - 1] = (byte) result[i];
547 }
548 }
549 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700550 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 if (ar.result == null) {
553 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (ar.exception != null) {
556 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
557 }
558
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700559 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700560 if (ar.exception instanceof CommandException) {
561 CommandException.Error error =
562 ((CommandException) (ar.exception)).getCommandError();
563 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700564 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700565 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700566 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 }
568 }
569 openChannelResp = new IccOpenLogicalChannelResponse(
570 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700572 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
576 case CMD_CLOSE_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900581 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
585 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800590 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
591 break;
592
593 case CMD_NV_READ_ITEM:
594 request = (MainThreadRequest) msg.obj;
595 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700596 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800597 break;
598
599 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800605 request.result = "";
606 if (ar.result == null) {
607 loge("nvReadItem: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("nvReadItem: CommandException: " +
610 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800612 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
Jake Hambye994d462014-02-03 13:10:13 -0800618 case CMD_NV_WRITE_ITEM:
619 request = (MainThreadRequest) msg.obj;
620 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
621 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700622 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
623 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800624 break;
625
626 case EVENT_NV_WRITE_ITEM_DONE:
627 handleNullReturnEvent(msg, "nvWriteItem");
628 break;
629
630 case CMD_NV_WRITE_CDMA_PRL:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
633 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_WRITE_CDMA_PRL_DONE:
637 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
638 break;
639
640 case CMD_NV_RESET_CONFIG:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
643 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
644 break;
645
646 case EVENT_NV_RESET_CONFIG_DONE:
647 handleNullReturnEvent(msg, "nvResetConfig");
648 break;
649
Jake Hamby7c27be32014-03-03 13:25:59 -0800650 case CMD_GET_PREFERRED_NETWORK_TYPE:
651 request = (MainThreadRequest) msg.obj;
652 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700653 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800654 break;
655
656 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // Integer
661 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800662 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800663 if (ar.result == null) {
664 loge("getPreferredNetworkType: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("getPreferredNetworkType: CommandException: " +
667 ar.exception);
668 } else {
669 loge("getPreferredNetworkType: Unknown exception");
670 }
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 break;
674
675 case CMD_SET_PREFERRED_NETWORK_TYPE:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
678 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700679 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800680 break;
681
682 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
683 handleNullReturnEvent(msg, "setPreferredNetworkType");
684 break;
685
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000686 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
687 request = (MainThreadRequest)msg.obj;
688 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700689 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000690 break;
691
692 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
693 ar = (AsyncResult)msg.obj;
694 request = (MainThreadRequest)ar.userObj;
695 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000697 break;
698
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800699 case CMD_SET_VOICEMAIL_NUMBER:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
702 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800703 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
704 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800705 break;
706
707 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
708 handleNullReturnEvent(msg, "setVoicemailNumber");
709 break;
710
Stuart Scott54788802015-03-30 13:18:01 -0700711 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
714 request);
715 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
716 break;
717
718 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
719 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
720 break;
721
Shishir Agrawal302c8692015-06-19 13:49:39 -0700722 case CMD_PERFORM_NETWORK_SCAN:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
725 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
726 break;
727
728 case EVENT_PERFORM_NETWORK_SCAN_DONE:
729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
731 CellNetworkScanResult cellScanResult;
732 if (ar.exception == null && ar.result != null) {
733 cellScanResult = new CellNetworkScanResult(
734 CellNetworkScanResult.STATUS_SUCCESS,
735 (List<OperatorInfo>) ar.result);
736 } else {
737 if (ar.result == null) {
738 loge("getCellNetworkScanResults: Empty response");
739 }
740 if (ar.exception != null) {
741 loge("getCellNetworkScanResults: Exception: " + ar.exception);
742 }
743 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
744 if (ar.exception instanceof CommandException) {
745 CommandException.Error error =
746 ((CommandException) (ar.exception)).getCommandError();
747 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
748 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
749 } else if (error == CommandException.Error.GENERIC_FAILURE) {
750 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
751 }
752 }
753 cellScanResult = new CellNetworkScanResult(errorCode, null);
754 }
755 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700757 break;
758
759 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
760 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700761 ManualNetworkSelectionArgument selArg =
762 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
764 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700765 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
766 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700767 break;
768
769 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
770 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
771 break;
772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700773 case CMD_GET_MODEM_ACTIVITY_INFO:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700776 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700777 break;
778
779 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
780 ar = (AsyncResult) msg.obj;
781 request = (MainThreadRequest) ar.userObj;
782 if (ar.exception == null && ar.result != null) {
783 request.result = ar.result;
784 } else {
785 if (ar.result == null) {
786 loge("queryModemActivityInfo: Empty response");
787 } else if (ar.exception instanceof CommandException) {
788 loge("queryModemActivityInfo: CommandException: " +
789 ar.exception);
790 } else {
791 loge("queryModemActivityInfo: Unknown exception");
792 }
793 }
Amit Mahajand4766222016-01-28 15:28:28 -0800794 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
795 if (request.result == null) {
796 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700799 break;
800
Meng Wang1a7c35a2016-05-05 20:56:15 -0700801 case CMD_SET_ALLOWED_CARRIERS:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
804 mPhone.setAllowedCarriers(
805 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700806 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700807 break;
808
809 case EVENT_SET_ALLOWED_CARRIERS_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 if (ar.result == null) {
816 loge("setAllowedCarriers: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("setAllowedCarriers: CommandException: " +
819 ar.exception);
820 } else {
821 loge("setAllowedCarriers: Unknown exception");
822 }
823 }
824 // Result cannot be null. Return -1 on error.
825 if (request.result == null) {
826 request.result = new int[]{-1};
827 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700828 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700829 break;
830
831 case CMD_GET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700834 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 break;
836
837 case EVENT_GET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("getAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("getAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("getAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return empty list of CarrierIdentifier.
853 if (request.result == null) {
854 request.result = new ArrayList<CarrierIdentifier>(0);
855 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 break;
858
Nathan Haroldb3014052017-01-25 15:57:32 -0800859 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
860 ar = (AsyncResult) msg.obj;
861 request = (MainThreadRequest) ar.userObj;
862 if (ar.exception == null && ar.result != null) {
863 request.result = ar.result;
864 } else {
865 request.result = new IllegalArgumentException(
866 "Failed to retrieve Forbidden Plmns");
867 if (ar.result == null) {
868 loge("getForbiddenPlmns: Empty response");
869 } else {
870 loge("getForbiddenPlmns: Unknown exception");
871 }
872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800874 break;
875
876 case CMD_GET_FORBIDDEN_PLMNS:
877 request = (MainThreadRequest) msg.obj;
878 uiccCard = getUiccCardFromRequest(request);
879 if (uiccCard == null) {
880 loge("getForbiddenPlmns() UiccCard is null");
881 request.result = new IllegalArgumentException(
882 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800884 break;
885 }
886 Integer appType = (Integer) request.argument;
887 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
888 if (uiccApp == null) {
889 loge("getForbiddenPlmns() no app with specified type -- "
890 + appType);
891 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 break;
894 } else {
895 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
896 + " specified type -- " + appType);
897 }
898 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
899 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
900 onCompleted);
901 break;
902
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000903 case CMD_SWITCH_SLOTS:
904 request = (MainThreadRequest) msg.obj;
905 int[] physicalSlots = (int[]) request.argument;
906 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
907 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
908 break;
909
910 case EVENT_SWITCH_SLOTS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
915 break;
916 case CMD_GET_NETWORK_SELECTION_MODE:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
919 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
920 break;
921
922 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception != null) {
926 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
927 } else {
928 int mode = ((int[]) ar.result)[0];
929 if (mode == 0) {
930 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
931 } else {
932 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
933 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
936 break;
937 case CMD_GET_CDMA_ROAMING_MODE:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
940 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
941 break;
942 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception != null) {
946 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
947 } else {
948 request.result = ((int[]) ar.result)[0];
949 }
950 notifyRequester(request);
951 break;
952 case CMD_SET_CDMA_ROAMING_MODE:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
955 int mode = (int) request.argument;
956 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
957 break;
958 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 request.result = ar.exception == null;
962 notifyRequester(request);
963 break;
964 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
967 int subscriptionMode = (int) request.argument;
968 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
969 break;
970 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = ar.exception == null;
974 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 break;
976
Nathan Harold3ff88932018-08-14 10:19:49 -0700977 case CMD_GET_ALL_CELL_INFO:
978 request = (MainThreadRequest) msg.obj;
979 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
980 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
981 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
982 break;
983
984 case EVENT_GET_ALL_CELL_INFO_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
988 synchronized (request) {
989 request.notifyAll();
990 }
991 break;
992
993 case CMD_GET_CELL_LOCATION: {
994 request = (MainThreadRequest) msg.obj;
995 WorkSource ws = (WorkSource) request.argument;
996 Phone phone = getPhoneFromRequest(request);
997 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
998 break;
999 }
1000
1001 case EVENT_GET_CELL_LOCATION_DONE: {
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception == null) {
1005 request.result = ar.result;
1006 } else {
1007 Phone phone = getPhoneFromRequest(request);
1008 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1009 ? new CdmaCellLocation() : new GsmCellLocation();
1010 }
1011
1012 synchronized (request) {
1013 request.notifyAll();
1014 }
1015 break;
1016 }
1017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001018 default:
1019 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1020 break;
1021 }
1022 }
Jake Hambye994d462014-02-03 13:10:13 -08001023
Pengquan Menga1bb6272018-09-06 09:59:22 -07001024 private void notifyRequester(MainThreadRequest request) {
1025 synchronized (request) {
1026 request.notifyAll();
1027 }
1028 }
1029
Jake Hambye994d462014-02-03 13:10:13 -08001030 private void handleNullReturnEvent(Message msg, String command) {
1031 AsyncResult ar = (AsyncResult) msg.obj;
1032 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1033 if (ar.exception == null) {
1034 request.result = true;
1035 } else {
1036 request.result = false;
1037 if (ar.exception instanceof CommandException) {
1038 loge(command + ": CommandException: " + ar.exception);
1039 } else {
1040 loge(command + ": Unknown exception");
1041 }
1042 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 }
1046
1047 /**
1048 * Posts the specified command to be executed on the main thread,
1049 * waits for the request to complete, and returns the result.
1050 * @see #sendRequestAsync
1051 */
1052 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001053 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1054 }
1055
1056 /**
1057 * Posts the specified command to be executed on the main thread,
1058 * waits for the request to complete, and returns the result.
1059 * @see #sendRequestAsync
1060 */
1061 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1063 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001064 }
1065
1066 /**
1067 * Posts the specified command to be executed on the main thread,
1068 * waits for the request to complete, and returns the result.
1069 * @see #sendRequestAsync
1070 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001072 return sendRequest(command, argument, subId, null);
1073 }
1074
1075 /**
1076 * Posts the specified command to be executed on the main thread,
1077 * waits for the request to complete, and returns the result.
1078 * @see #sendRequestAsync
1079 */
1080 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1082 throw new RuntimeException("This method will deadlock if called from the main thread.");
1083 }
1084
vagdeviaf9a5b92018-08-15 16:01:53 -07001085 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 Message msg = mMainThreadHandler.obtainMessage(command, request);
1087 msg.sendToTarget();
1088
1089 // Wait for the request to complete
1090 synchronized (request) {
1091 while (request.result == null) {
1092 try {
1093 request.wait();
1094 } catch (InterruptedException e) {
1095 // Do nothing, go back and wait until the request is complete
1096 }
1097 }
1098 }
1099 return request.result;
1100 }
1101
1102 /**
1103 * Asynchronous ("fire and forget") version of sendRequest():
1104 * Posts the specified command to be executed on the main thread, and
1105 * returns immediately.
1106 * @see #sendRequest
1107 */
1108 private void sendRequestAsync(int command) {
1109 mMainThreadHandler.sendEmptyMessage(command);
1110 }
1111
1112 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001113 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1114 * @see {@link #sendRequest(int,Object)}
1115 */
1116 private void sendRequestAsync(int command, Object argument) {
1117 MainThreadRequest request = new MainThreadRequest(argument);
1118 Message msg = mMainThreadHandler.obtainMessage(command, request);
1119 msg.sendToTarget();
1120 }
1121
1122 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 * Initialize the singleton PhoneInterfaceManager instance.
1124 * This is only done once, at startup, from PhoneApp.onCreate().
1125 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001126 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 synchronized (PhoneInterfaceManager.class) {
1128 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001129 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 } else {
1131 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1132 }
1133 return sInstance;
1134 }
1135 }
1136
1137 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001138 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 mApp = app;
1140 mPhone = phone;
1141 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001142 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1144 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001145 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001146 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001147 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001148 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001149 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001150
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001151 publish();
1152 }
1153
1154 private void publish() {
1155 if (DBG) log("publish: " + this);
1156
1157 ServiceManager.addService("phone", this);
1158 }
1159
Stuart Scott584921c2015-01-15 17:10:34 -08001160 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001161 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1162 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001163 }
1164
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001165 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1166 Phone phone = getPhoneFromRequest(request);
1167 return phone == null ? null :
1168 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1169 }
1170
Wink Saville36469e72014-06-11 15:17:00 -07001171 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001172 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001173 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 //
1176 // Implementation of the ITelephony interface.
1177 //
1178
1179 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001180 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
Wink Savilleb564aae2014-10-23 10:18:09 -07001183 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 if (DBG) log("dial: " + number);
1185 // No permission check needed here: This is just a wrapper around the
1186 // ACTION_DIAL intent, which is available to any app since it puts up
1187 // the UI before it does anything.
1188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001189 final long identity = Binder.clearCallingIdentity();
1190 try {
1191 String url = createTelUrl(number);
1192 if (url == null) {
1193 return;
1194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001196 // PENDING: should we just silently fail if phone is offhook or ringing?
1197 PhoneConstants.State state = mCM.getState(subId);
1198 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1199 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1200 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1201 mApp.startActivity(intent);
1202 }
1203 } finally {
1204 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 }
1206 }
1207
1208 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001209 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001210 }
1211
Wink Savilleb564aae2014-10-23 10:18:09 -07001212 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 if (DBG) log("call: " + number);
1214
1215 // This is just a wrapper around the ACTION_CALL intent, but we still
1216 // need to do a permission check since we're calling startActivity()
1217 // from the context of the phone app.
1218 enforceCallPermission();
1219
1220 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1221 != AppOpsManager.MODE_ALLOWED) {
1222 return;
1223 }
1224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001225 final long identity = Binder.clearCallingIdentity();
1226 try {
1227 String url = createTelUrl(number);
1228 if (url == null) {
1229 return;
1230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001232 boolean isValid = false;
1233 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1234 if (slist != null) {
1235 for (SubscriptionInfo subInfoRecord : slist) {
1236 if (subInfoRecord.getSubscriptionId() == subId) {
1237 isValid = true;
1238 break;
1239 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001240 }
Wink Saville08874612014-08-31 19:19:58 -07001241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001242 if (!isValid) {
1243 return;
1244 }
Wink Saville08874612014-08-31 19:19:58 -07001245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001246 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1247 intent.putExtra(SUBSCRIPTION_KEY, subId);
1248 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1249 mApp.startActivity(intent);
1250 } finally {
1251 Binder.restoreCallingIdentity(identity);
1252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 }
1254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 /**
1256 * End a call based on call state
1257 * @return true is a call was ended
1258 */
1259 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001260 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
1263 /**
1264 * End a call based on the call state of the subId
1265 * @return true is a call was ended
1266 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001267 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001268 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 }
1270
1271 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001272 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001273 }
1274
Wink Savilleb564aae2014-10-23 10:18:09 -07001275 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001276 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001280 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001282 public void silenceRinger() {
1283 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 }
1285
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001286 @Override
1287 public boolean isOffhook(String callingPackage) {
1288 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001294 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001295 return false;
1296 }
1297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001298 final long identity = Binder.clearCallingIdentity();
1299 try {
1300 final Phone phone = getPhone(subId);
1301 if (phone != null) {
1302 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1303 } else {
1304 return false;
1305 }
1306 } finally {
1307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001311 @Override
1312 public boolean isRinging(String callingPackage) {
1313 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001319 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 return false;
1321 }
1322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001323 final long identity = Binder.clearCallingIdentity();
1324 try {
1325 final Phone phone = getPhone(subId);
1326 if (phone != null) {
1327 return (phone.getState() == PhoneConstants.State.RINGING);
1328 } else {
1329 return false;
1330 }
1331 } finally {
1332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001336 @Override
1337 public boolean isIdle(String callingPackage) {
1338 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001341 @Override
1342 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001344 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001345 return false;
1346 }
1347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001348 final long identity = Binder.clearCallingIdentity();
1349 try {
1350 final Phone phone = getPhone(subId);
1351 if (phone != null) {
1352 return (phone.getState() == PhoneConstants.State.IDLE);
1353 } else {
1354 return false;
1355 }
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001366 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001367 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1368 }
1369
1370 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001376 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1377 }
1378
1379 /** {@hide} */
1380 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001381 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001382 }
1383
Wink Savilleb564aae2014-10-23 10:18:09 -07001384 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001386
1387 final long identity = Binder.clearCallingIdentity();
1388 try {
1389 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1390 checkSimPin.start();
1391 return checkSimPin.unlockSim(null, pin);
1392 } finally {
1393 Binder.restoreCallingIdentity(identity);
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396
Wink Saville9de0f752013-10-22 19:04:03 -07001397 /** {@hide} */
1398 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001404
1405 final long identity = Binder.clearCallingIdentity();
1406 try {
1407 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1408 checkSimPuk.start();
1409 return checkSimPuk.unlockSim(puk, pin);
1410 } finally {
1411 Binder.restoreCallingIdentity(identity);
1412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 }
1414
1415 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001416 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 * a synchronous one.
1418 */
1419 private static class UnlockSim extends Thread {
1420
1421 private final IccCard mSimCard;
1422
1423 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001424 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1425 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
1427 // For replies from SimCard interface
1428 private Handler mHandler;
1429
1430 // For async handler to identify request type
1431 private static final int SUPPLY_PIN_COMPLETE = 100;
1432
1433 public UnlockSim(IccCard simCard) {
1434 mSimCard = simCard;
1435 }
1436
1437 @Override
1438 public void run() {
1439 Looper.prepare();
1440 synchronized (UnlockSim.this) {
1441 mHandler = new Handler() {
1442 @Override
1443 public void handleMessage(Message msg) {
1444 AsyncResult ar = (AsyncResult) msg.obj;
1445 switch (msg.what) {
1446 case SUPPLY_PIN_COMPLETE:
1447 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1448 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001449 mRetryCount = msg.arg1;
1450 if (ar.exception != null) {
1451 if (ar.exception instanceof CommandException &&
1452 ((CommandException)(ar.exception)).getCommandError()
1453 == CommandException.Error.PASSWORD_INCORRECT) {
1454 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1455 } else {
1456 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1457 }
1458 } else {
1459 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 mDone = true;
1462 UnlockSim.this.notifyAll();
1463 }
1464 break;
1465 }
1466 }
1467 };
1468 UnlockSim.this.notifyAll();
1469 }
1470 Looper.loop();
1471 }
1472
1473 /*
1474 * Use PIN or PUK to unlock SIM card
1475 *
1476 * If PUK is null, unlock SIM card with PIN
1477 *
1478 * If PUK is not null, unlock SIM card with PUK and set PIN code
1479 */
Wink Saville9de0f752013-10-22 19:04:03 -07001480 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481
1482 while (mHandler == null) {
1483 try {
1484 wait();
1485 } catch (InterruptedException e) {
1486 Thread.currentThread().interrupt();
1487 }
1488 }
1489 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1490
1491 if (puk == null) {
1492 mSimCard.supplyPin(pin, callback);
1493 } else {
1494 mSimCard.supplyPuk(puk, pin, callback);
1495 }
1496
1497 while (!mDone) {
1498 try {
1499 Log.d(LOG_TAG, "wait for done");
1500 wait();
1501 } catch (InterruptedException e) {
1502 // Restore the interrupted status
1503 Thread.currentThread().interrupt();
1504 }
1505 }
1506 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001507 int[] resultArray = new int[2];
1508 resultArray[0] = mResult;
1509 resultArray[1] = mRetryCount;
1510 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 }
1513
1514 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001516
1517 }
1518
Wink Savilleb564aae2014-10-23 10:18:09 -07001519 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 // No permission check needed here: this call is harmless, and it's
1521 // needed for the ServiceState.requestStateUpdate() call (which is
1522 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523 final long identity = Binder.clearCallingIdentity();
1524 try {
1525 final Phone phone = getPhone(subId);
1526 if (phone != null) {
1527 phone.updateServiceLocation();
1528 }
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001534 @Override
1535 public boolean isRadioOn(String callingPackage) {
1536 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001539 @Override
1540 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001542 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 return false;
1544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 return isRadioOnForSubscriber(subId);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001552 }
1553
1554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1560 } else {
1561 return false;
1562 }
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
1579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1580 }
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 }
Wink Saville36469e72014-06-11 15:17:00 -07001584 }
1585
1586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
Wink Savilleb564aae2014-10-23 10:18:09 -07001590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001592
1593 final long identity = Binder.clearCallingIdentity();
1594 try {
1595 final Phone phone = getPhone(subId);
1596 if (phone == null) {
1597 return false;
1598 }
1599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1600 toggleRadioOnOffForSubscriber(subId);
1601 }
1602 return true;
1603 } finally {
1604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001608 public boolean needMobileRadioShutdown() {
1609 /*
1610 * If any of the Radios are available, it will need to be
1611 * shutdown. So return true if any Radio is available.
1612 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1616 Phone phone = PhoneFactory.getPhone(i);
1617 if (phone != null && phone.isRadioAvailable()) return true;
1618 }
1619 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1620 return false;
1621 } finally {
1622 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 }
1625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001626 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001628 enforceModifyPermission();
1629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1633 logv("Shutting down Phone " + i);
1634 shutdownRadioUsingPhoneId(i);
1635 }
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001638 }
1639 }
1640
1641 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 Phone phone = PhoneFactory.getPhone(phoneId);
1643 if (phone != null && phone.isRadioAvailable()) {
1644 phone.shutdownRadio();
1645 }
1646 }
1647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001650
1651 final long identity = Binder.clearCallingIdentity();
1652 try {
1653 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1654 if (defaultPhone != null) {
1655 defaultPhone.setRadioPower(turnOn);
1656 return true;
1657 } else {
1658 loge("There's no default phone.");
1659 return false;
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001663 }
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Wink Savilleb564aae2014-10-23 10:18:09 -07001666 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001668
1669 final long identity = Binder.clearCallingIdentity();
1670 try {
1671 final Phone phone = getPhone(subId);
1672 if (phone != null) {
1673 phone.setRadioPower(turnOn);
1674 return true;
1675 } else {
1676 return false;
1677 }
1678 } finally {
1679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Wink Saville36469e72014-06-11 15:17:00 -07001683 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public boolean enableDataConnectivity() {
1686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001687
1688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 int subId = mSubscriptionController.getDefaultDataSubId();
1691 final Phone phone = getPhone(subId);
1692 if (phone != null) {
1693 phone.setUserDataEnabled(true);
1694 return true;
1695 } else {
1696 return false;
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public boolean disableDataConnectivity() {
1706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001707
1708 final long identity = Binder.clearCallingIdentity();
1709 try {
1710 int subId = mSubscriptionController.getDefaultDataSubId();
1711 final Phone phone = getPhone(subId);
1712 if (phone != null) {
1713 phone.setUserDataEnabled(false);
1714 return true;
1715 } else {
1716 return false;
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
1722
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001724 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
1729 return phone.isDataAllowed();
1730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
1738 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001740 }
1741
pkanwarae03a6b2016-11-06 20:37:09 -08001742 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001743 enforceCallPermission();
1744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1748 return;
1749 }
1750 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1751 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
1754 }
pkanwar32d516d2016-10-14 19:37:38 -07001755 };
1756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1763 return false;
1764 }
1765 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 Phone phone = PhoneFactory.getPhone(slotIndex);
1779 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1780 PhoneConstantConversions.convertCallState(phone.getState());
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1791 if (phone != null) {
1792 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1793 } else {
1794 return PhoneConstantConversions.convertDataState(
1795 PhoneConstants.DataState.DISCONNECTED);
1796 }
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 }
1801
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1807 if (phone != null) {
1808 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1809 } else {
1810 return TelephonyManager.DATA_ACTIVITY_NONE;
1811 }
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
1817 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001818 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001819 mPhone.getContext().getSystemService(AppOpsManager.class)
1820 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001821 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001822 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001823 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 if (DBG_LOC) log("getCellLocation: is active user");
1830 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1833 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834 return data;
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
1837 }
Svetoslav64fad262015-04-14 14:35:21 -07001838 }
1839
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001841 public String getNetworkCountryIsoForPhone(int phoneId) {
1842 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1843 // registered cell info, so return a NULL country instead.
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001846 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1847 // Get default phone in this case.
1848 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1849 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001850 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001851 // Todo: fix this when we can get the actual cellular network info when the device
1852 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001853 if (TelephonyManager.NETWORK_TYPE_IWLAN
1854 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1855 return "";
1856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001857 Phone phone = PhoneFactory.getPhone(phoneId);
1858 if (phone != null) {
1859 ServiceStateTracker sst = phone.getServiceStateTracker();
1860 if (sst != null) {
1861 LocaleTracker lt = sst.getLocaleTracker();
1862 if (lt != null) {
1863 return lt.getCurrentCountry();
1864 }
1865 }
1866 }
1867 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 }
1872
1873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001875 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001876 }
1877
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 mApp.enforceCallingOrSelfPermission(
1881 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 final Phone phone = getPhone(subId);
1886 if (phone != null) {
1887 phone.enableLocationUpdates();
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
1894 @Override
1895 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001896 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001897 }
1898
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001900 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 mApp.enforceCallingOrSelfPermission(
1902 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903
1904 final long identity = Binder.clearCallingIdentity();
1905 try {
1906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
1908 phone.disableLocationUpdates();
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 @Override
1916 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001917 public List<NeighboringCellInfo>
1918 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001919 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1920 throw new SecurityException(
1921 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1922 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001923
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1925 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1926 return null;
1927 }
Svetoslav64fad262015-04-14 14:35:21 -07001928
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001929 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930
Nathan Haroldf180aac2018-06-01 18:43:55 -07001931 List<CellInfo> info = getAllCellInfo(callingPackage);
1932 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933
Nathan Haroldf180aac2018-06-01 18:43:55 -07001934 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1935 for (CellInfo ci : info) {
1936 if (ci instanceof CellInfoGsm) {
1937 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1938 } else if (ci instanceof CellInfoWcdma) {
1939 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001942 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945
1946 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001947 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001948 mPhone.getContext().getSystemService(AppOpsManager.class)
1949 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001950 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001951 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001952 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001955 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001956 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001957 final long identity = Binder.clearCallingIdentity();
1958 try {
1959 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1960 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001961 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1962 CMD_GET_ALL_CELL_INFO,
1963 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001964 if (info != null) cellInfos.addAll(info);
1965 }
1966 return cellInfos;
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970 }
1971
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001972 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001974 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976
1977 final long identity = Binder.clearCallingIdentity();
1978 try {
1979 mPhone.setCellInfoListRate(rateInMillis, workSource);
1980 } finally {
1981 Binder.restoreCallingIdentity(identity);
1982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Shishir Agrawala9f32182016-04-12 12:00:16 -07001985 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001986 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001987 Phone phone = PhoneFactory.getPhone(slotIndex);
1988 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001989 return null;
1990 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001991 int subId = phone.getSubId();
1992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1993 mApp, subId, callingPackage, "getImeiForSlot")) {
1994 return null;
1995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996
1997 final long identity = Binder.clearCallingIdentity();
1998 try {
1999 return phone.getImei();
2000 } finally {
2001 Binder.restoreCallingIdentity(identity);
2002 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002003 }
2004
2005 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002006 public String getTypeAllocationCodeForSlot(int slotIndex) {
2007 Phone phone = PhoneFactory.getPhone(slotIndex);
2008 String tac = null;
2009 if (phone != null) {
2010 String imei = phone.getImei();
2011 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2012 }
2013 return tac;
2014 }
2015
2016 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002017 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002018 Phone phone = PhoneFactory.getPhone(slotIndex);
2019 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002020 return null;
2021 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002022 int subId = phone.getSubId();
2023 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2024 mApp, subId, callingPackage, "getMeidForSlot")) {
2025 return null;
2026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002027
2028 final long identity = Binder.clearCallingIdentity();
2029 try {
2030 return phone.getMeid();
2031 } finally {
2032 Binder.restoreCallingIdentity(identity);
2033 }
Jack Yu2af8d712017-03-15 17:14:14 -07002034 }
2035
2036 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002037 public String getManufacturerCodeForSlot(int slotIndex) {
2038 Phone phone = PhoneFactory.getPhone(slotIndex);
2039 String manufacturerCode = null;
2040 if (phone != null) {
2041 String meid = phone.getMeid();
2042 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2043 }
2044 return manufacturerCode;
2045 }
2046
2047 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002048 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002049 Phone phone = PhoneFactory.getPhone(slotIndex);
2050 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002051 return null;
2052 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002053 int subId = phone.getSubId();
2054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2055 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2056 return null;
2057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058
2059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 return phone.getDeviceSvn();
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
2064 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002065 }
2066
fionaxu43304da2017-11-27 22:51:16 -08002067 @Override
2068 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002069 final long identity = Binder.clearCallingIdentity();
2070 try {
2071 final Phone phone = getPhone(subId);
2072 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
2075 }
fionaxu43304da2017-11-27 22:51:16 -08002076 }
2077
2078 @Override
2079 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 final Phone phone = getPhone(subId);
2083 return phone == null ? null : phone.getCarrierName();
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
2086 }
fionaxu43304da2017-11-27 22:51:16 -08002087 }
2088
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 //
2090 // Internal helper methods.
2091 //
2092
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002093 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2095 *
2096 * @throws SecurityException if the caller does not have the required permission
2097 */
2098 private void enforceModifyPermission() {
2099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2100 }
2101
2102 /**
2103 * Make sure the caller has the CALL_PHONE permission.
2104 *
2105 * @throws SecurityException if the caller does not have the required permission
2106 */
2107 private void enforceCallPermission() {
2108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2109 }
2110
Stuart Scott8eef64f2015-04-08 15:13:54 -07002111 private void enforceConnectivityInternalPermission() {
2112 mApp.enforceCallingOrSelfPermission(
2113 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2114 "ConnectivityService");
2115 }
2116
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 private String createTelUrl(String number) {
2118 if (TextUtils.isEmpty(number)) {
2119 return null;
2120 }
2121
Jake Hambye994d462014-02-03 13:10:13 -08002122 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 }
2124
Ihab Awadf9e92732013-12-05 18:02:52 -08002125 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2127 }
2128
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002129 private static void logv(String msg) {
2130 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2131 }
2132
Ihab Awadf9e92732013-12-05 18:02:52 -08002133 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2135 }
2136
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002137 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002139 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002140 }
2141
Sanket Padawe356d7632015-06-22 14:03:32 -07002142 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002143 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002144 final long identity = Binder.clearCallingIdentity();
2145 try {
2146 final Phone phone = PhoneFactory.getPhone(slotIndex);
2147 if (phone == null) {
2148 return PhoneConstants.PHONE_TYPE_NONE;
2149 } else {
2150 return phone.getPhoneType();
2151 }
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 }
2156
2157 /**
2158 * Returns the CDMA ERI icon index to display
2159 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002160 @Override
2161 public int getCdmaEriIconIndex(String callingPackage) {
2162 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002168 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 return -1;
2170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 if (phone != null) {
2176 return phone.getCdmaEriIconIndex();
2177 } else {
2178 return -1;
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
2185 /**
2186 * Returns the CDMA ERI icon mode,
2187 * 0 - ON
2188 * 1 - FLASHING
2189 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002190 @Override
2191 public int getCdmaEriIconMode(String callingPackage) {
2192 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002193 }
2194
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002198 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 return -1;
2200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002201
2202 final long identity = Binder.clearCallingIdentity();
2203 try {
2204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 return phone.getCdmaEriIconMode();
2207 } else {
2208 return -1;
2209 }
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214
2215 /**
2216 * Returns the CDMA ERI text,
2217 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002218 @Override
2219 public String getCdmaEriText(String callingPackage) {
2220 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002221 }
2222
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002226 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 return null;
2228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229
2230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 final Phone phone = getPhone(subId);
2233 if (phone != null) {
2234 return phone.getCdmaEriText();
2235 } else {
2236 return null;
2237 }
2238 } finally {
2239 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
2243 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002244 * Returns the CDMA MDN.
2245 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002247 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2249 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250
2251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 final Phone phone = getPhone(subId);
2254 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2255 return phone.getLine1Number();
2256 } else {
2257 return null;
2258 }
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002261 }
2262 }
2263
2264 /**
2265 * Returns the CDMA MIN.
2266 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2270 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271
2272 final long identity = Binder.clearCallingIdentity();
2273 try {
2274 final Phone phone = getPhone(subId);
2275 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2276 return phone.getCdmaMin();
2277 } else {
2278 return null;
2279 }
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002282 }
2283 }
2284
2285 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 * Returns true if CDMA provisioning needs to run.
2287 */
2288 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 final long identity = Binder.clearCallingIdentity();
2290 try {
2291 return mPhone.needsOtaServiceProvisioning();
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002298 * Sets the voice mail number of a given subId.
2299 */
2300 @Override
2301 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303
2304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2307 new Pair<String, String>(alphaTag, number), new Integer(subId));
2308 return success;
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002312 }
2313
Ta-wei Yen87c49842016-05-13 21:19:52 -07002314 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002315 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2317 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2318 if (!TextUtils.equals(callingPackage, systemDialer)) {
2319 throw new SecurityException("caller must be system dialer");
2320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2325 if (phoneAccountHandle == null) {
2326 return null;
2327 }
2328 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002331 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002332 }
2333
2334 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002335 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002339 return null;
2340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return RemoteVvmTaskManager
2345 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002349 }
2350
2351 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002352 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2353 VisualVoicemailSmsFilterSettings settings) {
2354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2359 mPhone.getContext(), callingPackage, subId, settings);
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
2362 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002363 }
2364
2365 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002366 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2372 mPhone.getContext(), callingPackage, subId);
2373 } finally {
2374 Binder.restoreCallingIdentity(identity);
2375 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002376 }
2377
2378 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002379 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2380 String callingPackage, int subId) {
2381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382
2383 final long identity = Binder.clearCallingIdentity();
2384 try {
2385 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2386 mPhone.getContext(), callingPackage, subId);
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
2389 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002390 }
2391
2392 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002393 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002394 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395
2396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2399 mPhone.getContext(), subId);
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
2402 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002403 }
2404
2405 @Override
2406 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2407 String number, int port, String text, PendingIntent sentIntent) {
2408 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002409 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002410 enforceSendSmsPermission();
2411 // Make the calls as the phone process.
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2415 if (port == 0) {
2416 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2417 sentIntent, null, false);
2418 } else {
2419 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2420 smsManager.sendDataMessageWithSelfPermissions(number, null,
2421 (short) port, data, sentIntent, null);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002426 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002427 /**
fionaxu0152e512016-11-14 13:36:14 -08002428 * Sets the voice activation state of a given subId.
2429 */
2430 @Override
2431 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2433 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 final Phone phone = getPhone(subId);
2438 if (phone != null) {
2439 phone.setVoiceActivationState(activationState);
2440 } else {
2441 loge("setVoiceActivationState fails with invalid subId: " + subId);
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002445 }
2446 }
2447
2448 /**
2449 * Sets the data activation state of a given subId.
2450 */
2451 @Override
2452 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2454 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002455
2456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 final Phone phone = getPhone(subId);
2459 if (phone != null) {
2460 phone.setDataActivationState(activationState);
2461 } else {
2462 loge("setVoiceActivationState fails with invalid subId: " + subId);
2463 }
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002466 }
2467 }
2468
2469 /**
2470 * Returns the voice activation state of a given subId.
2471 */
2472 @Override
2473 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002474 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475
fionaxu0152e512016-11-14 13:36:14 -08002476 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 if (phone != null) {
2480 return phone.getVoiceActivationState();
2481 } else {
2482 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2483 }
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002486 }
2487 }
2488
2489 /**
2490 * Returns the data activation state of a given subId.
2491 */
2492 @Override
2493 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002494 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495
fionaxu0152e512016-11-14 13:36:14 -08002496 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 if (phone != null) {
2500 return phone.getDataActivationState();
2501 } else {
2502 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002506 }
2507 }
2508
2509 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 * Returns the unread count of voicemails
2511 */
2512 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002513 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002514 }
2515
2516 /**
2517 * Returns the unread count of voicemails for a subId
2518 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002520 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 final Phone phone = getPhone(subId);
2524 if (phone != null) {
2525 return phone.getVoiceMessageCount();
2526 } else {
2527 return 0;
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
2534 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002535 * returns true, if the device is in a state where both voice and data
2536 * are supported simultaneously. This can change based on location or network condition.
2537 */
2538 @Override
2539 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 final Phone phone = getPhone(subId);
2543 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002547 }
2548
2549 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002550 * Send the dialer code if called from the current default dialer or the caller has
2551 * carrier privilege.
2552 * @param inputCode The dialer code to send
2553 */
2554 @Override
2555 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2557 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2558 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002559 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2560 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562
2563 final long identity = Binder.clearCallingIdentity();
2564 try {
2565 mPhone.sendDialerSpecialCode(inputCode);
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
fionaxu235cc5e2017-03-06 22:25:57 -08002569 }
2570
2571 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002572 * Returns the data network type.
2573 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 *
2575 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2576 */
2577 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002578 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(getDefaultSubscription());
2582 if (phone != null) {
2583 return phone.getServiceState().getDataNetworkType();
2584 } else {
2585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002589 }
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Pengquan Menga1bb6272018-09-06 09:59:22 -07002592 @Override
2593 public int getNetworkSelectionMode(int subId) {
2594 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2595 }
2596
Wink Saville36469e72014-06-11 15:17:00 -07002597 /**
2598 * Returns the network type for a subId
2599 */
2600 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002601 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002604 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2605 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
2611 return phone.getServiceState().getDataNetworkType();
2612 } else {
2613 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 /**
2621 * Returns the data network type
2622 */
2623 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002624 public int getDataNetworkType(String callingPackage) {
2625 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002626 }
2627
2628 /**
2629 * Returns the data network type for a subId
2630 */
2631 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002632 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002634 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002635 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2636 }
2637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
2642 return phone.getServiceState().getDataNetworkType();
2643 } else {
2644 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
2651 /**
Wink Saville36469e72014-06-11 15:17:00 -07002652 * Returns the Voice network type for a subId
2653 */
2654 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002655 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002657 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002658 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2659 }
2660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(subId);
2664 if (phone != null) {
2665 return phone.getServiceState().getVoiceNetworkType();
2666 } else {
2667 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
2674 /**
2675 * @return true if a ICC card is present
2676 */
2677 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002678 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002679 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2680 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002681 }
2682
2683 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002684 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002685 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002686 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002687 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 final Phone phone = PhoneFactory.getPhone(slotIndex);
2691 if (phone != null) {
2692 return phone.getIccCard().hasIccCard();
2693 } else {
2694 return false;
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
2701 /**
2702 * Return if the current radio is LTE on CDMA. This
2703 * is a tri-state return value as for a period of time
2704 * the mode may be unknown.
2705 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002706 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002708 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 @Override
2711 public int getLteOnCdmaMode(String callingPackage) {
2712 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002713 }
2714
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002716 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002718 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002719 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2720 }
2721
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 final Phone phone = getPhone(subId);
2725 if (phone == null) {
2726 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2727 } else {
2728 return phone.getLteOnCdmaMode();
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 }
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
2735 public void setPhone(Phone phone) {
2736 mPhone = phone;
2737 }
2738
2739 /**
2740 * {@hide}
2741 * Returns Default subId, 0 in the case of single standby.
2742 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002743 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002744 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
Shishir Agrawala9f32182016-04-12 12:00:16 -07002747 private int getSlotForDefaultSubscription() {
2748 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2749 }
2750
Wink Savilleb564aae2014-10-23 10:18:09 -07002751 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002752 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002754
2755 /**
2756 * @see android.telephony.TelephonyManager.WifiCallingChoices
2757 */
2758 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2762 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2763 getWhenToMakeWifiCallsDefaultPreference());
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002767 }
2768
2769 /**
2770 * @see android.telephony.TelephonyManager.WifiCallingChoices
2771 */
2772 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2776 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2777 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002781 }
2782
Sailesh Nepald1e68152013-12-12 19:08:02 -08002783 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002784 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002785 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002786 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002787
Shishir Agrawal566b7612013-10-28 14:41:00 -07002788 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002789 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2790 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2792 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 if (TextUtils.equals(ISDR_AID, aid)) {
2798 // Only allows LPA to open logical channel to ISD-R.
2799 ComponentInfo bestComponent =
2800 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2801 if (bestComponent == null
2802 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2803 loge("The calling package is not allowed to access ISD-R.");
2804 throw new SecurityException(
2805 "The calling package is not allowed to access ISD-R.");
2806 }
Derek Tan740e1672017-06-27 14:56:27 -07002807 }
Derek Tan740e1672017-06-27 14:56:27 -07002808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 if (DBG) {
2810 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2811 }
2812 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2813 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2814 if (DBG) log("iccOpenLogicalChannel: " + response);
2815 return response;
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002819 }
2820
2821 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002822 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2824 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
2828 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2829 if (channel < 0) {
2830 return false;
2831 }
2832 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2833 if (DBG) log("iccCloseLogicalChannel: " + success);
2834 return success;
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838 }
2839
2840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002841 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002842 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2844 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 if (DBG) {
2849 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2850 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2851 + p3 + " data=" + data);
2852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 if (channel < 0) {
2855 return "";
2856 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2859 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2860 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 // Append the returned status code to the end of the response payload.
2863 String s = Integer.toHexString(
2864 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2865 if (response.payload != null) {
2866 s = IccUtils.bytesToHexString(response.payload) + s;
2867 }
2868 return s;
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002871 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002872 }
Jake Hambye994d462014-02-03 13:10:13 -08002873
Evan Charltonc66da362014-05-16 14:06:40 -07002874 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002875 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2876 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2878 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2884 && TextUtils.equals(ISDR_AID, data)) {
2885 // Only allows LPA to select ISD-R.
2886 ComponentInfo bestComponent =
2887 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2888 if (bestComponent == null
2889 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2890 loge("The calling package is not allowed to select ISD-R.");
2891 throw new SecurityException(
2892 "The calling package is not allowed to select ISD-R.");
2893 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002894 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896 if (DBG) {
2897 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2898 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2899 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2902 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2903 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 // Append the returned status code to the end of the response payload.
2906 String s = Integer.toHexString(
2907 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2908 if (response.payload != null) {
2909 s = IccUtils.bytesToHexString(response.payload) + s;
2910 }
2911 return s;
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002914 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002915 }
2916
2917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002918 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002919 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2921 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 if (DBG) {
2926 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2927 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2928 }
2929
2930 IccIoResult response =
2931 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2932 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2933 subId);
2934
2935 if (DBG) {
2936 log("Exchange SIM_IO [R]" + response);
2937 }
2938
2939 byte[] result = null;
2940 int length = 2;
2941 if (response.payload != null) {
2942 length = 2 + response.payload.length;
2943 result = new byte[length];
2944 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2945 } else {
2946 result = new byte[length];
2947 }
2948
2949 result[length - 1] = (byte) response.sw2;
2950 result[length - 2] = (byte) response.sw1;
2951 return result;
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002954 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002955 }
2956
Nathan Haroldb3014052017-01-25 15:57:32 -08002957 /**
2958 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2959 * on a particular subscription
2960 */
sqianb6e41952018-03-12 14:54:01 -07002961 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2963 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2964 return null;
2965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 if (appType != TelephonyManager.APPTYPE_USIM
2970 && appType != TelephonyManager.APPTYPE_SIM) {
2971 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2972 return null;
2973 }
2974 Object response = sendRequest(
2975 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2976 if (response instanceof String[]) {
2977 return (String[]) response;
2978 }
2979 // Response is an Exception of some kind,
2980 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002981 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 } finally {
2983 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002984 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002985 }
2986
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002988 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2990 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2995 if (response.payload == null) {
2996 return "";
2997 }
Evan Charltonc66da362014-05-16 14:06:40 -07002998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 // Append the returned status code to the end of the response payload.
3000 String s = Integer.toHexString(
3001 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3002 s = IccUtils.bytesToHexString(response.payload) + s;
3003 return s;
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Evan Charltonc66da362014-05-16 14:06:40 -07003007 }
3008
Jake Hambye994d462014-02-03 13:10:13 -08003009 /**
3010 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3011 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3012 *
3013 * @param itemID the ID of the item to read
3014 * @return the NV item as a String, or null on error.
3015 */
3016 @Override
3017 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3020 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003025 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3027 return value;
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Jake Hambye994d462014-02-03 13:10:13 -08003031 }
3032
3033 /**
3034 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3035 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3036 *
3037 * @param itemID the ID of the item to read
3038 * @param itemValue the value to write, as a String
3039 * @return true on success; false on any failure
3040 */
3041 @Override
3042 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003043 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3045 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3050 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003051 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3053 return success;
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Jake Hambye994d462014-02-03 13:10:13 -08003057 }
3058
3059 /**
3060 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3061 * Used for device configuration by some CDMA operators.
3062 *
3063 * @param preferredRoamingList byte array containing the new PRL
3064 * @return true on success; false on any failure
3065 */
3066 @Override
3067 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3075 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3076 return success;
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Jake Hambye994d462014-02-03 13:10:13 -08003080 }
3081
3082 /**
3083 * Perform the specified type of NV config reset.
3084 * Used for device configuration by some CDMA operators.
3085 *
3086 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3087 * @return true on success; false on any failure
3088 */
3089 @Override
3090 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3092 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 if (DBG) log("nvResetConfig: type " + resetType);
3097 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3098 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3099 return success;
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
Jake Hambye994d462014-02-03 13:10:13 -08003103 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003104
Svet Ganovb320e182015-04-16 12:30:10 -07003105 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003108 return new String[0];
3109 }
3110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 return mPhone.getPcscfAddress(apnType);
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
Wink Saville36469e72014-06-11 15:17:00 -07003117 }
3118
Brad Ebinger51f743a2017-01-23 13:50:20 -08003119 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003120 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3121 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003122 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003123 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003124 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003125
3126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 PhoneFactory.getImsResolver().enableIms(slotId);
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003132 }
3133
3134 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003135 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3136 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003137 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003138 public void disableIms(int slotId) {
3139 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 PhoneFactory.getImsResolver().disableIms(slotId);
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
3146 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003147 }
3148
3149 /**
3150 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3151 * feature or {@link null} if the service is not available. If the feature is available, the
3152 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3153 */
3154 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003155 IImsServiceFeatureCallback callback) {
3156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157
3158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003164 }
3165
3166 /**
3167 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3168 * feature during emergency calling or {@link null} if the service is not available. If the
3169 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3170 * listener for feature updates.
3171 */
3172 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003181 }
3182
Brad Ebinger5f64b052017-12-14 14:26:15 -08003183 /**
3184 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3185 * specified.
3186 */
3187 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003196 }
3197
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003198 /**
3199 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3200 * specified.
3201 */
3202 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3203 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204
3205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003211 }
3212
Brad Ebinger884c07b2018-02-15 16:17:40 -08003213 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003214 * Sets the ImsService Package Name that Telephony will bind to.
3215 *
3216 * @param slotId the slot ID that the ImsService should bind for.
3217 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3218 * ImsService is the device default ImsService.
3219 * @param packageName The package name of the application that contains the ImsService to bind
3220 * to.
3221 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3222 * @hide
3223 */
3224 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003225 int[] subIds = SubscriptionManager.getSubId(slotId);
3226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3227 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3228 "setImsService");
3229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3233 isCarrierImsService, packageName);
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003237 }
3238
3239 /**
3240 * Return the ImsService configuration.
3241 *
3242 * @param slotId The slot that the ImsService is associated with.
3243 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3244 * the device default.
3245 * @return the package name of the ImsService configuration.
3246 */
3247 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003248 int[] subIds = SubscriptionManager.getSubId(slotId);
3249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3250 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3251 "getImsService");
3252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3256 isCarrierImsService);
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003260 }
3261
Wink Saville36469e72014-06-11 15:17:00 -07003262 public void setImsRegistrationState(boolean registered) {
3263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264
3265 final long identity = Binder.clearCallingIdentity();
3266 try {
3267 mPhone.setImsRegistrationState(registered);
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
Wink Saville36469e72014-06-11 15:17:00 -07003271 }
3272
3273 /**
Stuart Scott54788802015-03-30 13:18:01 -07003274 * Set the network selection mode to automatic.
3275 *
3276 */
3277 @Override
3278 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3280 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3285 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Stuart Scott54788802015-03-30 13:18:01 -07003289 }
3290
Pengquan Mengea84e042018-09-20 14:57:26 -07003291 /**
3292 * Ask the radio to connect to the input network and change selection mode to manual.
3293 *
3294 * @param subId the id of the subscription.
3295 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3296 * the operator to attach to.
3297 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3298 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3299 * normal network selection next time.
3300 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003301 */
3302 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003303 public boolean setNetworkSelectionModeManual(
3304 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3306 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 final long identity = Binder.clearCallingIdentity();
3308 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003309 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003311 if (DBG) {
3312 log("setNetworkSelectionModeManual: subId: " + subId
3313 + " operator: " + operatorInfo);
3314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
3318 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003319 }
3320
3321 /**
3322 * Scans for available networks.
3323 */
3324 @Override
3325 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3327 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328
Pengquan Menga1bb6272018-09-06 09:59:22 -07003329 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 try {
3331 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003332 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003337 }
3338
3339 /**
yinxub1bed742017-04-17 11:45:04 -07003340 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003341 *
yinxub1bed742017-04-17 11:45:04 -07003342 * @param subId id of the subscription
3343 * @param request contains the radio access networks with bands/channels to scan
3344 * @param messenger callback messenger for scan results or errors
3345 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003346 * @return the id of the requested scan which can be used to stop the scan.
3347 */
3348 @Override
3349 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3350 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 return mNetworkScanRequestTracker.startNetworkScan(
3357 request, messenger, binder, getPhone(subId));
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
yinxu504e1392017-04-12 16:03:22 -07003361 }
3362
3363 /**
3364 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003365 *
3366 * @param subId id of the subscription
3367 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003368 */
3369 @Override
3370 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3372 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
yinxu504e1392017-04-12 16:03:22 -07003380 }
3381
3382 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003383 * Get the calculated preferred network type.
3384 * Used for debugging incorrect network type.
3385 *
3386 * @return the preferred network type, defined in RILConstants.java.
3387 */
3388 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003389 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003391 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003392 return RILConstants.PREFERRED_NETWORK_MODE;
3393 }
3394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 // FIXME: need to get SubId from somewhere.
3398 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Junda Liu84d15a22014-07-02 11:21:04 -07003402 }
3403
3404 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003405 * Get the preferred network type.
3406 * Used for device configuration by some CDMA operators.
3407 *
3408 * @return the preferred network type, defined in RILConstants.java.
3409 */
3410 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003411 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3413 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 if (DBG) log("getPreferredNetworkType");
3418 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3419 int networkType = (result != null ? result[0] : -1);
3420 if (DBG) log("getPreferredNetworkType: " + networkType);
3421 return networkType;
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003425 }
3426
3427 /**
3428 * Set the preferred network type.
3429 * Used for device configuration by some CDMA operators.
3430 *
3431 * @param networkType the preferred network type, defined in RILConstants.java.
3432 * @return true on success; false on any failure.
3433 */
3434 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003435 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3437 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3442 Boolean success = (Boolean) sendRequest(
3443 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3444 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3445 if (success) {
3446 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3447 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3448 }
3449 return success;
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003452 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003453 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003454
3455 /**
Junda Liu475951f2014-11-07 16:45:03 -08003456 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3457 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3458 * tethering.
3459 *
3460 * @return 0: Not required. 1: required. 2: Not set.
3461 * @hide
3462 */
3463 @Override
3464 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003465 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3470 Settings.Global.TETHER_DUN_REQUIRED, 2);
3471 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3472 // config_tether_apndata.
3473 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3474 dunRequired = 1;
3475 }
3476 return dunRequired;
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003479 }
Junda Liu475951f2014-11-07 16:45:03 -08003480 }
3481
3482 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003483 * Set mobile data enabled
3484 * Used by the user through settings etc to turn on/off mobile data
3485 *
3486 * @param enable {@code true} turn turn data on, else {@code false}
3487 */
3488 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003489 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 int phoneId = mSubscriptionController.getPhoneId(subId);
3496 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3497 Phone phone = PhoneFactory.getPhone(phoneId);
3498 if (phone != null) {
3499 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3500 phone.setUserDataEnabled(enable);
3501 } else {
3502 loge("setUserDataEnabled: no phone for subId=" + subId);
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003506 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003507 }
3508
3509 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003510 * Get the user enabled state of Mobile Data.
3511 *
3512 * TODO: remove and use isUserDataEnabled.
3513 * This can't be removed now because some vendor codes
3514 * calls through ITelephony directly while they should
3515 * use TelephonyManager.
3516 *
3517 * @return true on enabled
3518 */
3519 @Override
3520 public boolean getDataEnabled(int subId) {
3521 return isUserDataEnabled(subId);
3522 }
3523
3524 /**
3525 * Get whether mobile data is enabled per user setting.
3526 *
3527 * There are other factors deciding whether mobile data is actually enabled, but they are
3528 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003529 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003530 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003531 *
3532 * @return {@code true} if data is enabled else {@code false}
3533 */
3534 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003535 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003536 try {
3537 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3538 null);
3539 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3541 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 int phoneId = mSubscriptionController.getPhoneId(subId);
3547 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3548 Phone phone = PhoneFactory.getPhone(phoneId);
3549 if (phone != null) {
3550 boolean retVal = phone.isUserDataEnabled();
3551 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3552 return retVal;
3553 } else {
3554 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3555 return false;
3556 }
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003559 }
3560 }
3561
3562 /**
3563 * Get whether mobile data is enabled.
3564 *
3565 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3566 * whether mobile data is actually enabled.
3567 *
3568 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3569 *
3570 * @return {@code true} if data is enabled else {@code false}
3571 */
3572 @Override
3573 public boolean isDataEnabled(int subId) {
3574 try {
3575 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3576 null);
3577 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3579 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 int phoneId = mSubscriptionController.getPhoneId(subId);
3585 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3586 Phone phone = PhoneFactory.getPhone(phoneId);
3587 if (phone != null) {
3588 boolean retVal = phone.isDataEnabled();
3589 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3590 return retVal;
3591 } else {
3592 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3593 return false;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003597 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003598 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003599
3600 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003601 public int getCarrierPrivilegeStatus(int subId) {
3602 final Phone phone = getPhone(subId);
3603 if (phone == null) {
3604 loge("getCarrierPrivilegeStatus: Invalid subId");
3605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3606 }
3607 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003608 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003609 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3611 }
3612 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003613 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003614 }
Junda Liu29340342014-07-10 15:23:27 -07003615
3616 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3618 final Phone phone = getPhone(subId);
3619 if (phone == null) {
3620 loge("getCarrierPrivilegeStatus: Invalid subId");
3621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3622 }
3623 UiccProfile profile =
3624 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3625 if (profile == null) {
3626 loge("getCarrierPrivilegeStatus: No UICC");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3628 }
3629 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3630 }
3631
3632 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003633 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003634 if (TextUtils.isEmpty(pkgName))
3635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003636 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003637 if (card == null) {
3638 loge("checkCarrierPrivilegesForPackage: No UICC");
3639 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3640 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003641 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3642 }
3643
3644 @Override
3645 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003646 if (TextUtils.isEmpty(pkgName))
3647 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003648 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3649 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3650 UiccCard card = UiccController.getInstance().getUiccCard(i);
3651 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003652 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003653 continue;
3654 }
3655
3656 result = card.getCarrierPrivilegeStatus(
3657 mPhone.getContext().getPackageManager(), pkgName);
3658 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3659 break;
3660 }
3661 }
3662
3663 return result;
Junda Liu29340342014-07-10 15:23:27 -07003664 }
Derek Tan89e89d42014-07-08 17:00:10 -07003665
3666 @Override
Junda Liue64de782015-04-16 17:19:16 -07003667 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3668 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3669 loge("phoneId " + phoneId + " is not valid.");
3670 return null;
3671 }
3672 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003673 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003674 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003675 return null ;
3676 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003677 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003678 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003679 }
3680
Amith Yamasani6e118872016-02-19 12:53:51 -08003681 @Override
3682 public List<String> getPackagesWithCarrierPrivileges() {
3683 PackageManager pm = mPhone.getContext().getPackageManager();
3684 List<String> privilegedPackages = new ArrayList<>();
3685 List<PackageInfo> packages = null;
3686 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3687 UiccCard card = UiccController.getInstance().getUiccCard(i);
3688 if (card == null) {
3689 // No UICC in that slot.
3690 continue;
3691 }
3692 if (card.hasCarrierPrivilegeRules()) {
3693 if (packages == null) {
3694 // Only check packages in user 0 for now
3695 packages = pm.getInstalledPackagesAsUser(
3696 PackageManager.MATCH_DISABLED_COMPONENTS
3697 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3698 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3699 }
3700 for (int p = packages.size() - 1; p >= 0; p--) {
3701 PackageInfo pkgInfo = packages.get(p);
3702 if (pkgInfo != null && pkgInfo.packageName != null
3703 && card.getCarrierPrivilegeStatus(pkgInfo)
3704 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3705 privilegedPackages.add(pkgInfo.packageName);
3706 }
3707 }
3708 }
3709 }
3710 return privilegedPackages;
3711 }
3712
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 final Phone phone = getPhone(subId);
3715 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003716 if (card == null) {
3717 loge("getIccId: No UICC");
3718 return null;
3719 }
3720 String iccId = card.getIccId();
3721 if (TextUtils.isEmpty(iccId)) {
3722 loge("getIccId: ICC ID is null or empty.");
3723 return null;
3724 }
3725 return iccId;
3726 }
3727
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003728 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003729 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3730 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3732 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 final String iccId = getIccId(subId);
3737 final Phone phone = getPhone(subId);
3738 if (phone == null) {
3739 return false;
3740 }
3741 final String subscriberId = phone.getSubscriberId();
3742
3743 if (DBG_MERGE) {
3744 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3745 + subscriberId + " to " + number);
3746 }
3747
3748 if (TextUtils.isEmpty(iccId)) {
3749 return false;
3750 }
3751
3752 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3753
3754 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3755 if (alphaTag == null) {
3756 editor.remove(alphaTagPrefKey);
3757 } else {
3758 editor.putString(alphaTagPrefKey, alphaTag);
3759 }
3760
3761 // Record both the line number and IMSI for this ICCID, since we need to
3762 // track all merged IMSIs based on line number
3763 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3764 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3765 if (number == null) {
3766 editor.remove(numberPrefKey);
3767 editor.remove(subscriberPrefKey);
3768 } else {
3769 editor.putString(numberPrefKey, number);
3770 editor.putString(subscriberPrefKey, subscriberId);
3771 }
3772
3773 editor.commit();
3774 return true;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003777 }
Derek Tan7226c842014-07-02 17:42:23 -07003778 }
3779
3780 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003781 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003782 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003784 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003785 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003786 return null;
3787 }
Derek Tan97ebb422014-09-05 16:55:38 -07003788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 String iccId = getIccId(subId);
3792 if (iccId != null) {
3793 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3794 if (DBG_MERGE) {
3795 log("getLine1NumberForDisplay returning "
3796 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3797 }
3798 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3801 return null;
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003804 }
Derek Tan7226c842014-07-02 17:42:23 -07003805 }
3806
3807 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003808 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003810 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003811 return null;
3812 }
Derek Tan97ebb422014-09-05 16:55:38 -07003813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 String iccId = getIccId(subId);
3817 if (iccId != null) {
3818 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3819 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3820 }
3821 return null;
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003824 }
Derek Tan7226c842014-07-02 17:42:23 -07003825 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003826
3827 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003828 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003829 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3830 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003832 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3833 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003834 return null;
3835 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003836
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003837 final long identity = Binder.clearCallingIdentity();
3838 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final Context context = mPhone.getContext();
3840 final TelephonyManager tele = TelephonyManager.from(context);
3841 final SubscriptionManager sub = SubscriptionManager.from(context);
3842
3843 // Figure out what subscribers are currently active
3844 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3845 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3846 // the process, where TelephonyManager was instantiated.
3847 // Otherwise AppOps check will fail.
3848
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003849 final int[] subIds = sub.getActiveSubscriptionIdList();
3850 for (int subId : subIds) {
3851 activeSubscriberIds.add(tele.getSubscriberId(subId));
3852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853
3854 // First pass, find a number override for an active subscriber
3855 String mergeNumber = null;
3856 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3857 for (String key : prefs.keySet()) {
3858 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3859 final String subscriberId = (String) prefs.get(key);
3860 if (activeSubscriberIds.contains(subscriberId)) {
3861 final String iccId = key.substring(
3862 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3863 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3864 mergeNumber = (String) prefs.get(numberKey);
3865 if (DBG_MERGE) {
3866 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3867 + " for active subscriber " + subscriberId);
3868 }
3869 if (!TextUtils.isEmpty(mergeNumber)) {
3870 break;
3871 }
3872 }
3873 }
3874 }
3875
3876 // Shortcut when no active merged subscribers
3877 if (TextUtils.isEmpty(mergeNumber)) {
3878 return null;
3879 }
3880
3881 // Second pass, find all subscribers under that line override
3882 final ArraySet<String> result = new ArraySet<>();
3883 for (String key : prefs.keySet()) {
3884 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3885 final String number = (String) prefs.get(key);
3886 if (mergeNumber.equals(number)) {
3887 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3888 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3889 final String subscriberId = (String) prefs.get(subscriberKey);
3890 if (!TextUtils.isEmpty(subscriberId)) {
3891 result.add(subscriberId);
3892 }
3893 }
3894 }
3895 }
3896
3897 final String[] resultArray = result.toArray(new String[result.size()]);
3898 Arrays.sort(resultArray);
3899 if (DBG_MERGE) {
3900 Slog.d(LOG_TAG,
3901 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3902 }
3903 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003906 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003907 }
3908
3909 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003910 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3912 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 final Phone phone = getPhone(subId);
3917 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003921 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003922
3923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003924 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003925 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3926 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928
3929 final long identity = Binder.clearCallingIdentity();
3930 try {
3931 final Phone phone = getPhone(subId);
3932 if (phone == null) {
3933 return false;
3934 }
3935 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3936 cdmaNonRoamingList);
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003939 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003940 }
3941
3942 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003943 @Deprecated
3944 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3945 enforceModifyPermission();
3946
3947 int returnValue = 0;
3948 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003949 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003950 if(result.exception == null) {
3951 if (result.result != null) {
3952 byte[] responseData = (byte[])(result.result);
3953 if(responseData.length > oemResp.length) {
3954 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3955 responseData.length + "bytes. Buffer Size is " +
3956 oemResp.length + "bytes.");
3957 }
3958 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3959 returnValue = responseData.length;
3960 }
3961 } else {
3962 CommandException ex = (CommandException) result.exception;
3963 returnValue = ex.getCommandError().ordinal();
3964 if(returnValue > 0) returnValue *= -1;
3965 }
3966 } catch (RuntimeException e) {
3967 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3968 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3969 if(returnValue > 0) returnValue *= -1;
3970 }
3971
3972 return returnValue;
3973 }
3974
3975 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003976 public void setRadioCapability(RadioAccessFamily[] rafs) {
3977 try {
3978 ProxyController.getInstance().setRadioCapability(rafs);
3979 } catch (RuntimeException e) {
3980 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3981 }
3982 }
3983
3984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003985 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003986 Phone phone = PhoneFactory.getPhone(phoneId);
3987 if (phone == null) {
3988 return RadioAccessFamily.RAF_UNKNOWN;
3989 }
3990 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003992 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003993 return RadioAccessFamily.RAF_UNKNOWN;
3994 }
3995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004002 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004003
4004 @Override
4005 public void enableVideoCalling(boolean enable) {
4006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004014 }
4015
4016 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004017 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4019 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4020 return false;
4021 }
Svet Ganovb320e182015-04-16 12:30:10 -07004022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // Check the user preference and the system-level IMS setting. Even if the user has
4026 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4027 // In the long run, we may instead need to check if there exists a connection service
4028 // which can support video calling.
4029 ImsManager imsManager =
4030 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4031 return imsManager.isVtEnabledByPlatform()
4032 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4033 && imsManager.isVtEnabledByUser();
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004037 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004038
Andrew Leea1239f22015-03-02 17:44:07 -08004039 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4042 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4043 return false;
4044 }
4045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 CarrierConfigManager configManager =
4049 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4050 return configManager.getConfigForSubId(mPhone.getSubId())
4051 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Andrew Leea1239f22015-03-02 17:44:07 -08004055 }
4056
4057 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 public boolean isWorldPhone(int subId, String callingPackage) {
4059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4060 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4061 return false;
4062 }
4063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 CarrierConfigManager configManager =
4067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4068 return configManager.getConfigForSubId(mPhone.getSubId())
4069 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Andrew Leea1239f22015-03-02 17:44:07 -08004073 }
4074
Andrew Lee9431b832015-03-09 18:46:45 -07004075 @Override
4076 public boolean isTtyModeSupported() {
4077 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004078 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004079 }
4080
4081 @Override
4082 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
Andrew Lee9431b832015-03-09 18:46:45 -07004089 }
4090
Hall Liu98187582018-01-22 19:15:32 -08004091 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4095 mPhone.getSubId()).getBoolean(
4096 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4097 boolean isDeviceSupported =
4098 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4099 return isCarrierSupported && isDeviceSupported;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Hall Liu98187582018-01-22 19:15:32 -08004103 }
4104
Hall Liu3ad5f012018-04-06 16:23:39 -07004105 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 return isRttSupported() && Settings.Secure.getInt(
4109 mPhone.getContext().getContentResolver(),
4110 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004114 }
4115
Sanket Padawe7310cc72015-01-14 09:53:20 -08004116 /**
4117 * Returns the unique device ID of phone, for example, the IMEI for
4118 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4119 *
4120 * <p>Requires Permission:
4121 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4122 */
4123 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004124 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004125 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004126 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004127 return null;
4128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004129 int subId = phone.getSubId();
4130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4131 mApp, subId, callingPackage, "getDeviceId")) {
4132 return null;
4133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 return phone.getDeviceId();
4138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004141 }
4142
Ping Sunc67b7c22016-03-02 19:16:45 +08004143 /**
4144 * {@hide}
4145 * Returns the IMS Registration Status on a particular subid
4146 *
4147 * @param subId
4148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004149 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004150 Phone phone = getPhone(subId);
4151 if (phone != null) {
4152 return phone.isImsRegistered();
4153 } else {
4154 return false;
4155 }
4156 }
4157
Santos Cordon7a1885b2015-02-03 11:15:19 -08004158 @Override
4159 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004166 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004167
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004168 /**
4169 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004170 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004171 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 Phone phone = getPhone(subId);
4175 if (phone != null) {
4176 return phone.isWifiCallingEnabled();
4177 } else {
4178 return false;
4179 }
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004183 }
4184
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004185 /**
4186 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004187 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
4191 Phone phone = getPhone(subId);
4192 if (phone != null) {
4193 return phone.isVolteEnabled();
4194 } else {
4195 return false;
4196 }
4197 } finally {
4198 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004200 }
Svet Ganovb320e182015-04-16 12:30:10 -07004201
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 /**
4203 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004204 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 Phone phone = getPhone(subId);
4209 if (phone != null) {
4210 return phone.isVideoEnabled();
4211 } else {
4212 return false;
4213 }
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004216 }
4217 }
4218
4219 /**
4220 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4221 * defined in {@link ImsRegistrationImplBase}.
4222 */
4223 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.getImsRegistrationTech();
4229 } else {
4230 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004235 }
4236
Stuart Scott8eef64f2015-04-08 15:13:54 -07004237 @Override
4238 public void factoryReset(int subId) {
4239 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004240 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4241 return;
4242 }
4243
Svet Ganovcc087f82015-05-12 20:35:54 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004246 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004248 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004249 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004250 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4251 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004252 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004253 }
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004256 }
4257 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004258
4259 @Override
4260 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // We query all subscriptions instead of just the active ones, because
4264 // this might be called early on in the provisioning flow when the
4265 // subscriptions potentially aren't active yet.
4266 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4267 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004268 return null;
4269 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271 // This function may be called very early, say, from the setup wizard, at
4272 // which point we won't have a default subscription set. If that's the case
4273 // we just choose the first, which will be valid in "most cases".
4274 final int defaultSubId = getDefaultSubscription();
4275 SubscriptionInfo info = null;
4276 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4277 info = slist.get(0);
4278 } else {
4279 for (SubscriptionInfo item : slist) {
4280 if (item.getSubscriptionId() == defaultSubId) {
4281 info = item;
4282 break;
4283 }
4284 }
4285
4286 if (info == null) {
4287 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004288 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004289 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 // Try and fetch the locale from the carrier properties or from the SIM language
4292 // preferences (EF-PL and EF-LI)...
4293 final int mcc = info.getMcc();
4294 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4295 String simLanguage = null;
4296 if (defaultPhone != null) {
4297 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4298 if (localeFromDefaultSim != null) {
4299 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4300 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4301 return localeFromDefaultSim.toLanguageTag();
4302 } else {
4303 simLanguage = localeFromDefaultSim.getLanguage();
4304 }
4305 }
4306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 // The SIM language preferences only store a language (e.g. fr = French), not an
4309 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4310 // the SIM and carrier preferences does not include a country we add the country
4311 // determined from the SIM MCC to provide an exact locale.
4312 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4313 simLanguage);
4314 if (mccLocale != null) {
4315 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4316 return mccLocale.toLanguageTag();
4317 }
4318
4319 if (DBG) log("No locale found - returning null");
4320 return null;
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004324 }
4325
4326 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327 return mSubscriptionController.getAllSubInfoList(
4328 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004329 }
4330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 /**
4332 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4333 */
4334 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4335 return mSubscriptionController.getActiveSubscriptionInfoList(
4336 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004337 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004338
Chenjie Yu1ba97252018-01-11 18:16:20 -08004339 private final ModemActivityInfo mLastModemActivityInfo =
4340 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4341
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004342 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004343 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4344 * representing the state of the modem.
4345 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004346 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4347 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004348 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004349 */
4350 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004351 public void requestModemActivityInfo(ResultReceiver result) {
4352 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 ModemActivityInfo ret = null;
4358 synchronized (mLastModemActivityInfo) {
4359 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4360 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004361 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004362 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4364 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4365 mergedTxTimeMs[i] =
4366 info.getTxTimeMillis()[i]
4367 + mLastModemActivityInfo.getTxTimeMillis()[i];
4368 }
4369 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4370 mLastModemActivityInfo.setSleepTimeMillis(
4371 info.getSleepTimeMillis()
4372 + mLastModemActivityInfo.getSleepTimeMillis());
4373 mLastModemActivityInfo.setIdleTimeMillis(
4374 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4375 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4376 mLastModemActivityInfo.setRxTimeMillis(
4377 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4378 mLastModemActivityInfo.setEnergyUsed(
4379 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4382 mLastModemActivityInfo.getSleepTimeMillis(),
4383 mLastModemActivityInfo.getIdleTimeMillis(),
4384 mLastModemActivityInfo.getTxTimeMillis(),
4385 mLastModemActivityInfo.getRxTimeMillis(),
4386 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388 Bundle bundle = new Bundle();
4389 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4390 result.send(0, bundle);
4391 } finally {
4392 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004393 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004394 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004395
Siddharth Rayb8114062018-06-17 15:02:38 -07004396 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4397 // less than total activity duration.
4398 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4399 if (info == null) {
4400 return false;
4401 }
4402 int activityDurationMs =
4403 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4404 int totalTxTimeMs = 0;
4405 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4406 totalTxTimeMs += info.getTxTimeMillis()[i];
4407 }
4408 return (info.isValid()
4409 && (info.getSleepTimeMillis() <= activityDurationMs)
4410 && (info.getIdleTimeMillis() <= activityDurationMs)
4411 && (info.getRxTimeMillis() <= activityDurationMs)
4412 && (totalTxTimeMs <= activityDurationMs));
4413 }
4414
Jack Yu85bd38a2015-11-09 11:34:32 -08004415 /**
4416 * {@hide}
4417 * Returns the service state information on specified subscription.
4418 */
4419 @Override
4420 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004421 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004422 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004423 return null;
4424 }
4425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 final Phone phone = getPhone(subId);
4429 if (phone == null) {
4430 return null;
4431 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 return phone.getServiceState();
4434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004437 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004438
4439 /**
4440 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4441 *
4442 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4443 * voicemail ringtone.
4444 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4445 * PhoneAccount.
4446 */
4447 @Override
4448 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4452 if (phone == null) {
4453 phone = mPhone;
4454 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004460 }
4461
4462 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004463 * Sets the per-account voicemail ringtone.
4464 *
4465 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4466 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4467 *
4468 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4469 * voicemail ringtone.
4470 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4471 * PhoneAccount.
4472 */
4473 @Override
4474 public void setVoicemailRingtoneUri(String callingPackage,
4475 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4477 if (!TextUtils.equals(callingPackage,
4478 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4480 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4481 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4487 if (phone == null) {
4488 phone = mPhone;
4489 }
4490 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4491 } finally {
4492 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004493 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004494 }
4495
4496 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004497 * Returns whether vibration is set for voicemail notification in Phone settings.
4498 *
4499 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4500 * voicemail vibration setting.
4501 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4502 */
4503 @Override
4504 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 final long identity = Binder.clearCallingIdentity();
4506 try {
4507 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4508 if (phone == null) {
4509 phone = mPhone;
4510 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004516 }
4517
Youhan Wange64578a2016-05-02 15:32:42 -07004518 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004519 * Sets the per-account voicemail vibration.
4520 *
4521 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4522 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4523 *
4524 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4525 * voicemail vibration setting.
4526 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4527 * specific PhoneAccount.
4528 */
4529 @Override
4530 public void setVoicemailVibrationEnabled(String callingPackage,
4531 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4532 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4533 if (!TextUtils.equals(callingPackage,
4534 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4536 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4537 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004538 }
4539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4543 if (phone == null) {
4544 phone = mPhone;
4545 }
4546 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004549 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004550 }
4551
4552 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004553 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4554 *
4555 * @throws SecurityException if the caller does not have the required permission
4556 */
4557 private void enforceReadPrivilegedPermission() {
4558 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4559 null);
4560 }
4561
4562 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004563 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4564 * permission.
4565 *
4566 * @throws SecurityException if the caller does not have the required permission
4567 */
4568 private void enforceSendSmsPermission() {
4569 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4570 }
4571
4572 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004573 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004574 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004575 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004576 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004577 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 ComponentName componentName =
4581 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4582 if (componentName == null) {
4583 throw new SecurityException(
4584 "Caller not current active visual voicemail package[null]");
4585 }
4586 String vvmPackage = componentName.getPackageName();
4587 if (!callingPackage.equals(vvmPackage)) {
4588 throw new SecurityException("Caller not current active visual voicemail package["
4589 + vvmPackage + "]");
4590 }
4591 } finally {
4592 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004593 }
4594 }
4595
4596 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004597 * Return the application ID for the app type.
4598 *
4599 * @param subId the subscription ID that this request applies to.
4600 * @param appType the uicc app type.
4601 * @return Application ID for specificied app type, or null if no uicc.
4602 */
4603 @Override
4604 public String getAidForAppType(int subId, int appType) {
4605 enforceReadPrivilegedPermission();
4606 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607
4608 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004609 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 if (phone == null) {
4611 return null;
4612 }
4613 String aid = null;
4614 try {
4615 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4616 .getApplicationByType(appType).getAid();
4617 } catch (Exception e) {
4618 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4619 }
4620 return aid;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004623 }
Youhan Wange64578a2016-05-02 15:32:42 -07004624 }
4625
Youhan Wang4001d252016-05-11 10:29:41 -07004626 /**
4627 * Return the Electronic Serial Number.
4628 *
4629 * @param subId the subscription ID that this request applies to.
4630 * @return ESN or null if error.
4631 */
4632 @Override
4633 public String getEsn(int subId) {
4634 enforceReadPrivilegedPermission();
4635 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004638 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 if (phone == null) {
4640 return null;
4641 }
4642 String esn = null;
4643 try {
4644 esn = phone.getEsn();
4645 } catch (Exception e) {
4646 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4647 }
4648 return esn;
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004651 }
Youhan Wang4001d252016-05-11 10:29:41 -07004652 }
4653
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004654 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004655 * Return the Preferred Roaming List Version.
4656 *
4657 * @param subId the subscription ID that this request applies to.
4658 * @return PRLVersion or null if error.
4659 */
4660 @Override
4661 public String getCdmaPrlVersion(int subId) {
4662 enforceReadPrivilegedPermission();
4663 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004666 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 if (phone == null) {
4668 return null;
4669 }
4670 String cdmaPrlVersion = null;
4671 try {
4672 cdmaPrlVersion = phone.getCdmaPrlVersion();
4673 } catch (Exception e) {
4674 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4675 }
4676 return cdmaPrlVersion;
4677 } finally {
4678 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004679 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004680 }
4681
4682 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004683 * Get snapshot of Telephony histograms
4684 * @return List of Telephony histograms
4685 * @hide
4686 */
4687 @Override
4688 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4690 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 return RIL.getTelephonyRILTimingHistograms();
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004698 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699
4700 /**
4701 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004702 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004703 * Require system privileges. In the future we may add this to carrier APIs.
4704 *
4705 * @return The number of carriers set successfully, should match length of carriers
4706 */
4707 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004708 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004709 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004711
Meng Wang9b7c4e92017-02-17 11:41:27 -08004712 if (carriers == null) {
4713 throw new NullPointerException("carriers cannot be null");
4714 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004719 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4720 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 return retVal[0];
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004725 }
4726
4727 /**
4728 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004729 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004730 * Require system privileges. In the future we may add this to carrier APIs.
4731 *
4732 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4733 * means all carriers are allowed.
4734 */
4735 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004736 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004737 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739
4740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004743 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4744 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004748 }
4749
fionaxu59545b42016-05-25 15:53:37 -07004750 /**
4751 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4752 * @param subId the subscription ID that this action applies to.
4753 * @param enabled control enable or disable metered apns.
4754 * {@hide}
4755 */
4756 @Override
4757 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4758 enforceModifyPermission();
4759 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760
4761 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004762 if (phone == null) {
4763 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4764 return;
4765 }
4766 try {
4767 phone.carrierActionSetMeteredApnsEnabled(enabled);
4768 } catch (Exception e) {
4769 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004772 }
4773 }
4774
4775 /**
4776 * Action set from carrier signalling broadcast receivers to enable/disable radio
4777 * @param subId the subscription ID that this action applies to.
4778 * @param enabled control enable or disable radio.
4779 * {@hide}
4780 */
4781 @Override
4782 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4783 enforceModifyPermission();
4784 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785
4786 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004787 if (phone == null) {
4788 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4789 return;
4790 }
4791 try {
4792 phone.carrierActionSetRadioEnabled(enabled);
4793 } catch (Exception e) {
4794 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 } finally {
4796 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004797 }
4798 }
4799
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004800 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004801 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4802 * network status based on which carrier apps could apply actions accordingly,
4803 * enable/disable default url handler for example.
4804 *
4805 * @param subId the subscription ID that this action applies to.
4806 * @param report control start/stop reporting the default network status.
4807 * {@hide}
4808 */
4809 @Override
4810 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4811 enforceModifyPermission();
4812 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
4814 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004815 if (phone == null) {
4816 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4817 return;
4818 }
4819 try {
4820 phone.carrierActionReportDefaultNetworkStatus(report);
4821 } catch (Exception e) {
4822 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 } finally {
4824 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004825 }
4826 }
4827
4828 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004829 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4830 * bug report is being generated.
4831 */
4832 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004833 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004834 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4835 != PackageManager.PERMISSION_GRANTED) {
4836 writer.println("Permission Denial: can't dump Phone from pid="
4837 + Binder.getCallingPid()
4838 + ", uid=" + Binder.getCallingUid()
4839 + "without permission "
4840 + android.Manifest.permission.DUMP);
4841 return;
4842 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004843 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004844 }
Jack Yueb89b242016-06-22 13:27:47 -07004845
Brad Ebingerdac2f002018-04-03 15:17:52 -07004846 @Override
4847 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4848 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4849 throws RemoteException {
4850 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4851 }
4852
Jack Yueb89b242016-06-22 13:27:47 -07004853 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004854 * Get aggregated video call data usage since boot.
4855 *
4856 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4857 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004858 * {@hide}
4859 */
4860 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004861 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004862 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4863 null);
4864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 // NetworkStatsService keeps tracking the active network interface and identity. It
4868 // records the delta with the corresponding network identity.
4869 // We just return the total video call data usage snapshot since boot.
4870 Phone phone = getPhone(subId);
4871 if (phone != null) {
4872 return phone.getVtDataUsage(perUidStats);
4873 }
4874 return null;
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004877 }
Jack Yueb89b242016-06-22 13:27:47 -07004878 }
Jack Yu75ab2952016-07-08 14:29:33 -07004879
4880 /**
4881 * Policy control of data connection. Usually used when data limit is passed.
4882 * @param enabled True if enabling the data, otherwise disabling.
4883 * @param subId Subscription index
4884 * {@hide}
4885 */
4886 @Override
4887 public void setPolicyDataEnabled(boolean enabled, int subId) {
4888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 Phone phone = getPhone(subId);
4893 if (phone != null) {
4894 phone.setPolicyDataEnabled(enabled);
4895 }
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004898 }
4899 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004900
4901 /**
4902 * Get Client request stats
4903 * @return List of Client Request Stats
4904 * @hide
4905 */
4906 @Override
4907 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004909 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004910 return null;
4911 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004912 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 if (phone != null) {
4917 return phone.getClientRequestStats();
4918 }
4919
4920 return null;
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004924 }
4925
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004926 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004927 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004928 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004929 }
Jack Yueb4124c2017-02-16 15:32:43 -08004930
4931 /**
Grace Chen70990072017-03-24 17:21:30 -07004932 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004933 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004934 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004935 * @param state State of SIM (power down, power up, pass through)
4936 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4937 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4938 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004939 *
4940 **/
4941 @Override
Grace Chen70990072017-03-24 17:21:30 -07004942 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004943 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004944 Phone phone = PhoneFactory.getPhone(slotIndex);
4945
vagdeviaf9a5b92018-08-15 16:01:53 -07004946 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 final long identity = Binder.clearCallingIdentity();
4949 try {
4950 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004951 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 }
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004955 }
4956 }
Shuo Qiandd210312017-04-12 22:11:33 +00004957
Tyler Gunn65d45c22017-06-05 11:22:26 -07004958 private boolean isUssdApiAllowed(int subId) {
4959 CarrierConfigManager configManager =
4960 (CarrierConfigManager) mPhone.getContext().getSystemService(
4961 Context.CARRIER_CONFIG_SERVICE);
4962 if (configManager == null) {
4963 return false;
4964 }
4965 PersistableBundle pb = configManager.getConfigForSubId(subId);
4966 if (pb == null) {
4967 return false;
4968 }
4969 return pb.getBoolean(
4970 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4971 }
4972
Shuo Qiandd210312017-04-12 22:11:33 +00004973 /**
4974 * Check if phone is in emergency callback mode
4975 * @return true if phone is in emergency callback mode
4976 * @param subId sub id
4977 */
goneil9c5f4872017-12-05 14:07:56 -08004978 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004979 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004980 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 if (phone != null) {
4986 return phone.isInEcm();
4987 } else {
4988 return false;
4989 }
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004992 }
4993 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004994
4995 /**
4996 * Get the current signal strength information for the given subscription.
4997 * Because this information is not updated when the device is in a low power state
4998 * it should not be relied-upon to be current.
4999 * @param subId Subscription index
5000 * @return the most recent cached signal strength info from the modem
5001 */
5002 @Override
5003 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 final long identity = Binder.clearCallingIdentity();
5005 try {
5006 Phone p = getPhone(subId);
5007 if (p == null) {
5008 return null;
5009 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 return p.getSignalStrength();
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005016
Pengquan Meng77b7f132018-08-22 14:49:57 -07005017 /**
5018 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5019 *
5020 * <p>Requires one of the following permissions:
5021 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5022 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5023 * privileges.
5024 *
5025 * @param subId subscription id
5026 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5027 * {@code false}.
5028 */
5029 @Override
5030 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005031 boolean isEnabled = false;
5032 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005033 try {
5034 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005035 null /* message */);
5036 Phone phone = getPhone(subId);
5037 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005038 } catch (Exception e) {
5039 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5040 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005041 } finally {
5042 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005043 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005044 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005045 }
5046
5047
5048 /**
5049 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5050 *
5051 * <p> Requires permission:
5052 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5053 * privileges.
5054 *
5055 * @param subId subscription id
5056 * @param isEnabled {@code true} means enable, {@code false} means disable.
5057 */
5058 @Override
5059 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005060 final long identity = Binder.clearCallingIdentity();
5061 try {
5062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5063 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005064
Pengquan Menga1bb6272018-09-06 09:59:22 -07005065 Phone phone = getPhone(subId);
5066 if (phone != null) {
5067 phone.setDataRoamingEnabled(isEnabled);
5068 }
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005071 }
5072 }
5073
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005074 @Override
5075 public UiccSlotInfo[] getUiccSlotsInfo() {
5076 enforceReadPrivilegedPermission();
5077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5081 if (slots == null) {
5082 Rlog.i(LOG_TAG, "slots is null.");
5083 return null;
5084 }
5085
5086 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5087 for (int i = 0; i < slots.length; i++) {
5088 UiccSlot slot = slots[i];
5089 if (slot == null) {
5090 continue;
5091 }
5092
5093 String cardId;
5094 UiccCard card = slot.getUiccCard();
5095 if (card != null) {
5096 cardId = card.getCardId();
5097 } else {
5098 cardId = slot.getIccId();
5099 }
5100
5101 int cardState = 0;
5102 switch (slot.getCardState()) {
5103 case CARDSTATE_ABSENT:
5104 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5105 break;
5106 case CARDSTATE_PRESENT:
5107 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5108 break;
5109 case CARDSTATE_ERROR:
5110 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5111 break;
5112 case CARDSTATE_RESTRICTED:
5113 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5114 break;
5115 default:
5116 break;
5117
5118 }
5119
5120 infos[i] = new UiccSlotInfo(
5121 slot.isActive(),
5122 slot.isEuicc(),
5123 cardId,
5124 cardState,
5125 slot.getPhoneId(),
5126 slot.isExtendedApduSupported());
5127 }
5128 return infos;
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005131 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005132 }
5133
5134 @Override
5135 public boolean switchSlots(int[] physicalSlots) {
5136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137
5138 final long identity = Binder.clearCallingIdentity();
5139 try {
5140 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005144 }
Jack Yu4c988042018-02-27 15:30:01 -08005145
5146 @Override
5147 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5148 enforceModifyPermission();
5149 final Phone phone = getPhone(subId);
5150 if (phone == null) {
5151 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5152 return;
5153 }
5154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 phone.setRadioIndicationUpdateMode(filters, mode);
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Jack Yu4c988042018-02-27 15:30:01 -08005161 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005162
5163 /**
goneil47ffb6e2018-04-06 15:40:58 -07005164 * A test API to reload the UICC profile.
5165 *
5166 * <p>Requires that the calling app has permission
5167 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5168 * @hide
5169 */
5170 @Override
5171 public void refreshUiccProfile(int subId) {
5172 enforceModifyPermission();
5173
5174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 Phone phone = getPhone(subId);
5177 if (phone == null) {
5178 return;
5179 }
5180 UiccCard uiccCard = phone.getUiccCard();
5181 if (uiccCard == null) {
5182 return;
5183 }
5184 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5185 if (uiccProfile == null) {
5186 return;
5187 }
5188 uiccProfile.refresh();
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
5192 }
5193
5194 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005195 * Returns false if the mobile data is disabled by default, otherwise return true.
5196 */
5197 private boolean getDefaultDataEnabled() {
5198 return "true".equalsIgnoreCase(
5199 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5200 }
5201
5202 /**
5203 * Returns true if the data roaming is enabled by default, i.e the system property
5204 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5205 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5206 */
5207 private boolean getDefaultDataRoamingEnabled(int subId) {
5208 final CarrierConfigManager configMgr = (CarrierConfigManager)
5209 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5210 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5211 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5212 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5213 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5214 return isDataRoamingEnabled;
5215 }
5216
5217 /**
5218 * Returns the default network type for the given {@code subId}, if the default network type is
5219 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5220 */
5221 private int getDefaultNetworkType(int subId) {
5222 return Integer.parseInt(
5223 TelephonyManager.getTelephonyProperty(
5224 mSubscriptionController.getPhoneId(subId),
5225 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5226 String.valueOf(Phone.PREFERRED_NT_MODE)));
5227 }
fionaxua13278b2018-03-21 00:08:13 -07005228
5229 @Override
5230 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5231 gid1, String gid2, String plmn, String spn) {
5232 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233
5234 final long identity = Binder.clearCallingIdentity();
5235 try {
5236 final Phone phone = getPhone(subId);
5237 if (phone == null) {
5238 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5239 return;
5240 }
5241 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005244 }
fionaxua13278b2018-03-21 00:08:13 -07005245 }
5246
5247 @Override
5248 public int getCarrierIdListVersion(int subId) {
5249 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 final Phone phone = getPhone(subId);
5254 if (phone == null) {
5255 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5256 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5257 }
5258 return phone.getCarrierIdListVersion();
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005261 }
fionaxua13278b2018-03-21 00:08:13 -07005262 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005263
5264 @Override
5265 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5267 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5268 return -1;
5269 }
5270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
5277 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005278
5279 @Override
5280 public int getCdmaRoamingMode(int subId) {
5281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5282 mApp, subId, "getCdmaRoamingMode");
5283
5284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
5290 }
5291
5292 @Override
5293 public boolean setCdmaRoamingMode(int subId, int mode) {
5294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "setCdmaRoamingMode");
5296
5297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
5303 }
5304
5305 @Override
5306 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5308 mApp, subId, "setCdmaSubscriptionMode");
5309
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005317
5318 private void ensureUserRunning(int userId) {
5319 if (!mUserManager.isUserRunning(userId)) {
5320 throw new IllegalStateException("User " + userId + " does not exist or not running");
5321 }
5322 }
5323
5324 /**
5325 * Returns a list of SMS apps on a given user.
5326 *
5327 * Only the shell user (UID 2000 or 0) can call it.
5328 * Target user must be running.
5329 */
5330 @Override
5331 public String[] getSmsApps(int userId) {
5332 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5333 ensureUserRunning(userId);
5334
5335 final Collection<SmsApplicationData> apps =
5336 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5337
5338 String[] ret = new String[apps.size()];
5339 int i = 0;
5340 for (SmsApplicationData app : apps) {
5341 ret[i++] = app.mPackageName;
5342 }
5343 return ret;
5344 }
5345
5346 /**
5347 * Returns the default SMS app package name on a given user.
5348 *
5349 * Only the shell user (UID 2000 or 0) can call it.
5350 * Target user must be running.
5351 */
5352 @Override
5353 public String getDefaultSmsApp(int userId) {
5354 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5355 ensureUserRunning(userId);
5356
5357 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5358 /* updateIfNeeded= */ true, userId);
5359 return cn == null ? null : cn.getPackageName();
5360 }
5361
5362 /**
5363 * Set a package as the default SMS app on a given user.
5364 *
5365 * Only the shell user (UID 2000 or 0) can call it.
5366 * Target user must be running.
5367 */
5368 @Override
5369 public void setDefaultSmsApp(int userId, String packageName) {
5370 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5371 ensureUserRunning(userId);
5372
5373 boolean found = false;
5374 for (String pkg : getSmsApps(userId)) {
5375 if (TextUtils.equals(packageName, pkg)) {
5376 found = true;
5377 break;
5378 }
5379 }
5380 if (!found) {
5381 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5382 }
5383
5384 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005386}