blob: 6fb9be59cc49151aaa96acec0eb8e9a4081ca8b6 [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
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080089import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070092import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsMmTelFeature;
94import android.telephony.ims.aidl.IImsRcsFeature;
95import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.feature.MmTelFeature;
98import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080099import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800104import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800105
Brad Ebinger4c460712018-10-01 10:40:55 -0700106import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700107import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800108import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700110import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700111import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800112import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700113import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800116import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800118import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700119import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700121import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700124import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800125import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700126import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700127import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700128import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700129import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700130import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700131import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800132import com.android.internal.telephony.SmsApplication;
133import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800134import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800135import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800136import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700137import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.uicc.IccIoResult;
139import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800140import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700141import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800142import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800144import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000145import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700146import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800147import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700148import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800149import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700150import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700151import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800152
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700153import java.io.FileDescriptor;
154import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800155import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800158import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800159import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800160import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800161import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100162import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800163import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800164import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165
166/**
167 * Implementation of the ITelephony interface.
168 */
Santos Cordon117fee72014-05-16 17:56:12 -0700169public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170 private static final String LOG_TAG = "PhoneInterfaceManager";
171 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
172 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174
175 // Message codes used with mMainThreadHandler
176 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700177 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
178 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179 private static final int CMD_OPEN_CHANNEL = 9;
180 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
181 private static final int CMD_CLOSE_CHANNEL = 11;
182 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800183 private static final int CMD_NV_READ_ITEM = 13;
184 private static final int EVENT_NV_READ_ITEM_DONE = 14;
185 private static final int CMD_NV_WRITE_ITEM = 15;
186 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
187 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
188 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700189 private static final int CMD_RESET_MODEM_CONFIG = 19;
190 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800191 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
192 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
193 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
194 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800195 private static final int CMD_SEND_ENVELOPE = 25;
196 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000197 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
198 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700199 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
200 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
201 private static final int CMD_EXCHANGE_SIM_IO = 31;
202 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800203 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
204 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700205 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700207 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
208 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700209 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
210 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
211 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
212 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700213 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
214 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
215 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
216 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700217 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800218 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
219 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000220 private static final int CMD_SWITCH_SLOTS = 50;
221 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700222 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
223 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
224 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
225 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
226 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
227 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
228 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
229 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700230 private static final int CMD_GET_ALL_CELL_INFO = 60;
231 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
232 private static final int CMD_GET_CELL_LOCATION = 62;
233 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700234 private static final int CMD_MODEM_REBOOT = 64;
235 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700236 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
237 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800238 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
239 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800241 // Parameters of select command.
242 private static final int SELECT_COMMAND = 0xA4;
243 private static final int SELECT_P1 = 0x04;
244 private static final int SELECT_P2 = 0;
245 private static final int SELECT_P3 = 0x10;
246
Pengquan Meng85728fb2018-03-12 16:31:21 -0700247 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
248 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
249 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
250
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 /** The singleton instance. */
252 private static PhoneInterfaceManager sInstance;
253
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700256 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private AppOpsManager mAppOps;
258 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800259 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800260 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700261 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
Derek Tan97ebb422014-09-05 16:55:38 -0700263 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
264 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800265 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800266 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700267
Micheled3107c52018-12-21 15:00:11 -0800268 // String to store multi SIM allowed
269 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
270
Derek Tan740e1672017-06-27 14:56:27 -0700271 // The AID of ISD-R.
272 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
273
yinxub1bed742017-04-17 11:45:04 -0700274 private NetworkScanRequestTracker mNetworkScanRequestTracker;
275
David Kelly5e06a7f2018-03-12 14:10:59 +0000276 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
277 private static final int MANUFACTURER_CODE_LENGTH = 8;
278
Derek Tan89e89d42014-07-08 17:00:10 -0700279 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 * A request object to use for transmitting data to an ICC.
281 */
282 private static final class IccAPDUArgument {
283 public int channel, cla, command, p1, p2, p3;
284 public String data;
285
286 public IccAPDUArgument(int channel, int cla, int command,
287 int p1, int p2, int p3, String data) {
288 this.channel = channel;
289 this.cla = cla;
290 this.command = command;
291 this.p1 = p1;
292 this.p2 = p2;
293 this.p3 = p3;
294 this.data = data;
295 }
296 }
297
298 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700299 * A request object to use for transmitting data to an ICC.
300 */
301 private static final class ManualNetworkSelectionArgument {
302 public OperatorInfo operatorInfo;
303 public boolean persistSelection;
304
305 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
306 this.operatorInfo = operatorInfo;
307 this.persistSelection = persistSelection;
308 }
309 }
310
311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
313 * request after sending. The main thread will notify the request when it is complete.
314 */
315 private static final class MainThreadRequest {
316 /** The argument to use for the request */
317 public Object argument;
318 /** The result of the request that is run on the main thread */
319 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800320 // The subscriber id that this request applies to. Defaults to
321 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
322 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 // In cases where subId is unavailable, the caller needs to specify the phone.
325 public Phone phone;
326
vagdevie435a3e2018-08-15 16:01:53 -0700327 public WorkSource workSource;
328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 public MainThreadRequest(Object argument) {
330 this.argument = argument;
331 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
334 this.argument = argument;
335 if (phone != null) {
336 this.phone = phone;
337 }
338 this.workSource = workSource;
339 }
340
vagdevie435a3e2018-08-15 16:01:53 -0700341 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800342 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800343 if (subId != null) {
344 this.subId = subId;
345 }
vagdevie435a3e2018-08-15 16:01:53 -0700346 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 }
349
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800350 private static final class IncomingThirdPartyCallArgs {
351 public final ComponentName component;
352 public final String callId;
353 public final String callerDisplayName;
354
355 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
356 String callerDisplayName) {
357 this.component = component;
358 this.callId = callId;
359 this.callerDisplayName = callerDisplayName;
360 }
361 }
362
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 /**
364 * A handler that processes messages on the main thread in the phone process. Since many
365 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
366 * inbound binder threads to the main thread in the phone process. The Binder thread
367 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
368 * on, which will be notified when the operation completes and will contain the result of the
369 * request.
370 *
371 * <p>If a MainThreadRequest object is provided in the msg.obj field,
372 * note that request.result must be set to something non-null for the calling thread to
373 * unblock.
374 */
375 private final class MainThreadHandler extends Handler {
376 @Override
377 public void handleMessage(Message msg) {
378 MainThreadRequest request;
379 Message onCompleted;
380 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800381 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700382 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800383 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
385 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700386 case CMD_HANDLE_USSD_REQUEST: {
387 request = (MainThreadRequest) msg.obj;
388 final Phone phone = getPhoneFromRequest(request);
389 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
390 String ussdRequest = ussdObject.first;
391 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700392
Pengquan Meng0c05b502018-09-06 09:59:22 -0700393 if (!isUssdApiAllowed(request.subId)) {
394 // Carrier does not support use of this API, return failure.
395 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
396 UssdResponse response = new UssdResponse(ussdRequest, null);
397 Bundle returnData = new Bundle();
398 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
399 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700400
Pengquan Meng0c05b502018-09-06 09:59:22 -0700401 request.result = true;
402 notifyRequester(request);
403 return;
404 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700405
Pengquan Meng0c05b502018-09-06 09:59:22 -0700406 try {
407 request.result = phone != null
408 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
409 } catch (CallStateException cse) {
410 request.result = false;
411 }
412 // Wake up the requesting thread
413 notifyRequester(request);
414 break;
pkanwar32d516d2016-10-14 19:37:38 -0700415 }
416
Yorke Lee716f67e2015-06-17 15:39:16 -0700417 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700419 final Phone phone = getPhoneFromRequest(request);
420 request.result = phone != null ?
421 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
422 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700424 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800431 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 if (uiccCard == null) {
433 loge("iccTransmitApduLogicalChannel: No UICC");
434 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700435 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
438 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 iccArgument.channel, iccArgument.cla, iccArgument.command,
441 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 ar = (AsyncResult) msg.obj;
448 request = (MainThreadRequest) ar.userObj;
449 if (ar.exception == null && ar.result != null) {
450 request.result = ar.result;
451 } else {
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 if (ar.result == null) {
454 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800455 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800457 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 } else {
459 loge("iccTransmitApduLogicalChannel: Unknown exception");
460 }
461 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
466 request = (MainThreadRequest) msg.obj;
467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduBasicChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 break;
500
501 case CMD_EXCHANGE_SIM_IO:
502 request = (MainThreadRequest) msg.obj;
503 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 if (uiccCard == null) {
506 loge("iccExchangeSimIO: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
511 request);
512 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
513 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
514 iccArgument.data, onCompleted);
515 }
516 break;
517
518 case EVENT_EXCHANGE_SIM_IO_DONE:
519 ar = (AsyncResult) msg.obj;
520 request = (MainThreadRequest) ar.userObj;
521 if (ar.exception == null && ar.result != null) {
522 request.result = ar.result;
523 } else {
524 request.result = new IccIoResult(0x6f, 0, (byte[])null);
525 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 break;
528
Derek Tan4d5e5c12014-02-04 11:54:58 -0800529 case CMD_SEND_ENVELOPE:
530 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800531 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 if (uiccCard == null) {
533 loge("sendEnvelopeWithStatus: No UICC");
534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 } else {
537 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
538 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
542 case EVENT_SEND_ENVELOPE_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("sendEnvelopeWithStatus: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("sendEnvelopeWithStatus: CommandException: " +
553 ar.exception);
554 } else {
555 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700558 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800572 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
573 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
577 case EVENT_OPEN_CHANNEL_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 int[] result = (int[]) ar.result;
583 int channelId = result[0];
584 byte[] selectResponse = null;
585 if (result.length > 1) {
586 selectResponse = new byte[result.length - 1];
587 for (int i = 1; i < result.length; ++i) {
588 selectResponse[i - 1] = (byte) result[i];
589 }
590 }
591 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.result == null) {
595 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 if (ar.exception != null) {
598 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
599 }
600
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700602 if (ar.exception instanceof CommandException) {
603 CommandException.Error error =
604 ((CommandException) (ar.exception)).getCommandError();
605 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700607 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(
612 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700614 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
618 case CMD_CLOSE_CHANNEL:
619 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800620 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 if (uiccCard == null) {
622 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900623 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 } else {
626 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
627 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 break;
630
631 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800632 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
633 break;
634
635 case CMD_NV_READ_ITEM:
636 request = (MainThreadRequest) msg.obj;
637 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800638 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
639 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800640 break;
641
642 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 ar = (AsyncResult) msg.obj;
644 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800645 if (ar.exception == null && ar.result != null) {
646 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 request.result = "";
649 if (ar.result == null) {
650 loge("nvReadItem: Empty response");
651 } else if (ar.exception instanceof CommandException) {
652 loge("nvReadItem: CommandException: " +
653 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 }
657 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
Jake Hambye994d462014-02-03 13:10:13 -0800661 case CMD_NV_WRITE_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
664 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800665 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700666 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_ITEM_DONE:
670 handleNullReturnEvent(msg, "nvWriteItem");
671 break;
672
673 case CMD_NV_WRITE_CDMA_PRL:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800676 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_WRITE_CDMA_PRL_DONE:
680 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
681 break;
682
chen xu1cc0abe2018-10-26 17:39:23 -0700683 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800684 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700685 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800686 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
chen xu1cc0abe2018-10-26 17:39:23 -0700689 case EVENT_RESET_MODEM_CONFIG_DONE:
690 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
Jake Hamby7c27be32014-03-03 13:25:59 -0800693 case CMD_GET_PREFERRED_NETWORK_TYPE:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700696 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result; // Integer
704 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800705 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 if (ar.result == null) {
707 loge("getPreferredNetworkType: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("getPreferredNetworkType: CommandException: " +
710 ar.exception);
711 } else {
712 loge("getPreferredNetworkType: Unknown exception");
713 }
714 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700715 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case CMD_SET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
721 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700722 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
726 handleNullReturnEvent(msg, "setPreferredNetworkType");
727 break;
728
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000729 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
730 request = (MainThreadRequest)msg.obj;
731 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800732 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 break;
734
735 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
736 ar = (AsyncResult)msg.obj;
737 request = (MainThreadRequest)ar.userObj;
738 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700739 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 break;
741
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700799 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null) {
816 request.result = true;
817 } else {
818 request.result = false;
819 loge("setNetworkSelectionModeManual " + ar.exception);
820 }
821 notifyRequester(request);
822 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 break;
824
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 case CMD_GET_MODEM_ACTIVITY_INFO:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800828 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 break;
830
831 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null && ar.result != null) {
835 request.result = ar.result;
836 } else {
837 if (ar.result == null) {
838 loge("queryModemActivityInfo: Empty response");
839 } else if (ar.exception instanceof CommandException) {
840 loge("queryModemActivityInfo: CommandException: " +
841 ar.exception);
842 } else {
843 loge("queryModemActivityInfo: Unknown exception");
844 }
845 }
Amit Mahajand4766222016-01-28 15:28:28 -0800846 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
847 if (request.result == null) {
848 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
849 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700850 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800855 CarrierRestrictionRules argument =
856 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800858 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800867 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
868 if (ar.exception instanceof CommandException) {
869 loge("setAllowedCarriers: CommandException: " + ar.exception);
870 CommandException.Error error =
871 ((CommandException) (ar.exception)).getCommandError();
872 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
873 request.result =
874 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
875 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 } else {
877 loge("setAllowedCarriers: Unknown exception");
878 }
879 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case CMD_GET_ALLOWED_CARRIERS:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800886 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
889 case EVENT_GET_ALLOWED_CARRIERS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800895 request.result = new IllegalStateException(
896 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700906 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
Nathan Haroldb3014052017-01-25 15:57:32 -0800909 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
915 request.result = new IllegalArgumentException(
916 "Failed to retrieve Forbidden Plmns");
917 if (ar.result == null) {
918 loge("getForbiddenPlmns: Empty response");
919 } else {
920 loge("getForbiddenPlmns: Unknown exception");
921 }
922 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925
926 case CMD_GET_FORBIDDEN_PLMNS:
927 request = (MainThreadRequest) msg.obj;
928 uiccCard = getUiccCardFromRequest(request);
929 if (uiccCard == null) {
930 loge("getForbiddenPlmns() UiccCard is null");
931 request.result = new IllegalArgumentException(
932 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935 }
936 Integer appType = (Integer) request.argument;
937 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
938 if (uiccApp == null) {
939 loge("getForbiddenPlmns() no app with specified type -- "
940 + appType);
941 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 } else {
945 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
946 + " specified type -- " + appType);
947 }
948 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
949 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
950 onCompleted);
951 break;
952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000953 case CMD_SWITCH_SLOTS:
954 request = (MainThreadRequest) msg.obj;
955 int[] physicalSlots = (int[]) request.argument;
956 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
957 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
958 break;
959
960 case EVENT_SWITCH_SLOTS_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700964 notifyRequester(request);
965 break;
966 case CMD_GET_NETWORK_SELECTION_MODE:
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
969 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
970 break;
971
972 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 if (ar.exception != null) {
976 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
977 } else {
978 int mode = ((int[]) ar.result)[0];
979 if (mode == 0) {
980 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
981 } else {
982 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
983 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700985 notifyRequester(request);
986 break;
987 case CMD_GET_CDMA_ROAMING_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
990 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
991 break;
992 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
997 } else {
998 request.result = ((int[]) ar.result)[0];
999 }
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_ROAMING_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1005 int mode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
1013 break;
1014 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1017 int subscriptionMode = (int) request.argument;
1018 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1019 break;
1020 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1021 ar = (AsyncResult) msg.obj;
1022 request = (MainThreadRequest) ar.userObj;
1023 request.result = ar.exception == null;
1024 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001025 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001026 case CMD_GET_ALL_CELL_INFO:
1027 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001029 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 case EVENT_GET_ALL_CELL_INFO_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001034 // If a timeout occurs, the response will be null
1035 request.result = (ar.exception == null && ar.result != null)
1036 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 synchronized (request) {
1038 request.notifyAll();
1039 }
1040 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001041 case CMD_REQUEST_CELL_INFO_UPDATE:
1042 request = (MainThreadRequest) msg.obj;
1043 request.phone.requestCellInfoUpdate(request.workSource,
1044 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1045 break;
1046 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1047 ar = (AsyncResult) msg.obj;
1048 request = (MainThreadRequest) ar.userObj;
1049 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1050 try {
1051 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001052 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001053 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1054 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001057 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 } else {
1059 // use the result as returned
1060 cb.onCellInfo((List<CellInfo>) ar.result);
1061 }
1062 } catch (RemoteException re) {
1063 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1064 }
1065 break;
1066 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 request = (MainThreadRequest) msg.obj;
1068 WorkSource ws = (WorkSource) request.argument;
1069 Phone phone = getPhoneFromRequest(request);
1070 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1071 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 ar = (AsyncResult) msg.obj;
1074 request = (MainThreadRequest) ar.userObj;
1075 if (ar.exception == null) {
1076 request.result = ar.result;
1077 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001079 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1080 ? new CdmaCellLocation() : new GsmCellLocation();
1081 }
1082
1083 synchronized (request) {
1084 request.notifyAll();
1085 }
1086 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001087 case CMD_MODEM_REBOOT:
1088 request = (MainThreadRequest) msg.obj;
1089 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001090 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001091 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001092 case EVENT_CMD_MODEM_REBOOT_DONE:
1093 handleNullReturnEvent(msg, "rebootModem");
1094 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001095 case CMD_REQUEST_ENABLE_MODEM:
1096 request = (MainThreadRequest) msg.obj;
1097 boolean enable = (boolean) request.argument;
1098 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1099 PhoneConfigurationManager.getInstance()
1100 .enablePhone(request.phone, enable, onCompleted);
1101 break;
1102 case EVENT_ENABLE_MODEM_DONE:
1103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
1105 request.result = (ar.exception == null);
1106 notifyRequester(request);
1107 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 default:
1109 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1110 break;
1111 }
1112 }
Jake Hambye994d462014-02-03 13:10:13 -08001113
Pengquan Meng0c05b502018-09-06 09:59:22 -07001114 private void notifyRequester(MainThreadRequest request) {
1115 synchronized (request) {
1116 request.notifyAll();
1117 }
1118 }
1119
Jake Hambye994d462014-02-03 13:10:13 -08001120 private void handleNullReturnEvent(Message msg, String command) {
1121 AsyncResult ar = (AsyncResult) msg.obj;
1122 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null) {
1124 request.result = true;
1125 } else {
1126 request.result = false;
1127 if (ar.exception instanceof CommandException) {
1128 loge(command + ": CommandException: " + ar.exception);
1129 } else {
1130 loge(command + ": Unknown exception");
1131 }
1132 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001133 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
1142 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001143 return sendRequest(
1144 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001145 }
1146
1147 /**
1148 * Posts the specified command to be executed on the main thread,
1149 * waits for the request to complete, and returns the result.
1150 * @see #sendRequestAsync
1151 */
1152 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1153 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001154 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001155 }
1156
1157 /**
1158 * Posts the specified command to be executed on the main thread,
1159 * waits for the request to complete, and returns the result.
1160 * @see #sendRequestAsync
1161 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001162 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001163 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001164 }
1165
1166 /**
1167 * Posts the specified command to be executed on the main thread,
1168 * waits for the request to complete, and returns the result.
1169 * @see #sendRequestAsync
1170 */
Nathan Harold92bed182018-10-12 18:16:49 -07001171 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1172 return sendRequest(command, argument, subId, null, workSource);
1173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
1180 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1181 return sendRequest(
1182 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1183 }
1184
1185 /**
1186 * Posts the specified command to be executed on the main thread,
1187 * waits for the request to complete, and returns the result.
1188 * @see #sendRequestAsync
1189 */
1190 private Object sendRequest(
1191 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1193 throw new RuntimeException("This method will deadlock if called from the main thread.");
1194 }
1195
Nathan Harold92bed182018-10-12 18:16:49 -07001196 MainThreadRequest request = null;
1197 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1198 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1199 } else if (phone != null) {
1200 request = new MainThreadRequest(argument, phone, workSource);
1201 } else {
1202 request = new MainThreadRequest(argument, subId, workSource);
1203 }
1204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 Message msg = mMainThreadHandler.obtainMessage(command, request);
1206 msg.sendToTarget();
1207
1208 // Wait for the request to complete
1209 synchronized (request) {
1210 while (request.result == null) {
1211 try {
1212 request.wait();
1213 } catch (InterruptedException e) {
1214 // Do nothing, go back and wait until the request is complete
1215 }
1216 }
1217 }
1218 return request.result;
1219 }
1220
1221 /**
1222 * Asynchronous ("fire and forget") version of sendRequest():
1223 * Posts the specified command to be executed on the main thread, and
1224 * returns immediately.
1225 * @see #sendRequest
1226 */
1227 private void sendRequestAsync(int command) {
1228 mMainThreadHandler.sendEmptyMessage(command);
1229 }
1230
1231 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001232 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001233 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001234 */
1235 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001236 sendRequestAsync(command, argument, null, null);
1237 }
1238
1239 /**
1240 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1241 * @see {@link #sendRequest(int,Object)}
1242 */
1243 private void sendRequestAsync(
1244 int command, Object argument, Phone phone, WorkSource workSource) {
1245 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 Message msg = mMainThreadHandler.obtainMessage(command, request);
1247 msg.sendToTarget();
1248 }
1249
1250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 * Initialize the singleton PhoneInterfaceManager instance.
1252 * This is only done once, at startup, from PhoneApp.onCreate().
1253 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001254 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 synchronized (PhoneInterfaceManager.class) {
1256 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001257 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 } else {
1259 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1260 }
1261 return sInstance;
1262 }
1263 }
1264
1265 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001266 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001269 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1271 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001272 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001273 mTelephonySharedPreferences =
1274 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001275 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001276 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 publish();
1279 }
1280
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001281 private Phone getDefaultPhone() {
1282 Phone thePhone = getPhone(getDefaultSubscription());
1283 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1284 }
1285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 private void publish() {
1287 if (DBG) log("publish: " + this);
1288
1289 ServiceManager.addService("phone", this);
1290 }
1291
Stuart Scott584921c2015-01-15 17:10:34 -08001292 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001293 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001294 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001295 }
1296
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001297 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1298 Phone phone = getPhoneFromRequest(request);
1299 return phone == null ? null :
1300 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1301 }
1302
Wink Saville36469e72014-06-11 15:17:00 -07001303 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001304 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001305 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307
1308 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 if (DBG) log("dial: " + number);
1314 // No permission check needed here: This is just a wrapper around the
1315 // ACTION_DIAL intent, which is available to any app since it puts up
1316 // the UI before it does anything.
1317
Malcolm Chend965c8b2018-02-28 15:00:40 -08001318 final long identity = Binder.clearCallingIdentity();
1319 try {
1320 String url = createTelUrl(number);
1321 if (url == null) {
1322 return;
1323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 // PENDING: should we just silently fail if phone is offhook or ringing?
1326 PhoneConstants.State state = mCM.getState(subId);
1327 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1328 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1329 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1330 mApp.startActivity(intent);
1331 }
1332 } finally {
1333 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335 }
1336
1337 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 if (DBG) log("call: " + number);
1343
1344 // This is just a wrapper around the ACTION_CALL intent, but we still
1345 // need to do a permission check since we're calling startActivity()
1346 // from the context of the phone app.
1347 enforceCallPermission();
1348
1349 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1350 != AppOpsManager.MODE_ALLOWED) {
1351 return;
1352 }
1353
Malcolm Chend965c8b2018-02-28 15:00:40 -08001354 final long identity = Binder.clearCallingIdentity();
1355 try {
1356 String url = createTelUrl(number);
1357 if (url == null) {
1358 return;
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
Malcolm Chend965c8b2018-02-28 15:00:40 -08001361 boolean isValid = false;
1362 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1363 if (slist != null) {
1364 for (SubscriptionInfo subInfoRecord : slist) {
1365 if (subInfoRecord.getSubscriptionId() == subId) {
1366 isValid = true;
1367 break;
1368 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001369 }
Wink Saville08874612014-08-31 19:19:58 -07001370 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001371 if (!isValid) {
1372 return;
1373 }
Wink Saville08874612014-08-31 19:19:58 -07001374
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1376 intent.putExtra(SUBSCRIPTION_KEY, subId);
1377 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1378 mApp.startActivity(intent);
1379 } finally {
1380 Binder.restoreCallingIdentity(identity);
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 }
1383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001385 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
Wink Savilleb564aae2014-10-23 10:18:09 -07001388 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001390 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1391 }
1392
1393 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001395 }
1396
Wink Savilleb564aae2014-10-23 10:18:09 -07001397 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001399 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1400 }
1401
1402 /** {@hide} */
1403 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001409
1410 final long identity = Binder.clearCallingIdentity();
1411 try {
1412 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1413 checkSimPin.start();
1414 return checkSimPin.unlockSim(null, pin);
1415 } finally {
1416 Binder.restoreCallingIdentity(identity);
1417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 }
1419
Wink Saville9de0f752013-10-22 19:04:03 -07001420 /** {@hide} */
1421 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001422 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001423 }
1424
Wink Savilleb564aae2014-10-23 10:18:09 -07001425 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001427
1428 final long identity = Binder.clearCallingIdentity();
1429 try {
1430 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1431 checkSimPuk.start();
1432 return checkSimPuk.unlockSim(puk, pin);
1433 } finally {
1434 Binder.restoreCallingIdentity(identity);
1435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 }
1437
1438 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001439 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 * a synchronous one.
1441 */
1442 private static class UnlockSim extends Thread {
1443
1444 private final IccCard mSimCard;
1445
1446 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001447 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1448 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449
1450 // For replies from SimCard interface
1451 private Handler mHandler;
1452
1453 // For async handler to identify request type
1454 private static final int SUPPLY_PIN_COMPLETE = 100;
1455
1456 public UnlockSim(IccCard simCard) {
1457 mSimCard = simCard;
1458 }
1459
1460 @Override
1461 public void run() {
1462 Looper.prepare();
1463 synchronized (UnlockSim.this) {
1464 mHandler = new Handler() {
1465 @Override
1466 public void handleMessage(Message msg) {
1467 AsyncResult ar = (AsyncResult) msg.obj;
1468 switch (msg.what) {
1469 case SUPPLY_PIN_COMPLETE:
1470 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1471 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001472 mRetryCount = msg.arg1;
1473 if (ar.exception != null) {
1474 if (ar.exception instanceof CommandException &&
1475 ((CommandException)(ar.exception)).getCommandError()
1476 == CommandException.Error.PASSWORD_INCORRECT) {
1477 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1478 } else {
1479 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1480 }
1481 } else {
1482 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 mDone = true;
1485 UnlockSim.this.notifyAll();
1486 }
1487 break;
1488 }
1489 }
1490 };
1491 UnlockSim.this.notifyAll();
1492 }
1493 Looper.loop();
1494 }
1495
1496 /*
1497 * Use PIN or PUK to unlock SIM card
1498 *
1499 * If PUK is null, unlock SIM card with PIN
1500 *
1501 * If PUK is not null, unlock SIM card with PUK and set PIN code
1502 */
Wink Saville9de0f752013-10-22 19:04:03 -07001503 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504
1505 while (mHandler == null) {
1506 try {
1507 wait();
1508 } catch (InterruptedException e) {
1509 Thread.currentThread().interrupt();
1510 }
1511 }
1512 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1513
1514 if (puk == null) {
1515 mSimCard.supplyPin(pin, callback);
1516 } else {
1517 mSimCard.supplyPuk(puk, pin, callback);
1518 }
1519
1520 while (!mDone) {
1521 try {
1522 Log.d(LOG_TAG, "wait for done");
1523 wait();
1524 } catch (InterruptedException e) {
1525 // Restore the interrupted status
1526 Thread.currentThread().interrupt();
1527 }
1528 }
1529 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001530 int[] resultArray = new int[2];
1531 resultArray[0] = mResult;
1532 resultArray[1] = mRetryCount;
1533 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535 }
1536
1537 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001539
1540 }
1541
Wink Savilleb564aae2014-10-23 10:18:09 -07001542 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 // No permission check needed here: this call is harmless, and it's
1544 // needed for the ServiceState.requestStateUpdate() call (which is
1545 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final Phone phone = getPhone(subId);
1549 if (phone != null) {
1550 phone.updateServiceLocation();
1551 }
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001557 @Override
1558 public boolean isRadioOn(String callingPackage) {
1559 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001560 }
1561
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001562 @Override
1563 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001565 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 return false;
1567 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568
1569 final long identity = Binder.clearCallingIdentity();
1570 try {
1571 return isRadioOnForSubscriber(subId);
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
1574 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001575 }
1576
1577 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1583 } else {
1584 return false;
1585 }
1586 } finally {
1587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
1591 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
Wink Saville36469e72014-06-11 15:17:00 -07001594
Wink Savilleb564aae2014-10-23 10:18:09 -07001595 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001597
1598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
1602 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1603 }
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607 }
1608
1609 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
Wink Savilleb564aae2014-10-23 10:18:09 -07001613 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001614 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001615
1616 final long identity = Binder.clearCallingIdentity();
1617 try {
1618 final Phone phone = getPhone(subId);
1619 if (phone == null) {
1620 return false;
1621 }
1622 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1623 toggleRadioOnOffForSubscriber(subId);
1624 }
1625 return true;
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
Wink Saville36469e72014-06-11 15:17:00 -07001630
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 public boolean needMobileRadioShutdown() {
1632 /*
1633 * If any of the Radios are available, it will need to be
1634 * shutdown. So return true if any Radio is available.
1635 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1639 Phone phone = PhoneFactory.getPhone(i);
1640 if (phone != null && phone.isRadioAvailable()) return true;
1641 }
1642 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1643 return false;
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
1648
Malcolm Chend965c8b2018-02-28 15:00:40 -08001649 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001651 enforceModifyPermission();
1652
1653 final long identity = Binder.clearCallingIdentity();
1654 try {
1655 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1656 logv("Shutting down Phone " + i);
1657 shutdownRadioUsingPhoneId(i);
1658 }
1659 } finally {
1660 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001661 }
1662 }
1663
1664 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001665 Phone phone = PhoneFactory.getPhone(phoneId);
1666 if (phone != null && phone.isRadioAvailable()) {
1667 phone.shutdownRadio();
1668 }
1669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001672 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001673
1674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1677 if (defaultPhone != null) {
1678 defaultPhone.setRadioPower(turnOn);
1679 return true;
1680 } else {
1681 loge("There's no default phone.");
1682 return false;
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001686 }
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001691
1692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.setRadioPower(turnOn);
1697 return true;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public boolean enableDataConnectivity() {
1709 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 int subId = mSubscriptionController.getDefaultDataSubId();
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001716 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Wink Saville36469e72014-06-11 15:17:00 -07001726 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public boolean disableDataConnectivity() {
1729 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001736 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737 return true;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001747 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 final Phone phone = getPhone(subId);
1751 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001752 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753 } else {
1754 return false;
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 }
1760
1761 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
pkanwarae03a6b2016-11-06 20:37:09 -08001765 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001766 enforceCallPermission();
1767
1768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1771 return;
1772 }
1773 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1774 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
1777 }
pkanwar32d516d2016-10-14 19:37:38 -07001778 };
1779
Wink Savilleb564aae2014-10-23 10:18:09 -07001780 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001782
1783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1786 return false;
1787 }
1788 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001795 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001796 }
1797
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001798 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001799 final long identity = Binder.clearCallingIdentity();
1800 try {
1801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1803 PhoneConstantConversions.convertCallState(phone.getState());
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
1806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1814 if (phone != null) {
1815 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1816 } else {
1817 return PhoneConstantConversions.convertDataState(
1818 PhoneConstants.DataState.DISCONNECTED);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1830 if (phone != null) {
1831 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1832 } else {
1833 return TelephonyManager.DATA_ACTIVITY_NONE;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001841 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001842 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001844 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1845 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001846 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001849 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 if (DBG_LOC) log("getCellLocation: is active user");
1853 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001854 int subId = mSubscriptionController.getDefaultDataSubId();
1855 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1856 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001857 return data;
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
1860 }
Svetoslav64fad262015-04-14 14:35:21 -07001861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 public String getNetworkCountryIsoForPhone(int phoneId) {
1865 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1866 // registered cell info, so return a NULL country instead.
1867 final long identity = Binder.clearCallingIdentity();
1868 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001869 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1870 // Get default phone in this case.
1871 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1872 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Nathan Harold31d7ff32018-10-15 20:20:30 -07001938 /**
1939 * Returns the target SDK version number for a given package name.
1940 *
1941 * @return target SDK if the package is found or INT_MAX.
1942 */
1943 private int getTargetSdk(String packageName) {
1944 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001945 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1946 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001947 if (ai != null) return ai.targetSdkVersion;
1948 } catch (PackageManager.NameNotFoundException unexpected) {
1949 }
1950 return Integer.MAX_VALUE;
1951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 @Override
1954 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001955 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1956 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001957 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1958 throw new SecurityException(
1959 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1960 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1963 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1964 return null;
1965 }
Svetoslav64fad262015-04-14 14:35:21 -07001966
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001967 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
Nathan Haroldf180aac2018-06-01 18:43:55 -07001969 List<CellInfo> info = getAllCellInfo(callingPackage);
1970 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971
Nathan Haroldf180aac2018-06-01 18:43:55 -07001972 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1973 for (CellInfo ci : info) {
1974 if (ci instanceof CellInfoGsm) {
1975 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1976 } else if (ci instanceof CellInfoWcdma) {
1977 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001980 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001983 private List<CellInfo> getCachedCellInfo() {
1984 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1985 for (Phone phone : PhoneFactory.getPhones()) {
1986 List<CellInfo> info = phone.getAllCellInfo();
1987 if (info != null) cellInfos.addAll(info);
1988 }
1989 return cellInfos;
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991
1992 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001993 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001994 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001995 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001996 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001997 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001998 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002001 final int targetSdk = getTargetSdk(callingPackage);
2002 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2003 return getCachedCellInfo();
2004 }
2005
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002006 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002007 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002008 final long identity = Binder.clearCallingIdentity();
2009 try {
2010 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2011 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002012 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002013 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002014 if (info != null) cellInfos.addAll(info);
2015 }
2016 return cellInfos;
2017 } finally {
2018 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 }
2020 }
2021
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002022 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002023 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2024 requestCellInfoUpdateInternal(
2025 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2026 }
2027
2028 @Override
2029 public void requestCellInfoUpdateWithWorkSource(
2030 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2031 enforceModifyPermission();
2032 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2033 }
2034
2035 private void requestCellInfoUpdateInternal(
2036 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002037 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002039 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2040 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002041 return;
2042 }
2043
2044 final Phone phone = getPhone(subId);
2045 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2046
2047 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2048 }
2049
2050 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002052 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002057 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 }
2062
Shishir Agrawala9f32182016-04-12 12:00:16 -07002063 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002064 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 Phone phone = PhoneFactory.getPhone(slotIndex);
2066 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002067 return null;
2068 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002069 int subId = phone.getSubId();
2070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2071 mApp, subId, callingPackage, "getImeiForSlot")) {
2072 return null;
2073 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002074
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 return phone.getImei();
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002081 }
2082
2083 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002084 public String getTypeAllocationCodeForSlot(int slotIndex) {
2085 Phone phone = PhoneFactory.getPhone(slotIndex);
2086 String tac = null;
2087 if (phone != null) {
2088 String imei = phone.getImei();
2089 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2090 }
2091 return tac;
2092 }
2093
2094 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002095 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002096 Phone phone = PhoneFactory.getPhone(slotIndex);
2097 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002098 return null;
2099 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002100
Jeff Davidson913390f2018-02-23 17:11:49 -08002101 int subId = phone.getSubId();
2102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2103 mApp, subId, callingPackage, "getMeidForSlot")) {
2104 return null;
2105 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 return phone.getMeid();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
Jack Yu2af8d712017-03-15 17:14:14 -07002113 }
2114
2115 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002116 public String getManufacturerCodeForSlot(int slotIndex) {
2117 Phone phone = PhoneFactory.getPhone(slotIndex);
2118 String manufacturerCode = null;
2119 if (phone != null) {
2120 String meid = phone.getMeid();
2121 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2122 }
2123 return manufacturerCode;
2124 }
2125
2126 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002127 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 Phone phone = PhoneFactory.getPhone(slotIndex);
2129 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002130 return null;
2131 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002132 int subId = phone.getSubId();
2133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2134 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2135 return null;
2136 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002137
2138 final long identity = Binder.clearCallingIdentity();
2139 try {
2140 return phone.getDeviceSvn();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 }
2145
fionaxu43304da2017-11-27 22:51:16 -08002146 @Override
2147 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
fionaxu43304da2017-11-27 22:51:16 -08002155 }
2156
2157 @Override
2158 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
fionaxu43304da2017-11-27 22:51:16 -08002166 }
2167
calvinpaneed9ae82018-11-01 19:43:06 +08002168 @Override
chen xuc93cc282018-11-04 17:17:00 -08002169 public int getSubscriptionPreciseCarrierId(int subId) {
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = getPhone(subId);
2173 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2174 : phone.getPreciseCarrierId();
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
2177 }
2178 }
2179
2180 @Override
2181 public String getSubscriptionPreciseCarrierName(int subId) {
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 final Phone phone = getPhone(subId);
2185 return phone == null ? null : phone.getPreciseCarrierName();
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
2188 }
2189 }
2190
chen xu02581692018-11-11 19:03:44 -08002191 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002192 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2193 if (!isSubscriptionMccMnc) {
2194 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2195 }
chen xu02581692018-11-11 19:03:44 -08002196 final Phone phone = PhoneFactory.getPhone(slotIndex);
2197 if (phone == null) {
2198 return TelephonyManager.UNKNOWN_CARRIER_ID;
2199 }
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
2206 }
2207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 //
2209 // Internal helper methods.
2210 //
2211
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2214 *
2215 * @throws SecurityException if the caller does not have the required permission
2216 */
2217 private void enforceModifyPermission() {
2218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2219 }
2220
2221 /**
2222 * Make sure the caller has the CALL_PHONE permission.
2223 *
2224 * @throws SecurityException if the caller does not have the required permission
2225 */
2226 private void enforceCallPermission() {
2227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2228 }
2229
Stuart Scott8eef64f2015-04-08 15:13:54 -07002230 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002232 "ConnectivityService");
2233 }
2234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 private String createTelUrl(String number) {
2236 if (TextUtils.isEmpty(number)) {
2237 return null;
2238 }
2239
Jake Hambye994d462014-02-03 13:10:13 -08002240 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Ihab Awadf9e92732013-12-05 18:02:52 -08002243 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2245 }
2246
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002247 private static void logv(String msg) {
2248 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2249 }
2250
Ihab Awadf9e92732013-12-05 18:02:52 -08002251 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2253 }
2254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002255 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002257 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002261 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002262 final long identity = Binder.clearCallingIdentity();
2263 try {
2264 final Phone phone = PhoneFactory.getPhone(slotIndex);
2265 if (phone == null) {
2266 return PhoneConstants.PHONE_TYPE_NONE;
2267 } else {
2268 return phone.getPhoneType();
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
2276 * Returns the CDMA ERI icon index to display
2277 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 @Override
2279 public int getCdmaEriIconIndex(String callingPackage) {
2280 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002286 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 return -1;
2288 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 if (phone != null) {
2294 return phone.getCdmaEriIconIndex();
2295 } else {
2296 return -1;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * Returns the CDMA ERI icon mode,
2305 * 0 - ON
2306 * 1 - FLASHING
2307 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 @Override
2309 public int getCdmaEriIconMode(String callingPackage) {
2310 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 return -1;
2318 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002319
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 final Phone phone = getPhone(subId);
2323 if (phone != null) {
2324 return phone.getCdmaEriIconMode();
2325 } else {
2326 return -1;
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
2333 /**
2334 * Returns the CDMA ERI text,
2335 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 @Override
2337 public String getCdmaEriText(String callingPackage) {
2338 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return null;
2346 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 return phone.getCdmaEriText();
2353 } else {
2354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
2361 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002362 * Returns the CDMA MDN.
2363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2367 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002373 return phone.getLine1Number();
2374 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002375 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002376 return null;
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002380 }
2381 }
2382
2383 /**
2384 * Returns the CDMA MIN.
2385 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002387 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2389 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002390
2391 final long identity = Binder.clearCallingIdentity();
2392 try {
2393 final Phone phone = getPhone(subId);
2394 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2395 return phone.getCdmaMin();
2396 } else {
2397 return null;
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002401 }
2402 }
2403
Hall Liud892bec2018-11-30 14:51:45 -08002404 @Override
2405 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2406 INumberVerificationCallback callback, String callingPackage) {
2407 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2408 != PERMISSION_GRANTED) {
2409 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2410 }
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2412
2413 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2414 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2415 throw new SecurityException("Calling package must be configured in the device config");
2416 }
2417
2418 if (range == null) {
2419 throw new NullPointerException("Range must be non-null");
2420 }
2421
2422 timeoutMillis = Math.min(timeoutMillis,
2423 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2424
2425 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2426 }
2427
Junda Liuca05d5d2014-08-14 22:36:34 -07002428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 * Returns true if CDMA provisioning needs to run.
2430 */
2431 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432 final long identity = Binder.clearCallingIdentity();
2433 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002434 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002435 } finally {
2436 Binder.restoreCallingIdentity(identity);
2437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
2440 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002441 * Sets the voice mail number of a given subId.
2442 */
2443 @Override
2444 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2450 new Pair<String, String>(alphaTag, number), new Integer(subId));
2451 return success;
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
2454 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002455 }
2456
Ta-wei Yen87c49842016-05-13 21:19:52 -07002457 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002458 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002460 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002461 if (!TextUtils.equals(callingPackage, systemDialer)) {
2462 throw new SecurityException("caller must be system dialer");
2463 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2468 if (phoneAccountHandle == null) {
2469 return null;
2470 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002471 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472 } finally {
2473 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002474 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002475 }
2476
2477 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002478 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002481 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002482 return null;
2483 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002484
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002485 final long identity = Binder.clearCallingIdentity();
2486 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002487 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002491 }
2492
2493 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002494 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2495 VisualVoicemailSmsFilterSettings settings) {
2496 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002501 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002505 }
2506
2507 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002508 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002514 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002515 } finally {
2516 Binder.restoreCallingIdentity(identity);
2517 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002518 }
2519
2520 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002521 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2522 String callingPackage, int subId) {
2523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002524
2525 final long identity = Binder.clearCallingIdentity();
2526 try {
2527 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002528 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002532 }
2533
2534 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002535 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002536 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002541 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002545 }
2546
2547 @Override
2548 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2549 String number, int port, String text, PendingIntent sentIntent) {
2550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002551 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002552 enforceSendSmsPermission();
2553 // Make the calls as the phone process.
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2557 if (port == 0) {
2558 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2559 sentIntent, null, false);
2560 } else {
2561 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2562 smsManager.sendDataMessageWithSelfPermissions(number, null,
2563 (short) port, data, sentIntent, null);
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002568 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002569 /**
fionaxu0152e512016-11-14 13:36:14 -08002570 * Sets the voice activation state of a given subId.
2571 */
2572 @Override
2573 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2575 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setVoiceActivationState(activationState);
2582 } else {
2583 loge("setVoiceActivationState fails with invalid subId: " + subId);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002587 }
2588 }
2589
2590 /**
2591 * Sets the data activation state of a given subId.
2592 */
2593 @Override
2594 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2596 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 phone.setDataActivationState(activationState);
2603 } else {
2604 loge("setVoiceActivationState fails with invalid subId: " + subId);
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002608 }
2609 }
2610
2611 /**
2612 * Returns the voice activation state of a given subId.
2613 */
2614 @Override
2615 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002616 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617
fionaxu0152e512016-11-14 13:36:14 -08002618 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 if (phone != null) {
2622 return phone.getVoiceActivationState();
2623 } else {
2624 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
2632 * Returns the data activation state of a given subId.
2633 */
2634 @Override
2635 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002636 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637
fionaxu0152e512016-11-14 13:36:14 -08002638 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 if (phone != null) {
2642 return phone.getDataActivationState();
2643 } else {
2644 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002648 }
2649 }
2650
2651 /**
Wink Saville36469e72014-06-11 15:17:00 -07002652 * Returns the unread count of voicemails for a subId
2653 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002655 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2657 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2658 return 0;
2659 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 if (phone != null) {
2664 return phone.getVoiceMessageCount();
2665 } else {
2666 return 0;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
2673 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002674 * returns true, if the device is in a state where both voice and data
2675 * are supported simultaneously. This can change based on location or network condition.
2676 */
2677 @Override
2678 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002686 }
2687
2688 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002689 * Send the dialer code if called from the current default dialer or the caller has
2690 * carrier privilege.
2691 * @param inputCode The dialer code to send
2692 */
2693 @Override
2694 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002695 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002697 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2698 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002699 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2701 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002702 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002706 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
fionaxu235cc5e2017-03-06 22:25:57 -08002710 }
2711
2712 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002713 * Returns the data network type.
2714 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 *
2716 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2717 */
2718 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002719 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(getDefaultSubscription());
2723 if (phone != null) {
2724 return phone.getServiceState().getDataNetworkType();
2725 } else {
2726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002730 }
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
Pengquan Meng0c05b502018-09-06 09:59:22 -07002733 @Override
2734 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002735 if (!isActiveSubscription(subId)) {
2736 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2737 }
2738
Pengquan Meng0c05b502018-09-06 09:59:22 -07002739 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2740 }
2741
Brad Ebinger4c460712018-10-01 10:40:55 -07002742 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002743 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2744 throws RemoteException {
2745 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002746 final long token = Binder.clearCallingIdentity();
2747 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002749 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002750 .addRegistrationCallbackForSubscription(c, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(token);
2753 }
2754 }
2755
2756 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002757 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2758 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2761 }
2762 Binder.withCleanCallingIdentity(() -> {
2763 try {
2764 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002766 .removeRegistrationCallbackForSubscription(c, subId);
2767 } catch (IllegalArgumentException e) {
2768 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2769 + "is inactive, ignoring unregister.");
2770 // If the subscription is no longer active, just return, since the callback
2771 // will already have been removed internally.
2772 }
2773 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002774 }
2775
2776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002777 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2778 throws RemoteException {
2779 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002780 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2781 final long token = Binder.clearCallingIdentity();
2782 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002783 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 .addCapabilitiesCallbackForSubscription(c, subId);
2785 } finally {
2786 Binder.restoreCallingIdentity(token);
2787 }
2788 }
2789
2790 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002791 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2792 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002793
2794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2796 }
2797 Binder.withCleanCallingIdentity(() -> {
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002800 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002801 .removeCapabilitiesCallbackForSubscription(c, subId);
2802 } catch (IllegalArgumentException e) {
2803 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2804 + "is inactive, ignoring unregister.");
2805 // If the subscription is no longer active, just return, since the callback
2806 // will already have been removed internally.
2807 }
2808 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002809 }
2810
2811 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002812 public boolean isCapable(int subId, int capability, int regTech) {
2813 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2815 final long token = Binder.clearCallingIdentity();
2816 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002817 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002818 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2819 } catch (ImsException e) {
2820 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2821 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002822 } catch (IllegalArgumentException e) {
2823 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2824 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002831 public boolean isAvailable(int subId, int capability, int regTech) {
2832 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002833 final long token = Binder.clearCallingIdentity();
2834 try {
2835 Phone phone = getPhone(subId);
2836 if (phone == null) return false;
2837 return phone.isImsCapabilityAvailable(capability, regTech);
2838 } finally {
2839 Binder.restoreCallingIdentity(token);
2840 }
2841 }
2842
2843 @Override
2844 public boolean isAdvancedCallingSettingEnabled(int subId) {
2845 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2847 final long token = Binder.clearCallingIdentity();
2848 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002849 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002850 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2851 } finally {
2852 Binder.restoreCallingIdentity(token);
2853 }
2854 }
2855
2856 @Override
2857 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2859 "setAdvancedCallingSetting");
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002863 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public boolean isVtSettingEnabled(int subId) {
2872 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002876 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002877 getSlotIndexOrException(subId)).isVtEnabledByUser();
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
2881 }
2882
2883 @Override
2884 public void setVtSetting(int subId, boolean isEnabled) {
2885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2886 "setVtSetting");
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
2894 }
2895
2896 @Override
2897 public boolean isVoWiFiSettingEnabled(int subId) {
2898 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002902 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002903 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2912 "setVoWiFiSetting");
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002916 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2924 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2925 final long identity = Binder.clearCallingIdentity();
2926 try {
2927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
2933 }
2934
2935 @Override
2936 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2938 "setVoWiFiRoamingSetting");
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002942 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002943 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 }
2948
2949 @Override
2950 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2952 "setVoWiFiNonPersistent");
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002956 boolean isRoaming = TelephonyManager.from(
2957 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002958 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002959 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 @Override
2966 public int getVoWiFiModeSetting(int subId) {
2967 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002971 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 @Override
2979 public void setVoWiFiModeSetting(int subId, int mode) {
2980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2981 "setVoWiFiModeSetting");
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002985 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 @Override
2993 public int getVoWiFiRoamingModeSetting(int subId) {
2994 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002998 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
3006 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3008 "setVoWiFiRoamingModeSetting");
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003012 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 }
3018
3019 @Override
3020 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3022 "setRttCapabilityEnabled");
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003026 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003027 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
3034 public boolean isTtyOverVolteEnabled(int subId) {
3035 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003039 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003046 @Override
3047 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3048 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003053 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
3060 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3061 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3062 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003063 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3064 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3065 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003066 try {
3067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003068 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003069 .removeProvisioningCallbackForSubscription(callback, subId);
3070 } catch (IllegalArgumentException e) {
3071 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3072 + "is inactive, ignoring unregister.");
3073 // If the subscription is no longer active, just return, since the callback will already
3074 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003081 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3082 boolean isProvisioned) {
3083 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3084 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3085 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3086 }
3087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3088 "setProvisioningStatusForCapability");
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3092 Phone phone = getPhone(subId);
3093 if (phone == null) {
3094 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3095 + subId);
3096 return;
3097 }
3098 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3099 return;
3100 }
3101
3102 // this capability requires provisioning, route to the correct API.
3103 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3104 switch (capability) {
3105 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3106 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3107 ims.setVolteProvisioned(isProvisioned);
3108 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3109 ims.setWfcProvisioned(isProvisioned);
3110 }
3111 break;
3112 }
3113 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3114 // There is currently no difference in VT provisioning type.
3115 ims.setVtProvisioned(isProvisioned);
3116 break;
3117 }
3118 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3119 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3120 // change the capability of the feature instead if needed.
3121 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3122 == isProvisioned) {
3123 // No change in provisioning.
3124 return;
3125 }
3126 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3127 try {
3128 ims.changeMmTelCapability(capability, tech, isProvisioned);
3129 } catch (ImsException e) {
3130 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3131 + ", Exception" + e.getMessage());
3132 }
3133 break;
3134 }
3135 default: {
3136 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3137 + capability + "', which does not require provisioning.");
3138 }
3139 }
3140
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
3144 }
3145
3146 @Override
3147 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3148 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3149 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3150 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3151 }
3152 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3156 Phone phone = getPhone(subId);
3157 if (phone == null) {
3158 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3159 + subId);
3160 // We will fail with "true" as the provisioning status because this is the default
3161 // if we do not require provisioning.
3162 return true;
3163 }
3164
3165 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3166 return true;
3167 }
3168
3169 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3170 switch (capability) {
3171 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3172 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3173 return ims.isVolteProvisionedOnDevice();
3174 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3175 return ims.isWfcProvisionedOnDevice();
3176 }
3177 // This should never happen, since we are checking tech above to make sure it
3178 // is either LTE or IWLAN.
3179 throw new IllegalArgumentException("Invalid radio technology for voice "
3180 + "capability.");
3181 }
3182 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3183 // There is currently no difference in VT provisioning type.
3184 return ims.isVtProvisionedOnDevice();
3185 }
3186 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3187 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3188 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3189 }
3190 default: {
3191 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3192 + capability + "', which does not require provisioning.");
3193 }
3194 }
3195
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
3200
3201 @Override
3202 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3203 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3204 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3205 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3206 }
3207 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3208 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3209 return (provisionedBits & capability) > 0;
3210 }
3211
3212 @Override
3213 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3214 boolean isProvisioned) {
3215 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3216 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3217 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3218 }
3219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3220 "setProvisioningStatusForCapability");
3221 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3222 // If the current provisioning status for capability already matches isProvisioned,
3223 // do nothing.
3224 if (((provisionedBits & capability) > 0) == isProvisioned) {
3225 return;
3226 }
3227 if (isProvisioned) {
3228 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3229 } else {
3230 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3231 }
3232 }
3233
3234 /**
3235 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3236 * technology. The bitfield should mirror the bitfield defined by
3237 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3238 */
3239 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3240 String key = getMmTelProvisioningKey(subId, tech);
3241 // Default is no capabilities are provisioned.
3242 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3243 }
3244
3245 /**
3246 * Sets the MmTel capability provisioning bitfield (defined by
3247 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3248 * technology specified.
3249 *
3250 * Note: This is a synchronous command and should not be called on UI thread.
3251 */
3252 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3253 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3254 String key = getMmTelProvisioningKey(subId, tech);
3255 editor.putInt(key, newField);
3256 editor.commit();
3257 }
3258
3259 private static String getMmTelProvisioningKey(int subId, int tech) {
3260 // resulting key is provision_ims_mmtel_{subId}_{tech}
3261 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3262 }
3263
3264 /**
3265 * Query CarrierConfig to see if the specified capability requires provisioning for the
3266 * carrier associated with the subscription id.
3267 */
3268 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3269 int capability) {
3270 CarrierConfigManager configManager = new CarrierConfigManager(context);
3271 PersistableBundle c = configManager.getConfigForSubId(subId);
3272 boolean requireUtProvisioning = c.getBoolean(
3273 // By default, this config is true (even if there is no SIM). We also check to make
3274 // sure the subscription needs provisioning here, so we do not need to check for
3275 // the no-SIM case, where we would normally shortcut this to false.
3276 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3277 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3278 false);
3279 boolean requireVoiceVtProvisioning = c.getBoolean(
3280 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3281
3282 // First check to make sure that the capability requires provisioning.
3283 switch (capability) {
3284 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3285 // intentional fallthrough
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3287 if (requireVoiceVtProvisioning) {
3288 // Voice and Video requires provisioning
3289 return true;
3290 }
3291 break;
3292 }
3293 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3294 if (requireUtProvisioning) {
3295 // UT requires provisioning
3296 return true;
3297 }
3298 break;
3299 }
3300 }
3301 return false;
3302 }
3303
3304 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003305 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003306 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3307 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3308 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003309 enforceReadPrivilegedPermission("getImsProvisioningInt");
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003313 int slotId = getSlotIndex(subId);
3314 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3315 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3316 + subId + "' for key:" + key);
3317 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3318 }
3319 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003320 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003321 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3322 + subId + "' for key:" + key);
3323 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
3327 }
3328
3329 @Override
3330 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003331 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3332 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3333 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003334 enforceReadPrivilegedPermission("getImsProvisioningString");
3335 final long identity = Binder.clearCallingIdentity();
3336 try {
3337 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003338 int slotId = getSlotIndex(subId);
3339 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3340 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3341 + subId + "' for key:" + key);
3342 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3343 }
3344 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003345 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003346 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3347 + subId + "' for key:" + key);
3348 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
3352 }
3353
3354 @Override
3355 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003356 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3357 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3358 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003364 int slotId = getSlotIndex(subId);
3365 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3366 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3367 + subId + "' for key:" + key);
3368 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3369 }
3370 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003371 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003372 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3373 + "' for key:" + key);
3374 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003375 } finally {
3376 Binder.restoreCallingIdentity(identity);
3377 }
3378 }
3379
3380 @Override
3381 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003382 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3383 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3384 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3386 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003390 int slotId = getSlotIndex(subId);
3391 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3392 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3393 + subId + "' for key:" + key);
3394 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3395 }
3396 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003397 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003398 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3399 + "' for key:" + key);
3400 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
3404 }
3405
Brad Ebinger4c460712018-10-01 10:40:55 -07003406 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3407 int slotId = SubscriptionManager.getSlotIndex(subId);
3408 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003409 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003410 }
3411 return slotId;
3412 }
3413
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 private int getSlotIndex(int subId) {
3415 int slotId = SubscriptionManager.getSlotIndex(subId);
3416 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3417 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3418 }
3419 return slotId;
3420 }
3421
Wink Saville36469e72014-06-11 15:17:00 -07003422 /**
3423 * Returns the network type for a subId
3424 */
3425 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003426 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003428 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003429 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3430 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003431
Malcolm Chend965c8b2018-02-28 15:00:40 -08003432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 final Phone phone = getPhone(subId);
3435 if (phone != null) {
3436 return phone.getServiceState().getDataNetworkType();
3437 } else {
3438 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3439 }
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 }
3444
3445 /**
3446 * Returns the data network type
3447 */
3448 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003449 public int getDataNetworkType(String callingPackage) {
3450 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003451 }
3452
3453 /**
3454 * Returns the data network type for a subId
3455 */
3456 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003457 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003459 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003460 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3461 }
3462
Malcolm Chend965c8b2018-02-28 15:00:40 -08003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 final Phone phone = getPhone(subId);
3466 if (phone != null) {
3467 return phone.getServiceState().getDataNetworkType();
3468 } else {
3469 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3470 }
3471 } finally {
3472 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003474 }
3475
3476 /**
Wink Saville36469e72014-06-11 15:17:00 -07003477 * Returns the Voice network type for a subId
3478 */
3479 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003480 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003482 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003483 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3484 }
3485
Malcolm Chend965c8b2018-02-28 15:00:40 -08003486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null) {
3490 return phone.getServiceState().getVoiceNetworkType();
3491 } else {
3492 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
3499 /**
3500 * @return true if a ICC card is present
3501 */
3502 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003503 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003504 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3505 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003506 }
3507
3508 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003509 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003510 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003511 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003512 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 final Phone phone = PhoneFactory.getPhone(slotIndex);
3516 if (phone != null) {
3517 return phone.getIccCard().hasIccCard();
3518 } else {
3519 return false;
3520 }
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003524 }
3525
3526 /**
3527 * Return if the current radio is LTE on CDMA. This
3528 * is a tri-state return value as for a period of time
3529 * the mode may be unknown.
3530 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003531 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003533 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 @Override
3536 public int getLteOnCdmaMode(String callingPackage) {
3537 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003538 }
3539
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003544 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3545 }
3546
Malcolm Chend965c8b2018-02-28 15:00:40 -08003547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone == null) {
3551 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3552 } else {
3553 return phone.getLteOnCdmaMode();
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 }
Wink Saville36469e72014-06-11 15:17:00 -07003558 }
3559
Wink Saville36469e72014-06-11 15:17:00 -07003560 /**
3561 * {@hide}
3562 * Returns Default subId, 0 in the case of single standby.
3563 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003564 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003565 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003566 }
3567
Shishir Agrawala9f32182016-04-12 12:00:16 -07003568 private int getSlotForDefaultSubscription() {
3569 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3570 }
3571
Wink Savilleb564aae2014-10-23 10:18:09 -07003572 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003573 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003575
Pengquan Meng466e2482018-09-21 15:54:48 -07003576 private boolean isActiveSubscription(int subId) {
3577 return mSubscriptionController.isActiveSubId(subId);
3578 }
3579
Ihab Awadf2177b72013-11-25 13:33:23 -08003580 /**
3581 * @see android.telephony.TelephonyManager.WifiCallingChoices
3582 */
3583 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003584 final long identity = Binder.clearCallingIdentity();
3585 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003586 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003587 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3588 getWhenToMakeWifiCallsDefaultPreference());
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003592 }
3593
3594 /**
3595 * @see android.telephony.TelephonyManager.WifiCallingChoices
3596 */
3597 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003601 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003602 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003606 }
3607
Sailesh Nepald1e68152013-12-12 19:08:02 -08003608 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003609 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003610 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003611 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003612
Shishir Agrawal566b7612013-10-28 14:41:00 -07003613 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003614 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3615 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3617 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003619
Malcolm Chend965c8b2018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 if (TextUtils.equals(ISDR_AID, aid)) {
3623 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003624 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3625 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 if (bestComponent == null
3627 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3628 loge("The calling package is not allowed to access ISD-R.");
3629 throw new SecurityException(
3630 "The calling package is not allowed to access ISD-R.");
3631 }
Derek Tan740e1672017-06-27 14:56:27 -07003632 }
Derek Tan740e1672017-06-27 14:56:27 -07003633
Malcolm Chend965c8b2018-02-28 15:00:40 -08003634 if (DBG) {
3635 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3636 }
3637 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3638 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3639 if (DBG) log("iccOpenLogicalChannel: " + response);
3640 return response;
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003644 }
3645
3646 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003647 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3649 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003650
Malcolm Chend965c8b2018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3654 if (channel < 0) {
3655 return false;
3656 }
3657 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3658 if (DBG) log("iccCloseLogicalChannel: " + success);
3659 return success;
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003663 }
3664
3665 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003666 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003667 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3669 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003670
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 if (DBG) {
3674 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3675 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3676 + p3 + " data=" + data);
3677 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003678
Malcolm Chend965c8b2018-02-28 15:00:40 -08003679 if (channel < 0) {
3680 return "";
3681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003682
Malcolm Chend965c8b2018-02-28 15:00:40 -08003683 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3684 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3685 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003686
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687 // Append the returned status code to the end of the response payload.
3688 String s = Integer.toHexString(
3689 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3690 if (response.payload != null) {
3691 s = IccUtils.bytesToHexString(response.payload) + s;
3692 }
3693 return s;
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697 }
Jake Hambye994d462014-02-03 13:10:13 -08003698
Evan Charltonc66da362014-05-16 14:06:40 -07003699 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003700 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3701 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3703 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003705
Malcolm Chend965c8b2018-02-28 15:00:40 -08003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3709 && TextUtils.equals(ISDR_AID, data)) {
3710 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003711 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3712 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 if (bestComponent == null
3714 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3715 loge("The calling package is not allowed to select ISD-R.");
3716 throw new SecurityException(
3717 "The calling package is not allowed to select ISD-R.");
3718 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003719 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003720
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 if (DBG) {
3722 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3723 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003725
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3727 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3728 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003729
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730 // Append the returned status code to the end of the response payload.
3731 String s = Integer.toHexString(
3732 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3733 if (response.payload != null) {
3734 s = IccUtils.bytesToHexString(response.payload) + s;
3735 }
3736 return s;
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003739 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003740 }
3741
3742 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003743 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003744 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3746 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003747
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 if (DBG) {
3751 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3752 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3753 }
3754
3755 IccIoResult response =
3756 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3757 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3758 subId);
3759
3760 if (DBG) {
3761 log("Exchange SIM_IO [R]" + response);
3762 }
3763
3764 byte[] result = null;
3765 int length = 2;
3766 if (response.payload != null) {
3767 length = 2 + response.payload.length;
3768 result = new byte[length];
3769 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3770 } else {
3771 result = new byte[length];
3772 }
3773
3774 result[length - 1] = (byte) response.sw2;
3775 result[length - 2] = (byte) response.sw1;
3776 return result;
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003779 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003780 }
3781
Nathan Haroldb3014052017-01-25 15:57:32 -08003782 /**
3783 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3784 * on a particular subscription
3785 */
sqianb6e41952018-03-12 14:54:01 -07003786 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3788 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3789 return null;
3790 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 if (appType != TelephonyManager.APPTYPE_USIM
3795 && appType != TelephonyManager.APPTYPE_SIM) {
3796 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3797 return null;
3798 }
3799 Object response = sendRequest(
3800 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3801 if (response instanceof String[]) {
3802 return (String[]) response;
3803 }
3804 // Response is an Exception of some kind,
3805 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003806 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003807 } finally {
3808 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003809 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003810 }
3811
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003812 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003813 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3815 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003816
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3820 if (response.payload == null) {
3821 return "";
3822 }
Evan Charltonc66da362014-05-16 14:06:40 -07003823
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 // Append the returned status code to the end of the response payload.
3825 String s = Integer.toHexString(
3826 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3827 s = IccUtils.bytesToHexString(response.payload) + s;
3828 return s;
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
3831 }
Evan Charltonc66da362014-05-16 14:06:40 -07003832 }
3833
Jake Hambye994d462014-02-03 13:10:13 -08003834 /**
3835 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3836 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3837 *
3838 * @param itemID the ID of the item to read
3839 * @return the NV item as a String, or null on error.
3840 */
3841 @Override
3842 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003843 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846
3847 final long identity = Binder.clearCallingIdentity();
3848 try {
3849 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003850 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3852 return value;
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
Jake Hambye994d462014-02-03 13:10:13 -08003856 }
3857
3858 /**
3859 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3860 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3861 *
3862 * @param itemID the ID of the item to read
3863 * @param itemValue the value to write, as a String
3864 * @return true on success; false on any failure
3865 */
3866 @Override
3867 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3870 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3875 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003876 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003877 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3878 return success;
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
Jake Hambye994d462014-02-03 13:10:13 -08003882 }
3883
3884 /**
3885 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3886 * Used for device configuration by some CDMA operators.
3887 *
3888 * @param preferredRoamingList byte array containing the new PRL
3889 * @return true on success; false on any failure
3890 */
3891 @Override
3892 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3894 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3899 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3900 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3901 return success;
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
Jake Hambye994d462014-02-03 13:10:13 -08003905 }
3906
3907 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003908 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003909 * Used for device configuration by some CDMA operators.
3910 *
chen xu1cc0abe2018-10-26 17:39:23 -07003911 * @param slotIndex - device slot.
3912 *
Jake Hambye994d462014-02-03 13:10:13 -08003913 * @return true on success; false on any failure
3914 */
3915 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003916 public boolean resetModemConfig(int slotIndex) {
3917 Phone phone = PhoneFactory.getPhone(slotIndex);
3918 if (phone != null) {
3919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3920 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003921
chen xu1cc0abe2018-10-26 17:39:23 -07003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3925 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3926 return success;
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003930 }
chen xu1cc0abe2018-10-26 17:39:23 -07003931 return false;
3932 }
3933
3934 /**
3935 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3936 *
3937 * @param slotIndex - device slot.
3938 *
3939 * @return true on success; false on any failure
3940 */
3941 @Override
3942 public boolean rebootModem(int slotIndex) {
3943 Phone phone = PhoneFactory.getPhone(slotIndex);
3944 if (phone != null) {
3945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3946 mApp, phone.getSubId(), "rebootModem");
3947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3951 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3952 return success;
3953 } finally {
3954 Binder.restoreCallingIdentity(identity);
3955 }
3956 }
3957 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003958 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003959
Svet Ganovb320e182015-04-16 12:30:10 -07003960 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003961 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003963 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003964 return new String[0];
3965 }
3966
Malcolm Chend965c8b2018-02-28 15:00:40 -08003967 final long identity = Binder.clearCallingIdentity();
3968 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003969 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
Wink Saville36469e72014-06-11 15:17:00 -07003973 }
3974
Brad Ebinger51f743a2017-01-23 13:50:20 -08003975 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003976 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3977 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003978 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003979 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003980 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 PhoneFactory.getImsResolver().enableIms(slotId);
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003988 }
3989
3990 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003991 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3992 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003993 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003994 public void disableIms(int slotId) {
3995 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003996
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 PhoneFactory.getImsResolver().disableIms(slotId);
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004003 }
4004
4005 /**
4006 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4007 * feature or {@link null} if the service is not available. If the feature is available, the
4008 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4009 */
4010 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004011 IImsServiceFeatureCallback callback) {
4012 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004020 }
4021
4022 /**
4023 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4024 * feature during emergency calling or {@link null} if the service is not available. If the
4025 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4026 * listener for feature updates.
4027 */
4028 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4029 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004037 }
4038
Brad Ebinger5f64b052017-12-14 14:26:15 -08004039 /**
4040 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4041 * specified.
4042 */
4043 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4044 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004045
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004052 }
4053
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004054 /**
4055 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4056 * specified.
4057 */
4058 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4059 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004067 }
4068
Brad Ebinger884c07b2018-02-15 16:17:40 -08004069 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004070 * Sets the ImsService Package Name that Telephony will bind to.
4071 *
4072 * @param slotId the slot ID that the ImsService should bind for.
4073 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4074 * ImsService is the device default ImsService.
4075 * @param packageName The package name of the application that contains the ImsService to bind
4076 * to.
4077 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4078 * @hide
4079 */
4080 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004081 int[] subIds = SubscriptionManager.getSubId(slotId);
4082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4083 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4084 "setImsService");
4085
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4089 isCarrierImsService, packageName);
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004093 }
4094
4095 /**
4096 * Return the ImsService configuration.
4097 *
4098 * @param slotId The slot that the ImsService is associated with.
4099 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4100 * the device default.
4101 * @return the package name of the ImsService configuration.
4102 */
4103 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004104 int[] subIds = SubscriptionManager.getSubId(slotId);
4105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4106 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4107 "getImsService");
4108
Malcolm Chend965c8b2018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4112 isCarrierImsService);
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004116 }
4117
Wink Saville36469e72014-06-11 15:17:00 -07004118 public void setImsRegistrationState(boolean registered) {
4119 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004123 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Wink Saville36469e72014-06-11 15:17:00 -07004127 }
4128
4129 /**
Stuart Scott54788802015-03-30 13:18:01 -07004130 * Set the network selection mode to automatic.
4131 *
4132 */
4133 @Override
4134 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004137
Pengquan Meng466e2482018-09-21 15:54:48 -07004138 if (!isActiveSubscription(subId)) {
4139 return;
4140 }
4141
Malcolm Chend965c8b2018-02-28 15:00:40 -08004142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4145 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Stuart Scott54788802015-03-30 13:18:01 -07004149 }
4150
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004151 /**
4152 * Ask the radio to connect to the input network and change selection mode to manual.
4153 *
4154 * @param subId the id of the subscription.
4155 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4156 * the operator to attach to.
4157 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4158 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4159 * normal network selection next time.
4160 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004161 */
4162 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004163 public boolean setNetworkSelectionModeManual(
4164 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4166 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004167
4168 if (!isActiveSubscription(subId)) {
4169 return false;
4170 }
4171
Malcolm Chend965c8b2018-02-28 15:00:40 -08004172 final long identity = Binder.clearCallingIdentity();
4173 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004174 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004175 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004176 if (DBG) {
4177 log("setNetworkSelectionModeManual: subId: " + subId
4178 + " operator: " + operatorInfo);
4179 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004180 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004184 }
4185
4186 /**
4187 * Scans for available networks.
4188 */
4189 @Override
4190 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4192 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004193
Pengquan Meng0c05b502018-09-06 09:59:22 -07004194 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004195 try {
4196 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004197 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004198 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004202 }
4203
4204 /**
yinxub1bed742017-04-17 11:45:04 -07004205 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004206 *
yinxub1bed742017-04-17 11:45:04 -07004207 * @param subId id of the subscription
4208 * @param request contains the radio access networks with bands/channels to scan
4209 * @param messenger callback messenger for scan results or errors
4210 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004211 * @return the id of the requested scan which can be used to stop the scan.
4212 */
4213 @Override
4214 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
4215 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4217 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004218
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 return mNetworkScanRequestTracker.startNetworkScan(
4222 request, messenger, binder, getPhone(subId));
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
yinxu504e1392017-04-12 16:03:22 -07004226 }
4227
4228 /**
4229 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004230 *
4231 * @param subId id of the subscription
4232 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004233 */
4234 @Override
4235 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4237 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
yinxu504e1392017-04-12 16:03:22 -07004245 }
4246
4247 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004248 * Get the calculated preferred network type.
4249 * Used for debugging incorrect network type.
4250 *
4251 * @return the preferred network type, defined in RILConstants.java.
4252 */
4253 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004254 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004255 final Phone defaultPhone = getDefaultPhone();
4256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4257 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004258 return RILConstants.PREFERRED_NETWORK_MODE;
4259 }
4260
Malcolm Chend965c8b2018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004264 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Junda Liu84d15a22014-07-02 11:21:04 -07004268 }
4269
4270 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004271 * Get the preferred network type.
4272 * Used for device configuration by some CDMA operators.
4273 *
4274 * @return the preferred network type, defined in RILConstants.java.
4275 */
4276 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004277 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4279 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004280
4281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 if (DBG) log("getPreferredNetworkType");
4284 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4285 int networkType = (result != null ? result[0] : -1);
4286 if (DBG) log("getPreferredNetworkType: " + networkType);
4287 return networkType;
4288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004291 }
4292
4293 /**
4294 * Set the preferred network type.
4295 * Used for device configuration by some CDMA operators.
4296 *
4297 * @param networkType the preferred network type, defined in RILConstants.java.
4298 * @return true on success; false on any failure.
4299 */
4300 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004301 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4303 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004304
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4308 Boolean success = (Boolean) sendRequest(
4309 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4310 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4311 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004312 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4314 }
4315 return success;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004318 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004319 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004320
4321 /**
Junda Liu475951f2014-11-07 16:45:03 -08004322 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004323 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004324 * tethering.
4325 *
4326 * @return 0: Not required. 1: required. 2: Not set.
4327 * @hide
4328 */
4329 @Override
4330 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004331 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332
4333 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004334 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004335 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004336 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004337 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004338 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004339 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 dunRequired = 1;
4341 }
4342 return dunRequired;
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004345 }
Junda Liu475951f2014-11-07 16:45:03 -08004346 }
4347
4348 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004349 * Set mobile data enabled
4350 * Used by the user through settings etc to turn on/off mobile data
4351 *
4352 * @param enable {@code true} turn turn data on, else {@code false}
4353 */
4354 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004355 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004358
4359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 int phoneId = mSubscriptionController.getPhoneId(subId);
4362 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4363 Phone phone = PhoneFactory.getPhone(phoneId);
4364 if (phone != null) {
4365 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004366 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004367 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004368 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004369 }
4370 } finally {
4371 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004372 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004373 }
4374
4375 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004376 * Get the user enabled state of Mobile Data.
4377 *
4378 * TODO: remove and use isUserDataEnabled.
4379 * This can't be removed now because some vendor codes
4380 * calls through ITelephony directly while they should
4381 * use TelephonyManager.
4382 *
4383 * @return true on enabled
4384 */
4385 @Override
4386 public boolean getDataEnabled(int subId) {
4387 return isUserDataEnabled(subId);
4388 }
4389
4390 /**
4391 * Get whether mobile data is enabled per user setting.
4392 *
4393 * There are other factors deciding whether mobile data is actually enabled, but they are
4394 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004395 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004396 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004397 *
4398 * @return {@code true} if data is enabled else {@code false}
4399 */
4400 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004401 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004402 try {
4403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4404 null);
4405 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4407 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004408 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409
4410 final long identity = Binder.clearCallingIdentity();
4411 try {
4412 int phoneId = mSubscriptionController.getPhoneId(subId);
4413 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4414 Phone phone = PhoneFactory.getPhone(phoneId);
4415 if (phone != null) {
4416 boolean retVal = phone.isUserDataEnabled();
4417 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4418 return retVal;
4419 } else {
4420 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4421 return false;
4422 }
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004425 }
4426 }
4427
4428 /**
4429 * Get whether mobile data is enabled.
4430 *
4431 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4432 * whether mobile data is actually enabled.
4433 *
4434 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4435 *
4436 * @return {@code true} if data is enabled else {@code false}
4437 */
4438 @Override
4439 public boolean isDataEnabled(int subId) {
4440 try {
4441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4442 null);
4443 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4445 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004446 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004447
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 int phoneId = mSubscriptionController.getPhoneId(subId);
4451 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4452 Phone phone = PhoneFactory.getPhone(phoneId);
4453 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004454 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004455 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4456 return retVal;
4457 } else {
4458 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4459 return false;
4460 }
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004463 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004464 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004465
4466 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004467 public int getCarrierPrivilegeStatus(int subId) {
4468 final Phone phone = getPhone(subId);
4469 if (phone == null) {
4470 loge("getCarrierPrivilegeStatus: Invalid subId");
4471 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4472 }
4473 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004474 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004475 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004476 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4477 }
4478 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004479 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004480 }
Junda Liu29340342014-07-10 15:23:27 -07004481
4482 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004483 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4484 final Phone phone = getPhone(subId);
4485 if (phone == null) {
4486 loge("getCarrierPrivilegeStatus: Invalid subId");
4487 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4488 }
4489 UiccProfile profile =
4490 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4491 if (profile == null) {
4492 loge("getCarrierPrivilegeStatus: No UICC");
4493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4494 }
4495 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4496 }
4497
4498 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004499 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004500 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004501 if (TextUtils.isEmpty(pkgName))
4502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004503 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004504 if (card == null) {
4505 loge("checkCarrierPrivilegesForPackage: No UICC");
4506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4507 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004508 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4509 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004510 }
4511
4512 @Override
4513 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004514 if (TextUtils.isEmpty(pkgName))
4515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004516 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4517 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4518 UiccCard card = UiccController.getInstance().getUiccCard(i);
4519 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004520 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004521 continue;
4522 }
4523
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004524 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004525 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4526 break;
4527 }
4528 }
4529
4530 return result;
Junda Liu29340342014-07-10 15:23:27 -07004531 }
Derek Tan89e89d42014-07-08 17:00:10 -07004532
4533 @Override
Junda Liue64de782015-04-16 17:19:16 -07004534 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4535 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4536 loge("phoneId " + phoneId + " is not valid.");
4537 return null;
4538 }
4539 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004540 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004541 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004542 return null ;
4543 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004544 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004545 }
4546
Amith Yamasani6e118872016-02-19 12:53:51 -08004547 @Override
4548 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004549 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004550 List<String> privilegedPackages = new ArrayList<>();
4551 List<PackageInfo> packages = null;
4552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4553 UiccCard card = UiccController.getInstance().getUiccCard(i);
4554 if (card == null) {
4555 // No UICC in that slot.
4556 continue;
4557 }
4558 if (card.hasCarrierPrivilegeRules()) {
4559 if (packages == null) {
4560 // Only check packages in user 0 for now
4561 packages = pm.getInstalledPackagesAsUser(
4562 PackageManager.MATCH_DISABLED_COMPONENTS
4563 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4564 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4565 }
4566 for (int p = packages.size() - 1; p >= 0; p--) {
4567 PackageInfo pkgInfo = packages.get(p);
4568 if (pkgInfo != null && pkgInfo.packageName != null
4569 && card.getCarrierPrivilegeStatus(pkgInfo)
4570 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4571 privilegedPackages.add(pkgInfo.packageName);
4572 }
4573 }
4574 }
4575 }
4576 return privilegedPackages;
4577 }
4578
Wink Savilleb564aae2014-10-23 10:18:09 -07004579 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004580 final Phone phone = getPhone(subId);
4581 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004582 if (card == null) {
4583 loge("getIccId: No UICC");
4584 return null;
4585 }
4586 String iccId = card.getIccId();
4587 if (TextUtils.isEmpty(iccId)) {
4588 loge("getIccId: ICC ID is null or empty.");
4589 return null;
4590 }
4591 return iccId;
4592 }
4593
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004594 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004595 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4596 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004597 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4598 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004599
Malcolm Chend965c8b2018-02-28 15:00:40 -08004600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 final String iccId = getIccId(subId);
4603 final Phone phone = getPhone(subId);
4604 if (phone == null) {
4605 return false;
4606 }
4607 final String subscriberId = phone.getSubscriberId();
4608
4609 if (DBG_MERGE) {
4610 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4611 + subscriberId + " to " + number);
4612 }
4613
4614 if (TextUtils.isEmpty(iccId)) {
4615 return false;
4616 }
4617
4618 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4619
4620 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4621 if (alphaTag == null) {
4622 editor.remove(alphaTagPrefKey);
4623 } else {
4624 editor.putString(alphaTagPrefKey, alphaTag);
4625 }
4626
4627 // Record both the line number and IMSI for this ICCID, since we need to
4628 // track all merged IMSIs based on line number
4629 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4630 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4631 if (number == null) {
4632 editor.remove(numberPrefKey);
4633 editor.remove(subscriberPrefKey);
4634 } else {
4635 editor.putString(numberPrefKey, number);
4636 editor.putString(subscriberPrefKey, subscriberId);
4637 }
4638
4639 editor.commit();
4640 return true;
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004643 }
Derek Tan7226c842014-07-02 17:42:23 -07004644 }
4645
4646 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004647 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004648 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004650 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004651 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004652 return null;
4653 }
Derek Tan97ebb422014-09-05 16:55:38 -07004654
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 String iccId = getIccId(subId);
4658 if (iccId != null) {
4659 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4660 if (DBG_MERGE) {
4661 log("getLine1NumberForDisplay returning "
4662 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4663 }
4664 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004665 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004666 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4667 return null;
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004670 }
Derek Tan7226c842014-07-02 17:42:23 -07004671 }
4672
4673 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004674 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004676 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004677 return null;
4678 }
Derek Tan97ebb422014-09-05 16:55:38 -07004679
Malcolm Chend965c8b2018-02-28 15:00:40 -08004680 final long identity = Binder.clearCallingIdentity();
4681 try {
4682 String iccId = getIccId(subId);
4683 if (iccId != null) {
4684 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4685 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4686 }
4687 return null;
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004690 }
Derek Tan7226c842014-07-02 17:42:23 -07004691 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004692
4693 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004694 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004695 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4696 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004698 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4699 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004700 return null;
4701 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004702
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004703 final long identity = Binder.clearCallingIdentity();
4704 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004705 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004706 final TelephonyManager tele = TelephonyManager.from(context);
4707 final SubscriptionManager sub = SubscriptionManager.from(context);
4708
4709 // Figure out what subscribers are currently active
4710 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4711 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4712 // the process, where TelephonyManager was instantiated.
4713 // Otherwise AppOps check will fail.
4714
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004715 final int[] subIds = sub.getActiveSubscriptionIdList();
4716 for (int subId : subIds) {
4717 activeSubscriberIds.add(tele.getSubscriberId(subId));
4718 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004719
4720 // First pass, find a number override for an active subscriber
4721 String mergeNumber = null;
4722 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4723 for (String key : prefs.keySet()) {
4724 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4725 final String subscriberId = (String) prefs.get(key);
4726 if (activeSubscriberIds.contains(subscriberId)) {
4727 final String iccId = key.substring(
4728 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4729 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4730 mergeNumber = (String) prefs.get(numberKey);
4731 if (DBG_MERGE) {
4732 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4733 + " for active subscriber " + subscriberId);
4734 }
4735 if (!TextUtils.isEmpty(mergeNumber)) {
4736 break;
4737 }
4738 }
4739 }
4740 }
4741
4742 // Shortcut when no active merged subscribers
4743 if (TextUtils.isEmpty(mergeNumber)) {
4744 return null;
4745 }
4746
4747 // Second pass, find all subscribers under that line override
4748 final ArraySet<String> result = new ArraySet<>();
4749 for (String key : prefs.keySet()) {
4750 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4751 final String number = (String) prefs.get(key);
4752 if (mergeNumber.equals(number)) {
4753 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4754 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4755 final String subscriberId = (String) prefs.get(subscriberKey);
4756 if (!TextUtils.isEmpty(subscriberId)) {
4757 result.add(subscriberId);
4758 }
4759 }
4760 }
4761 }
4762
4763 final String[] resultArray = result.toArray(new String[result.size()]);
4764 Arrays.sort(resultArray);
4765 if (DBG_MERGE) {
4766 Slog.d(LOG_TAG,
4767 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4768 }
4769 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004772 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004773 }
4774
4775 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004776 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004777 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4778 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004779
4780 final long identity = Binder.clearCallingIdentity();
4781 try {
4782 final Phone phone = getPhone(subId);
4783 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004787 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004788
4789 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004790 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004791 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4792 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004793 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004794
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 final Phone phone = getPhone(subId);
4798 if (phone == null) {
4799 return false;
4800 }
4801 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4802 cdmaNonRoamingList);
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004805 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004806 }
4807
4808 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004809 @Deprecated
4810 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4811 enforceModifyPermission();
4812
4813 int returnValue = 0;
4814 try {
vagdevie435a3e2018-08-15 16:01:53 -07004815 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004816 if(result.exception == null) {
4817 if (result.result != null) {
4818 byte[] responseData = (byte[])(result.result);
4819 if(responseData.length > oemResp.length) {
4820 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4821 responseData.length + "bytes. Buffer Size is " +
4822 oemResp.length + "bytes.");
4823 }
4824 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4825 returnValue = responseData.length;
4826 }
4827 } else {
4828 CommandException ex = (CommandException) result.exception;
4829 returnValue = ex.getCommandError().ordinal();
4830 if(returnValue > 0) returnValue *= -1;
4831 }
4832 } catch (RuntimeException e) {
4833 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4834 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4835 if(returnValue > 0) returnValue *= -1;
4836 }
4837
4838 return returnValue;
4839 }
4840
4841 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004842 public void setRadioCapability(RadioAccessFamily[] rafs) {
4843 try {
4844 ProxyController.getInstance().setRadioCapability(rafs);
4845 } catch (RuntimeException e) {
4846 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4847 }
4848 }
4849
4850 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004851 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004852 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004853 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004854 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004855 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004856 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
chen xufeeed752018-10-26 14:17:57 -07004859 TelephonyPermissions
4860 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4861 mApp, phone.getSubId(), "getRadioAccessFamily");
4862 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004863 } finally {
4864 Binder.restoreCallingIdentity(identity);
4865 }
chen xufeeed752018-10-26 14:17:57 -07004866 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004867 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004868
4869 @Override
4870 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004871 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004872 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004873
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004876 ImsManager.getInstance(defaultPhone.getContext(),
4877 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004881 }
4882
4883 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004884 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004885 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004887 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004888 return false;
4889 }
Svet Ganovb320e182015-04-16 12:30:10 -07004890
Malcolm Chend965c8b2018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 // Check the user preference and the system-level IMS setting. Even if the user has
4894 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4895 // In the long run, we may instead need to check if there exists a connection service
4896 // which can support video calling.
4897 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004898 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004899 return imsManager.isVtEnabledByPlatform()
4900 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4901 && imsManager.isVtEnabledByUser();
4902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004905 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004906
Andrew Leea1239f22015-03-02 17:44:07 -08004907 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004908 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4910 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4911 return false;
4912 }
4913
4914 final long identity = Binder.clearCallingIdentity();
4915 try {
4916 CarrierConfigManager configManager =
4917 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004918 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004919 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
Andrew Leea1239f22015-03-02 17:44:07 -08004923 }
4924
4925 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 public boolean isWorldPhone(int subId, String callingPackage) {
4927 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4928 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4929 return false;
4930 }
4931
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 CarrierConfigManager configManager =
4935 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004936 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004937 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4938 } finally {
4939 Binder.restoreCallingIdentity(identity);
4940 }
Andrew Leea1239f22015-03-02 17:44:07 -08004941 }
4942
Andrew Lee9431b832015-03-09 18:46:45 -07004943 @Override
4944 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004945 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004946 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004947 }
4948
4949 @Override
4950 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
4952 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004953 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Andrew Lee9431b832015-03-09 18:46:45 -07004957 }
4958
Hall Liuf6668912018-10-31 17:05:23 -07004959 /**
4960 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4961 * support for the feature and device firmware support.
4962 *
4963 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4964 */
4965 @Override
4966 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004968 final Phone phone = getPhone(subscriptionId);
4969 if (phone == null) {
4970 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4971 return false;
4972 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004973 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004974 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004975 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4976 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004977 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004978 return isCarrierSupported && isDeviceSupported;
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
Hall Liu98187582018-01-22 19:15:32 -08004982 }
4983
Hall Liuf6668912018-10-31 17:05:23 -07004984 /**
4985 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4986 * both also support RTT.
4987 */
4988 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
Hall Liuf6668912018-10-31 17:05:23 -07004991 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004992 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004996 }
4997
Sanket Padawe7310cc72015-01-14 09:53:20 -08004998 /**
4999 * Returns the unique device ID of phone, for example, the IMEI for
5000 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5001 *
5002 * <p>Requires Permission:
5003 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5004 */
5005 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005006 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005007 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005008 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005009 return null;
5010 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005011 int subId = phone.getSubId();
5012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5013 mApp, subId, callingPackage, "getDeviceId")) {
5014 return null;
5015 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 return phone.getDeviceId();
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005023 }
5024
Ping Sunc67b7c22016-03-02 19:16:45 +08005025 /**
5026 * {@hide}
5027 * Returns the IMS Registration Status on a particular subid
5028 *
5029 * @param subId
5030 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005031 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005032 Phone phone = getPhone(subId);
5033 if (phone != null) {
5034 return phone.isImsRegistered();
5035 } else {
5036 return false;
5037 }
5038 }
5039
Santos Cordon7a1885b2015-02-03 11:15:19 -08005040 @Override
5041 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
5047 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005048 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005049
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005050 /**
5051 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005052 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005053 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 Phone phone = getPhone(subId);
5057 if (phone != null) {
5058 return phone.isWifiCallingEnabled();
5059 } else {
5060 return false;
5061 }
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005064 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005065 }
5066
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005067 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005068 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005069 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005070 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 Phone phone = getPhone(subId);
5074 if (phone != null) {
5075 return phone.isVideoEnabled();
5076 } else {
5077 return false;
5078 }
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005081 }
5082 }
5083
5084 /**
5085 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5086 * defined in {@link ImsRegistrationImplBase}.
5087 */
5088 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 Phone phone = getPhone(subId);
5092 if (phone != null) {
5093 return phone.getImsRegistrationTech();
5094 } else {
5095 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5096 }
5097 } finally {
5098 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005099 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005100 }
5101
Stuart Scott8eef64f2015-04-08 15:13:54 -07005102 @Override
5103 public void factoryReset(int subId) {
5104 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005105 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5106 return;
5107 }
5108
Svet Ganovcc087f82015-05-12 20:35:54 -07005109 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005110
Svet Ganovcc087f82015-05-12 20:35:54 -07005111 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005112 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5113 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005114 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005115 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005116 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005117 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5118 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005119 }
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005122 }
5123 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005124
5125 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005126 public String getSimLocaleForSubscriber(int subId) {
5127 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5128 final Phone phone = getPhone(subId);
5129 if (phone == null) {
5130 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005131 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005132 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005135 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5136 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137 // Try and fetch the locale from the carrier properties or from the SIM language
5138 // preferences (EF-PL and EF-LI)...
5139 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005141 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5142 if (localeFromDefaultSim != null) {
5143 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5144 if (DBG) log("Using locale from subId: " + subId + " locale: "
5145 + localeFromDefaultSim);
5146 return localeFromDefaultSim.toLanguageTag();
5147 } else {
5148 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005149 }
5150 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005151
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 // The SIM language preferences only store a language (e.g. fr = French), not an
5153 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5154 // the SIM and carrier preferences does not include a country we add the country
5155 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005156 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005157 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005158 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 return mccLocale.toLanguageTag();
5160 }
5161
5162 if (DBG) log("No locale found - returning null");
5163 return null;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005167 }
5168
5169 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005170 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005171 }
5172
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 /**
5174 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5175 */
5176 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005177 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005178 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005179
Chenjie Yu1ba97252018-01-11 18:16:20 -08005180 private final ModemActivityInfo mLastModemActivityInfo =
5181 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5182
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005183 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005184 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5185 * representing the state of the modem.
5186 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005187 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5188 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005189 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005190 */
5191 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005192 public void requestModemActivityInfo(ResultReceiver result) {
5193 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005194 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005195
5196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 ModemActivityInfo ret = null;
5199 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005200 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5201 CMD_GET_MODEM_ACTIVITY_INFO,
5202 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 if (isModemActivityInfoValid(info)) {
5204 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5205 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5206 mergedTxTimeMs[i] =
5207 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5208 }
5209 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5210 mLastModemActivityInfo.setSleepTimeMillis(
5211 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5212 mLastModemActivityInfo.setIdleTimeMillis(
5213 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5214 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5215 mLastModemActivityInfo.setRxTimeMillis(
5216 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5217 mLastModemActivityInfo.setEnergyUsed(
5218 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005219 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005220 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5221 mLastModemActivityInfo.getSleepTimeMillis(),
5222 mLastModemActivityInfo.getIdleTimeMillis(),
5223 mLastModemActivityInfo.getTxTimeMillis(),
5224 mLastModemActivityInfo.getRxTimeMillis(),
5225 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005226 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 Bundle bundle = new Bundle();
5228 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5229 result.send(0, bundle);
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005232 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005233 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005234
Siddharth Rayf5d29552018-06-17 15:02:38 -07005235 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5236 // less than total activity duration.
5237 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5238 if (info == null) {
5239 return false;
5240 }
5241 int activityDurationMs =
5242 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5243 int totalTxTimeMs = 0;
5244 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5245 totalTxTimeMs += info.getTxTimeMillis()[i];
5246 }
5247 return (info.isValid()
5248 && (info.getSleepTimeMillis() <= activityDurationMs)
5249 && (info.getIdleTimeMillis() <= activityDurationMs)
5250 && (info.getRxTimeMillis() <= activityDurationMs)
5251 && (totalTxTimeMs <= activityDurationMs));
5252 }
5253
Jack Yu85bd38a2015-11-09 11:34:32 -08005254 /**
5255 * {@hide}
5256 * Returns the service state information on specified subscription.
5257 */
5258 @Override
5259 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005261 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005262 return null;
5263 }
5264
Malcolm Chend965c8b2018-02-28 15:00:40 -08005265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 final Phone phone = getPhone(subId);
5268 if (phone == null) {
5269 return null;
5270 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005271
Malcolm Chend965c8b2018-02-28 15:00:40 -08005272 return phone.getServiceState();
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
5275 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005276 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005277
5278 /**
5279 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5280 *
5281 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5282 * voicemail ringtone.
5283 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5284 * PhoneAccount.
5285 */
5286 @Override
5287 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5291 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005292 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005293 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005294
Malcolm Chend965c8b2018-02-28 15:00:40 -08005295 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005299 }
5300
5301 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005302 * Sets the per-account voicemail ringtone.
5303 *
5304 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5305 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5306 *
5307 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5308 * voicemail ringtone.
5309 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5310 * PhoneAccount.
5311 */
5312 @Override
5313 public void setVoicemailRingtoneUri(String callingPackage,
5314 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005315 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5317 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005318 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5320 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5321 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005322 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5327 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005328 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005329 }
5330 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005333 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005334 }
5335
5336 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005337 * Returns whether vibration is set for voicemail notification in Phone settings.
5338 *
5339 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5340 * voicemail vibration setting.
5341 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5342 */
5343 @Override
5344 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005345 final long identity = Binder.clearCallingIdentity();
5346 try {
5347 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5348 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005349 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005350 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005351
Malcolm Chend965c8b2018-02-28 15:00:40 -08005352 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005356 }
5357
Youhan Wange64578a2016-05-02 15:32:42 -07005358 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005359 * Sets the per-account voicemail vibration.
5360 *
5361 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5362 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5363 *
5364 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5365 * voicemail vibration setting.
5366 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5367 * specific PhoneAccount.
5368 */
5369 @Override
5370 public void setVoicemailVibrationEnabled(String callingPackage,
5371 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005372 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5374 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005375 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5378 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005379 }
5380
Malcolm Chend965c8b2018-02-28 15:00:40 -08005381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5384 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005385 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005386 }
5387 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005390 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005391 }
5392
5393 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005394 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5395 *
5396 * @throws SecurityException if the caller does not have the required permission
5397 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005398 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005400 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005401 }
5402
5403 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005404 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5405 * permission.
5406 *
5407 * @throws SecurityException if the caller does not have the required permission
5408 */
5409 private void enforceSendSmsPermission() {
5410 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5411 }
5412
5413 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005414 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005415 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005416 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005417 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005418 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005422 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005423 if (componentName == null) {
5424 throw new SecurityException(
5425 "Caller not current active visual voicemail package[null]");
5426 }
5427 String vvmPackage = componentName.getPackageName();
5428 if (!callingPackage.equals(vvmPackage)) {
5429 throw new SecurityException("Caller not current active visual voicemail package["
5430 + vvmPackage + "]");
5431 }
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005434 }
5435 }
5436
5437 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005438 * Return the application ID for the app type.
5439 *
5440 * @param subId the subscription ID that this request applies to.
5441 * @param appType the uicc app type.
5442 * @return Application ID for specificied app type, or null if no uicc.
5443 */
5444 @Override
5445 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005446 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005447 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448
5449 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005450 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451 if (phone == null) {
5452 return null;
5453 }
5454 String aid = null;
5455 try {
5456 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5457 .getApplicationByType(appType).getAid();
5458 } catch (Exception e) {
5459 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5460 }
5461 return aid;
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005464 }
Youhan Wange64578a2016-05-02 15:32:42 -07005465 }
5466
Youhan Wang4001d252016-05-11 10:29:41 -07005467 /**
5468 * Return the Electronic Serial Number.
5469 *
5470 * @param subId the subscription ID that this request applies to.
5471 * @return ESN or null if error.
5472 */
5473 @Override
5474 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005475 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005476 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005479 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 if (phone == null) {
5481 return null;
5482 }
5483 String esn = null;
5484 try {
5485 esn = phone.getEsn();
5486 } catch (Exception e) {
5487 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5488 }
5489 return esn;
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005492 }
Youhan Wang4001d252016-05-11 10:29:41 -07005493 }
5494
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005495 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005496 * Return the Preferred Roaming List Version.
5497 *
5498 * @param subId the subscription ID that this request applies to.
5499 * @return PRLVersion or null if error.
5500 */
5501 @Override
5502 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005503 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005504 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005505
5506 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005507 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005508 if (phone == null) {
5509 return null;
5510 }
5511 String cdmaPrlVersion = null;
5512 try {
5513 cdmaPrlVersion = phone.getCdmaPrlVersion();
5514 } catch (Exception e) {
5515 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5516 }
5517 return cdmaPrlVersion;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005520 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005521 }
5522
5523 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005524 * Get snapshot of Telephony histograms
5525 * @return List of Telephony histograms
5526 * @hide
5527 */
5528 @Override
5529 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5531 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005532
5533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 return RIL.getTelephonyRILTimingHistograms();
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005539 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005540
5541 /**
5542 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005543 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5544 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005545 * Require system privileges. In the future we may add this to carrier APIs.
5546 *
Michele Berionne0963c862018-11-27 18:57:59 -08005547 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005548 */
5549 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005550 @TelephonyManager.SetCarrierRestrictionResult
5551 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005552 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005554
Michele Berionne0963c862018-11-27 18:57:59 -08005555 if (carrierRestrictionRules == null) {
5556 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005557 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005558
Malcolm Chend965c8b2018-02-28 15:00:40 -08005559 final long identity = Binder.clearCallingIdentity();
5560 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005561 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005562 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005566 }
5567
5568 /**
5569 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005570 * Get the allowed carrier list and the excluded carrier list, including the priority between
5571 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005572 * Require system privileges. In the future we may add this to carrier APIs.
5573 *
Michele Berionne0963c862018-11-27 18:57:59 -08005574 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005575 */
5576 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005577 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005578 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005583 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5584 if (response instanceof CarrierRestrictionRules) {
5585 return (CarrierRestrictionRules) response;
5586 }
5587 // Response is an Exception of some kind,
5588 // which is signalled to the user as a NULL retval
5589 return null;
5590 } catch (Exception e) {
5591 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5592 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005596 }
5597
fionaxu59545b42016-05-25 15:53:37 -07005598 /**
5599 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5600 * @param subId the subscription ID that this action applies to.
5601 * @param enabled control enable or disable metered apns.
5602 * {@hide}
5603 */
5604 @Override
5605 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5606 enforceModifyPermission();
5607 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005608
5609 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005610 if (phone == null) {
5611 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5612 return;
5613 }
5614 try {
5615 phone.carrierActionSetMeteredApnsEnabled(enabled);
5616 } catch (Exception e) {
5617 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005618 } finally {
5619 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005620 }
5621 }
5622
5623 /**
5624 * Action set from carrier signalling broadcast receivers to enable/disable radio
5625 * @param subId the subscription ID that this action applies to.
5626 * @param enabled control enable or disable radio.
5627 * {@hide}
5628 */
5629 @Override
5630 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5631 enforceModifyPermission();
5632 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005635 if (phone == null) {
5636 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5637 return;
5638 }
5639 try {
5640 phone.carrierActionSetRadioEnabled(enabled);
5641 } catch (Exception e) {
5642 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005645 }
5646 }
5647
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005648 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005649 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5650 * network status based on which carrier apps could apply actions accordingly,
5651 * enable/disable default url handler for example.
5652 *
5653 * @param subId the subscription ID that this action applies to.
5654 * @param report control start/stop reporting the default network status.
5655 * {@hide}
5656 */
5657 @Override
5658 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5659 enforceModifyPermission();
5660 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661
5662 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005663 if (phone == null) {
5664 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5665 return;
5666 }
5667 try {
5668 phone.carrierActionReportDefaultNetworkStatus(report);
5669 } catch (Exception e) {
5670 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671 } finally {
5672 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005673 }
5674 }
5675
5676 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005677 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5678 * bug report is being generated.
5679 */
5680 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005681 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005682 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5683 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005684 writer.println("Permission Denial: can't dump Phone from pid="
5685 + Binder.getCallingPid()
5686 + ", uid=" + Binder.getCallingUid()
5687 + "without permission "
5688 + android.Manifest.permission.DUMP);
5689 return;
5690 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005691 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005692 }
Jack Yueb89b242016-06-22 13:27:47 -07005693
Brad Ebingerdac2f002018-04-03 15:17:52 -07005694 @Override
5695 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5696 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5697 throws RemoteException {
5698 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5699 }
5700
Jack Yueb89b242016-06-22 13:27:47 -07005701 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005702 * Get aggregated video call data usage since boot.
5703 *
5704 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5705 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005706 * {@hide}
5707 */
5708 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005709 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5711 null);
5712
Malcolm Chend965c8b2018-02-28 15:00:40 -08005713 final long identity = Binder.clearCallingIdentity();
5714 try {
5715 // NetworkStatsService keeps tracking the active network interface and identity. It
5716 // records the delta with the corresponding network identity.
5717 // We just return the total video call data usage snapshot since boot.
5718 Phone phone = getPhone(subId);
5719 if (phone != null) {
5720 return phone.getVtDataUsage(perUidStats);
5721 }
5722 return null;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005725 }
Jack Yueb89b242016-06-22 13:27:47 -07005726 }
Jack Yu75ab2952016-07-08 14:29:33 -07005727
5728 /**
5729 * Policy control of data connection. Usually used when data limit is passed.
5730 * @param enabled True if enabling the data, otherwise disabling.
5731 * @param subId Subscription index
5732 * {@hide}
5733 */
5734 @Override
5735 public void setPolicyDataEnabled(boolean enabled, int subId) {
5736 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005737
5738 final long identity = Binder.clearCallingIdentity();
5739 try {
5740 Phone phone = getPhone(subId);
5741 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005742 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005743 }
5744 } finally {
5745 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005746 }
5747 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005748
5749 /**
5750 * Get Client request stats
5751 * @return List of Client Request Stats
5752 * @hide
5753 */
5754 @Override
5755 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005757 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005758 return null;
5759 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005760 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005761
Malcolm Chend965c8b2018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 if (phone != null) {
5765 return phone.getClientRequestStats();
5766 }
5767
5768 return null;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005772 }
5773
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005774 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005775 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005776 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005777 }
Jack Yueb4124c2017-02-16 15:32:43 -08005778
5779 /**
Grace Chen70990072017-03-24 17:21:30 -07005780 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005781 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005782 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005783 * @param state State of SIM (power down, power up, pass through)
5784 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5785 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5786 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005787 *
5788 **/
5789 @Override
Grace Chen70990072017-03-24 17:21:30 -07005790 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005791 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005792 Phone phone = PhoneFactory.getPhone(slotIndex);
5793
vagdevie435a3e2018-08-15 16:01:53 -07005794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5795
Malcolm Chend965c8b2018-02-28 15:00:40 -08005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005799 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005800 }
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005803 }
5804 }
Shuo Qiandd210312017-04-12 22:11:33 +00005805
Tyler Gunn65d45c22017-06-05 11:22:26 -07005806 private boolean isUssdApiAllowed(int subId) {
5807 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005808 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005809 if (configManager == null) {
5810 return false;
5811 }
5812 PersistableBundle pb = configManager.getConfigForSubId(subId);
5813 if (pb == null) {
5814 return false;
5815 }
5816 return pb.getBoolean(
5817 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5818 }
5819
Shuo Qiandd210312017-04-12 22:11:33 +00005820 /**
5821 * Check if phone is in emergency callback mode
5822 * @return true if phone is in emergency callback mode
5823 * @param subId sub id
5824 */
goneil9c5f4872017-12-05 14:07:56 -08005825 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005826 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005827 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005828 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005829
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 if (phone != null) {
5833 return phone.isInEcm();
5834 } else {
5835 return false;
5836 }
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005839 }
5840 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005841
5842 /**
5843 * Get the current signal strength information for the given subscription.
5844 * Because this information is not updated when the device is in a low power state
5845 * it should not be relied-upon to be current.
5846 * @param subId Subscription index
5847 * @return the most recent cached signal strength info from the modem
5848 */
5849 @Override
5850 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 Phone p = getPhone(subId);
5854 if (p == null) {
5855 return null;
5856 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005857
Malcolm Chend965c8b2018-02-28 15:00:40 -08005858 return p.getSignalStrength();
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005862 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005863
Pengquan Meng9140aec2018-08-22 14:49:57 -07005864 /**
chen xu907e5a22018-10-11 13:21:04 -07005865 * Get the current modem radio state for the given slot.
5866 * @param slotIndex slot index.
5867 * @param callingPackage the name of the package making the call.
5868 * @return the current radio power state from the modem
5869 */
5870 @Override
5871 public int getRadioPowerState(int slotIndex, String callingPackage) {
5872 Phone phone = PhoneFactory.getPhone(slotIndex);
5873 if (phone != null) {
5874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5875 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5876 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5877 }
5878
5879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 return phone.getRadioPowerState();
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
5885 }
5886 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5887 }
5888
5889 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005890 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5891 *
5892 * <p>Requires one of the following permissions:
5893 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5894 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5895 * privileges.
5896 *
5897 * @param subId subscription id
5898 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5899 * {@code false}.
5900 */
5901 @Override
5902 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005903 boolean isEnabled = false;
5904 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005905 try {
5906 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005907 null /* message */);
5908 Phone phone = getPhone(subId);
5909 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005910 } catch (Exception e) {
5911 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5912 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005915 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005916 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005917 }
5918
5919
5920 /**
5921 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5922 *
5923 * <p> Requires permission:
5924 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5925 * privileges.
5926 *
5927 * @param subId subscription id
5928 * @param isEnabled {@code true} means enable, {@code false} means disable.
5929 */
5930 @Override
5931 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5935 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005936
Pengquan Meng0c05b502018-09-06 09:59:22 -07005937 Phone phone = getPhone(subId);
5938 if (phone != null) {
5939 phone.setDataRoamingEnabled(isEnabled);
5940 }
5941 } finally {
5942 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005943 }
5944 }
5945
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005946 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005947 public boolean isManualNetworkSelectionAllowed(int subId) {
5948 boolean isAllowed = true;
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
5951 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5952 mApp, subId, "isManualNetworkSelectionAllowed");
5953 Phone phone = getPhone(subId);
5954 if (phone != null) {
5955 isAllowed = phone.isCspPlmnEnabled();
5956 }
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 return isAllowed;
5961 }
5962
5963 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08005964 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
5965 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
5966 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5967 throw new SecurityException("Caller does not have carrier privileges on any UICC.");
5968 }
Jordan Liu5aa07002018-12-18 15:44:48 -08005969
5970 final long identity = Binder.clearCallingIdentity();
5971 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08005972 UiccController uiccController = UiccController.getInstance();
5973 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
5974
5975 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
5976 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
5977 // Remove private info if the caller doesn't have access
5978 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
5979 for (UiccCardInfo cardInfo : cardInfos) {
5980 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
5981 UiccProfile profile = card.getUiccProfile();
5982 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
5983 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5984 filteredInfos.add(cardInfo.getUnprivileged());
5985 } else {
5986 filteredInfos.add(cardInfo);
5987 }
5988 }
5989 return filteredInfos;
5990 }
5991 return cardInfos;
5992 } catch (PackageManager.NameNotFoundException e) {
5993 // This should not happen since we pass the package info in from TelephonyManager
5994 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
5998 }
5999
6000 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006001 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006002 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006003
Malcolm Chend965c8b2018-02-28 15:00:40 -08006004 final long identity = Binder.clearCallingIdentity();
6005 try {
6006 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6007 if (slots == null) {
6008 Rlog.i(LOG_TAG, "slots is null.");
6009 return null;
6010 }
6011
6012 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6013 for (int i = 0; i < slots.length; i++) {
6014 UiccSlot slot = slots[i];
6015 if (slot == null) {
6016 continue;
6017 }
6018
6019 String cardId;
6020 UiccCard card = slot.getUiccCard();
6021 if (card != null) {
6022 cardId = card.getCardId();
6023 } else {
6024 cardId = slot.getIccId();
6025 }
6026
6027 int cardState = 0;
6028 switch (slot.getCardState()) {
6029 case CARDSTATE_ABSENT:
6030 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6031 break;
6032 case CARDSTATE_PRESENT:
6033 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6034 break;
6035 case CARDSTATE_ERROR:
6036 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6037 break;
6038 case CARDSTATE_RESTRICTED:
6039 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6040 break;
6041 default:
6042 break;
6043
6044 }
6045
6046 infos[i] = new UiccSlotInfo(
6047 slot.isActive(),
6048 slot.isEuicc(),
6049 cardId,
6050 cardState,
6051 slot.getPhoneId(),
6052 slot.isExtendedApduSupported());
6053 }
6054 return infos;
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006057 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006058 }
6059
6060 @Override
6061 public boolean switchSlots(int[] physicalSlots) {
6062 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
6066 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006070 }
Jack Yu4c988042018-02-27 15:30:01 -08006071
6072 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006073 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 return UiccController.getInstance().getCardIdForDefaultEuicc();
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
6080 }
6081
6082 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006083 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6084 enforceModifyPermission();
6085 final Phone phone = getPhone(subId);
6086 if (phone == null) {
6087 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6088 return;
6089 }
6090
Malcolm Chend965c8b2018-02-28 15:00:40 -08006091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 phone.setRadioIndicationUpdateMode(filters, mode);
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Jack Yu4c988042018-02-27 15:30:01 -08006097 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006098
6099 /**
goneil47ffb6e2018-04-06 15:40:58 -07006100 * A test API to reload the UICC profile.
6101 *
6102 * <p>Requires that the calling app has permission
6103 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6104 * @hide
6105 */
6106 @Override
6107 public void refreshUiccProfile(int subId) {
6108 enforceModifyPermission();
6109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 Phone phone = getPhone(subId);
6113 if (phone == null) {
6114 return;
6115 }
6116 UiccCard uiccCard = phone.getUiccCard();
6117 if (uiccCard == null) {
6118 return;
6119 }
6120 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6121 if (uiccProfile == null) {
6122 return;
6123 }
6124 uiccProfile.refresh();
6125 } finally {
6126 Binder.restoreCallingIdentity(identity);
6127 }
6128 }
6129
6130 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006131 * Returns false if the mobile data is disabled by default, otherwise return true.
6132 */
6133 private boolean getDefaultDataEnabled() {
6134 return "true".equalsIgnoreCase(
6135 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6136 }
6137
6138 /**
6139 * Returns true if the data roaming is enabled by default, i.e the system property
6140 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6141 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6142 */
6143 private boolean getDefaultDataRoamingEnabled(int subId) {
6144 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006145 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006146 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6147 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6148 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6149 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6150 return isDataRoamingEnabled;
6151 }
6152
6153 /**
6154 * Returns the default network type for the given {@code subId}, if the default network type is
6155 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6156 */
6157 private int getDefaultNetworkType(int subId) {
6158 return Integer.parseInt(
6159 TelephonyManager.getTelephonyProperty(
6160 mSubscriptionController.getPhoneId(subId),
6161 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6162 String.valueOf(Phone.PREFERRED_NT_MODE)));
6163 }
fionaxua13278b2018-03-21 00:08:13 -07006164
6165 @Override
6166 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6167 gid1, String gid2, String plmn, String spn) {
6168 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006169
6170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 final Phone phone = getPhone(subId);
6173 if (phone == null) {
6174 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6175 return;
6176 }
6177 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006180 }
fionaxua13278b2018-03-21 00:08:13 -07006181 }
6182
6183 @Override
6184 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006185 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006186
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 final Phone phone = getPhone(subId);
6190 if (phone == null) {
6191 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6192 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6193 }
6194 return phone.getCarrierIdListVersion();
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006197 }
fionaxua13278b2018-03-21 00:08:13 -07006198 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006199
6200 @Override
6201 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6203 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6204 return -1;
6205 }
6206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
6213 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006214
6215 @Override
6216 public int getCdmaRoamingMode(int subId) {
6217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6218 mApp, subId, "getCdmaRoamingMode");
6219
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 @Override
6229 public boolean setCdmaRoamingMode(int subId, int mode) {
6230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "setCdmaRoamingMode");
6232
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
6239 }
6240
6241 @Override
6242 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6244 mApp, subId, "setCdmaSubscriptionMode");
6245
6246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
chen xu7ee67862018-10-30 22:27:10 -07006253
sqian2fff4a32018-11-05 14:18:37 -08006254 private void ensureUserRunning(int userId) {
6255 if (!mUserManager.isUserRunning(userId)) {
6256 throw new IllegalStateException("User " + userId + " does not exist or not running");
6257 }
6258 }
6259
6260 /**
6261 * Returns a list of SMS apps on a given user.
6262 *
6263 * Only the shell user (UID 2000 or 0) can call it.
6264 * Target user must be running.
6265 */
6266 @Override
6267 public String[] getSmsApps(int userId) {
6268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6269 ensureUserRunning(userId);
6270
6271 final Collection<SmsApplicationData> apps =
6272 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6273
6274 String[] ret = new String[apps.size()];
6275 int i = 0;
6276 for (SmsApplicationData app : apps) {
6277 ret[i++] = app.mPackageName;
6278 }
6279 return ret;
6280 }
6281
6282 /**
6283 * Returns the default SMS app package name on a given user.
6284 *
6285 * Only the shell user (UID 2000 or 0) can call it.
6286 * Target user must be running.
6287 */
6288 @Override
6289 public String getDefaultSmsApp(int userId) {
6290 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6291 ensureUserRunning(userId);
6292
6293 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6294 /* updateIfNeeded= */ true, userId);
6295 return cn == null ? null : cn.getPackageName();
6296 }
6297
6298 /**
6299 * Set a package as the default SMS app on a given user.
6300 *
6301 * Only the shell user (UID 2000 or 0) can call it.
6302 * Target user must be running.
6303 */
6304 @Override
6305 public void setDefaultSmsApp(int userId, String packageName) {
6306 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6307 ensureUserRunning(userId);
6308
6309 boolean found = false;
6310 for (String pkg : getSmsApps(userId)) {
6311 if (TextUtils.equals(packageName, pkg)) {
6312 found = true;
6313 break;
6314 }
6315 }
6316 if (!found) {
6317 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6318 }
6319
6320 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6321 }
6322
chen xu7ee67862018-10-30 22:27:10 -07006323 @Override
sqian04b86072018-11-07 14:02:21 -08006324 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6325 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6327 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6328 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6329 }
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
sqian991b35e2018-12-12 16:48:18 -08006332 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6333 for (Phone phone: PhoneFactory.getPhones()) {
6334 if (phone.getEmergencyNumberTracker() != null
6335 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6336 emergencyNumberListInternal.put(
6337 phone.getSubId(),
6338 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6339 }
sqian03bca152018-12-05 18:48:28 -08006340 }
sqian991b35e2018-12-12 16:48:18 -08006341 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
sqian04b86072018-11-07 14:02:21 -08006345 }
6346
6347 @Override
sqian03bca152018-12-05 18:48:28 -08006348 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6349 final Phone defaultPhone = getDefaultPhone();
6350 if (!exactMatch) {
6351 TelephonyPermissions
6352 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6353 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6354 }
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
sqian991b35e2018-12-12 16:48:18 -08006357 for (Phone phone: PhoneFactory.getPhones()) {
6358 if (phone.getEmergencyNumberTracker() != null
6359 && phone.getEmergencyNumberTracker() != null) {
6360 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6361 number, exactMatch)) {
6362 return true;
sqian03bca152018-12-05 18:48:28 -08006363 }
6364 }
sqian03bca152018-12-05 18:48:28 -08006365 }
6366 return false;
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
6370 }
6371
sqian9d4df8b2019-01-15 18:32:07 -08006372 /**
6373 * Update emergency number list for test mode.
6374 */
6375 @Override
6376 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6378 "updateEmergencyNumberListTestMode");
6379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 for (Phone phone: PhoneFactory.getPhones()) {
6383 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6384 if (tracker != null) {
6385 tracker.executeEmergencyNumberTestModeCommand(action, num);
6386 }
6387 }
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
6391 }
6392
6393 /**
6394 * Get the full emergency number list for test mode.
6395 */
6396 @Override
6397 public List<String> getEmergencyNumberListTestMode() {
6398 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6399 "getEmergencyNumberListTestMode");
6400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 Set<String> emergencyNumbers = new HashSet<>();
6404 for (Phone phone: PhoneFactory.getPhones()) {
6405 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6406 if (tracker != null) {
6407 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6408 emergencyNumbers.add(num.getNumber());
6409 }
6410 }
6411 }
6412 return new ArrayList<>(emergencyNumbers);
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
6416 }
6417
sqian04b86072018-11-07 14:02:21 -08006418 @Override
chen xu7ee67862018-10-30 22:27:10 -07006419 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6420 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6421 Phone phone = getPhone(subId);
6422 if (phone == null) {
6423 return null;
6424 }
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 UiccProfile profile = UiccController.getInstance()
6428 .getUiccProfileForPhone(phone.getPhoneId());
6429 if (profile != null) {
6430 return profile.getCertsFromCarrierPrivilegeAccessRules();
6431 }
6432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 return null;
6436 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006437
6438 /**
6439 * Enable or disable a modem stack.
6440 */
6441 @Override
6442 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6443 enforceModifyPermission();
6444
6445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 Phone phone = PhoneFactory.getPhone(slotIndex);
6448 if (phone == null) {
6449 return false;
6450 } else {
6451 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6452 }
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
6455 }
6456 }
Micheled3107c52018-12-21 15:00:11 -08006457
6458 @Override
6459 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6460 enforceModifyPermission();
6461
6462 final long identity = Binder.clearCallingIdentity();
6463 try {
6464 mTelephonySharedPreferences.edit()
6465 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6466 .commit();
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 @Override
6473 public boolean isMultisimCarrierRestricted() {
6474 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
6478 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6479 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6480 if (numPhysicalSlots < 2) {
6481 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6482 return true;
6483 }
6484
6485 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6486 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
6490 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006491
6492 /**
6493 * Switch configs to enable multi-sim or switch back to single-sim
6494 * @param numOfSims number of active sims we want to switch to
6495 */
6496 @Override
6497 public void switchMultiSimConfig(int numOfSims) {
6498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6499 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6500 final long identity = Binder.clearCallingIdentity();
6501 try {
6502 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
6509 * Get how many sims have been activated on the phone
6510 */
6511 @Override
6512 public int getNumOfActiveSims() {
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 return mPhoneConfigurationManager.getNumOfActiveSims();
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006520
6521 /**
6522 * Get whether reboot is required or not after making changes to modem configurations.
6523 * Return value defaults to false
6524 */
6525 @Override
6526 public boolean isRebootRequiredForModemConfigChange() {
6527 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6528 final long identity = Binder.clearCallingIdentity();
6529 try {
6530 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006536}