blob: 2ea0b665b6b521ccf7954c455d048c5c9b920953 [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100136import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700137import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700140import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800141import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700142import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700143import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700144import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700145import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700146import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700148import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700149import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800150import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700152import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800153import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700154import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800155import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700156import com.android.internal.telephony.imsphone.ImsPhone;
157import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800158import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700159import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.IccIoResult;
161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800880 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
1104 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1114 ? new CdmaCellLocation() : new GsmCellLocation();
1115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
Naina Nallurid63128d2019-09-17 14:10:30 -07001222 case CMD_ERASE_MODEM_CONFIG:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1225 defaultPhone.eraseModemConfig(onCompleted);
1226 break;
1227 case EVENT_ERASE_MODEM_CONFIG_DONE:
1228 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001229 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 default:
1231 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1232 break;
1233 }
1234 }
Jake Hambye994d462014-02-03 13:10:13 -08001235
Pengquan Menga1bb6272018-09-06 09:59:22 -07001236 private void notifyRequester(MainThreadRequest request) {
1237 synchronized (request) {
1238 request.notifyAll();
1239 }
1240 }
1241
Jake Hambye994d462014-02-03 13:10:13 -08001242 private void handleNullReturnEvent(Message msg, String command) {
1243 AsyncResult ar = (AsyncResult) msg.obj;
1244 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1245 if (ar.exception == null) {
1246 request.result = true;
1247 } else {
1248 request.result = false;
1249 if (ar.exception instanceof CommandException) {
1250 loge(command + ": CommandException: " + ar.exception);
1251 } else {
1252 loge(command + ": Unknown exception");
1253 }
1254 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001255 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
1259 /**
1260 * Posts the specified command to be executed on the main thread,
1261 * waits for the request to complete, and returns the result.
1262 * @see #sendRequestAsync
1263 */
1264 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001265 return sendRequest(
1266 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001267 }
1268
1269 /**
1270 * Posts the specified command to be executed on the main thread,
1271 * waits for the request to complete, and returns the result.
1272 * @see #sendRequestAsync
1273 */
1274 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1275 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001276 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
1279 /**
1280 * Posts the specified command to be executed on the main thread,
1281 * waits for the request to complete, and returns the result.
1282 * @see #sendRequestAsync
1283 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001284 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001285 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001286 }
1287
1288 /**
1289 * Posts the specified command to be executed on the main thread,
1290 * waits for the request to complete, and returns the result.
1291 * @see #sendRequestAsync
1292 */
Nathan Harold92bed182018-10-12 18:16:49 -07001293 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1294 return sendRequest(command, argument, subId, null, workSource);
1295 }
1296
1297 /**
1298 * Posts the specified command to be executed on the main thread,
1299 * waits for the request to complete, and returns the result.
1300 * @see #sendRequestAsync
1301 */
1302 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1303 return sendRequest(
1304 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1305 }
1306
1307 /**
1308 * Posts the specified command to be executed on the main thread,
1309 * waits for the request to complete, and returns the result.
1310 * @see #sendRequestAsync
1311 */
1312 private Object sendRequest(
1313 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1315 throw new RuntimeException("This method will deadlock if called from the main thread.");
1316 }
1317
Nathan Harold92bed182018-10-12 18:16:49 -07001318 MainThreadRequest request = null;
1319 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1320 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1321 } else if (phone != null) {
1322 request = new MainThreadRequest(argument, phone, workSource);
1323 } else {
1324 request = new MainThreadRequest(argument, subId, workSource);
1325 }
1326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 Message msg = mMainThreadHandler.obtainMessage(command, request);
1328 msg.sendToTarget();
1329
1330 // Wait for the request to complete
1331 synchronized (request) {
1332 while (request.result == null) {
1333 try {
1334 request.wait();
1335 } catch (InterruptedException e) {
1336 // Do nothing, go back and wait until the request is complete
1337 }
1338 }
1339 }
1340 return request.result;
1341 }
1342
1343 /**
1344 * Asynchronous ("fire and forget") version of sendRequest():
1345 * Posts the specified command to be executed on the main thread, and
1346 * returns immediately.
1347 * @see #sendRequest
1348 */
1349 private void sendRequestAsync(int command) {
1350 mMainThreadHandler.sendEmptyMessage(command);
1351 }
1352
1353 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001354 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001355 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 */
1357 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001358 sendRequestAsync(command, argument, null, null);
1359 }
1360
1361 /**
1362 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1363 * @see {@link #sendRequest(int,Object)}
1364 */
1365 private void sendRequestAsync(
1366 int command, Object argument, Phone phone, WorkSource workSource) {
1367 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001368 Message msg = mMainThreadHandler.obtainMessage(command, request);
1369 msg.sendToTarget();
1370 }
1371
1372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 * Initialize the singleton PhoneInterfaceManager instance.
1374 * This is only done once, at startup, from PhoneApp.onCreate().
1375 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 synchronized (PhoneInterfaceManager.class) {
1378 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 } else {
1381 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1382 }
1383 return sInstance;
1384 }
1385 }
1386
1387 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001388 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001391 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1393 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001394 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001395 mTelephonySharedPreferences =
1396 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001397 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001398 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 publish();
1401 }
1402
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001403 private Phone getDefaultPhone() {
1404 Phone thePhone = getPhone(getDefaultSubscription());
1405 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1406 }
1407
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 private void publish() {
1409 if (DBG) log("publish: " + this);
1410
1411 ServiceManager.addService("phone", this);
1412 }
1413
Stuart Scott584921c2015-01-15 17:10:34 -08001414 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001415 if (request.phone != null) {
1416 return request.phone;
1417 } else {
1418 return getPhoneFromSubId(request.subId);
1419 }
1420 }
1421
1422 private Phone getPhoneFromSubId(int subId) {
1423 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1424 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001425 }
1426
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001427 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1428 Phone phone = getPhoneFromRequest(request);
1429 return phone == null ? null :
1430 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1431 }
1432
Wink Saville36469e72014-06-11 15:17:00 -07001433 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001434 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001435 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437
Naina Nallurid63128d2019-09-17 14:10:30 -07001438 private void sendEraseModemConfig(Phone phone) {
1439 if (phone != null) {
1440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1441 mApp, phone.getSubId(), "eraseModemConfig");
1442 final long identity = Binder.clearCallingIdentity();
1443 try {
1444 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1445 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
1448 }
1449 }
1450 }
1451
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001454 }
1455
Wink Savilleb564aae2014-10-23 10:18:09 -07001456 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 if (DBG) log("dial: " + number);
1458 // No permission check needed here: This is just a wrapper around the
1459 // ACTION_DIAL intent, which is available to any app since it puts up
1460 // the UI before it does anything.
1461
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001462 final long identity = Binder.clearCallingIdentity();
1463 try {
1464 String url = createTelUrl(number);
1465 if (url == null) {
1466 return;
1467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001469 // PENDING: should we just silently fail if phone is offhook or ringing?
1470 PhoneConstants.State state = mCM.getState(subId);
1471 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1472 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1473 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1474 mApp.startActivity(intent);
1475 }
1476 } finally {
1477 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479 }
1480
1481 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001482 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Wink Savilleb564aae2014-10-23 10:18:09 -07001485 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 if (DBG) log("call: " + number);
1487
1488 // This is just a wrapper around the ACTION_CALL intent, but we still
1489 // need to do a permission check since we're calling startActivity()
1490 // from the context of the phone app.
1491 enforceCallPermission();
1492
Jordan Liu1617b712019-07-10 15:06:26 -07001493 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 != AppOpsManager.MODE_ALLOWED) {
1495 return;
1496 }
1497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001498 final long identity = Binder.clearCallingIdentity();
1499 try {
1500 String url = createTelUrl(number);
1501 if (url == null) {
1502 return;
1503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001505 boolean isValid = false;
1506 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1507 if (slist != null) {
1508 for (SubscriptionInfo subInfoRecord : slist) {
1509 if (subInfoRecord.getSubscriptionId() == subId) {
1510 isValid = true;
1511 break;
1512 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001513 }
Wink Saville08874612014-08-31 19:19:58 -07001514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001515 if (!isValid) {
1516 return;
1517 }
Wink Saville08874612014-08-31 19:19:58 -07001518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1520 intent.putExtra(SUBSCRIPTION_KEY, subId);
1521 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1522 mApp.startActivity(intent);
1523 } finally {
1524 Binder.restoreCallingIdentity(identity);
1525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001529 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001534 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1535 }
1536
1537 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001538 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001543 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1544 }
1545
1546 /** {@hide} */
1547 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001548 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001549 }
1550
Wink Savilleb564aae2014-10-23 10:18:09 -07001551 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001553
1554 final long identity = Binder.clearCallingIdentity();
1555 try {
1556 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1557 checkSimPin.start();
1558 return checkSimPin.unlockSim(null, pin);
1559 } finally {
1560 Binder.restoreCallingIdentity(identity);
1561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Wink Saville9de0f752013-10-22 19:04:03 -07001564 /** {@hide} */
1565 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001566 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001567 }
1568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1575 checkSimPuk.start();
1576 return checkSimPuk.unlockSim(puk, pin);
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
1579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
1582 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001583 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 * a synchronous one.
1585 */
1586 private static class UnlockSim extends Thread {
1587
1588 private final IccCard mSimCard;
1589
1590 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001591 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1592 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593
1594 // For replies from SimCard interface
1595 private Handler mHandler;
1596
1597 // For async handler to identify request type
1598 private static final int SUPPLY_PIN_COMPLETE = 100;
1599
1600 public UnlockSim(IccCard simCard) {
1601 mSimCard = simCard;
1602 }
1603
1604 @Override
1605 public void run() {
1606 Looper.prepare();
1607 synchronized (UnlockSim.this) {
1608 mHandler = new Handler() {
1609 @Override
1610 public void handleMessage(Message msg) {
1611 AsyncResult ar = (AsyncResult) msg.obj;
1612 switch (msg.what) {
1613 case SUPPLY_PIN_COMPLETE:
1614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001616 mRetryCount = msg.arg1;
1617 if (ar.exception != null) {
1618 if (ar.exception instanceof CommandException &&
1619 ((CommandException)(ar.exception)).getCommandError()
1620 == CommandException.Error.PASSWORD_INCORRECT) {
1621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1622 } else {
1623 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1624 }
1625 } else {
1626 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 mDone = true;
1629 UnlockSim.this.notifyAll();
1630 }
1631 break;
1632 }
1633 }
1634 };
1635 UnlockSim.this.notifyAll();
1636 }
1637 Looper.loop();
1638 }
1639
1640 /*
1641 * Use PIN or PUK to unlock SIM card
1642 *
1643 * If PUK is null, unlock SIM card with PIN
1644 *
1645 * If PUK is not null, unlock SIM card with PUK and set PIN code
1646 */
Wink Saville9de0f752013-10-22 19:04:03 -07001647 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648
1649 while (mHandler == null) {
1650 try {
1651 wait();
1652 } catch (InterruptedException e) {
1653 Thread.currentThread().interrupt();
1654 }
1655 }
1656 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1657
1658 if (puk == null) {
1659 mSimCard.supplyPin(pin, callback);
1660 } else {
1661 mSimCard.supplyPuk(puk, pin, callback);
1662 }
1663
1664 while (!mDone) {
1665 try {
1666 Log.d(LOG_TAG, "wait for done");
1667 wait();
1668 } catch (InterruptedException e) {
1669 // Restore the interrupted status
1670 Thread.currentThread().interrupt();
1671 }
1672 }
1673 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001674 int[] resultArray = new int[2];
1675 resultArray[0] = mResult;
1676 resultArray[1] = mRetryCount;
1677 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679 }
1680
1681 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001682 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001683
1684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 // No permission check needed here: this call is harmless, and it's
1688 // needed for the ServiceState.requestStateUpdate() call (which is
1689 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
1694 phone.updateServiceLocation();
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001701 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001704 return isRadioOnWithFeature(callingPackage, null);
1705 }
1706
1707
1708 @Override
1709 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1710 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1711 callingFeatureId);
1712 }
1713
1714 @Deprecated
1715 @Override
1716 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1717 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001720 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001721 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1722 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001724 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 return false;
1726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727
1728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 return isRadioOnForSubscriber(subId);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001734 }
1735
1736 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 final long identity = Binder.clearCallingIdentity();
1738 try {
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
1741 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
1750 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001751 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
1768 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 final Phone phone = getPhone(subId);
1778 if (phone == null) {
1779 return false;
1780 }
1781 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1782 toggleRadioOnOffForSubscriber(subId);
1783 }
1784 return true;
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Wink Saville36469e72014-06-11 15:17:00 -07001789
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001790 public boolean needMobileRadioShutdown() {
1791 /*
1792 * If any of the Radios are available, it will need to be
1793 * shutdown. So return true if any Radio is available.
1794 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 final long identity = Binder.clearCallingIdentity();
1796 try {
1797 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1798 Phone phone = PhoneFactory.getPhone(i);
1799 if (phone != null && phone.isRadioAvailable()) return true;
1800 }
1801 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1802 return false;
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001805 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001806 }
1807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 enforceModifyPermission();
1811
1812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1815 logv("Shutting down Phone " + i);
1816 shutdownRadioUsingPhoneId(i);
1817 }
1818 } finally {
1819 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001820 }
1821 }
1822
1823 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001824 Phone phone = PhoneFactory.getPhone(phoneId);
1825 if (phone != null && phone.isRadioAvailable()) {
1826 phone.shutdownRadio();
1827 }
1828 }
1829
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1836 if (defaultPhone != null) {
1837 defaultPhone.setRadioPower(turnOn);
1838 return true;
1839 } else {
1840 loge("There's no default phone.");
1841 return false;
1842 }
1843 } finally {
1844 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001845 }
Wink Saville36469e72014-06-11 15:17:00 -07001846 }
1847
Wink Savilleb564aae2014-10-23 10:18:09 -07001848 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850
1851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 final Phone phone = getPhone(subId);
1854 if (phone != null) {
1855 phone.setRadioPower(turnOn);
1856 return true;
1857 } else {
1858 return false;
1859 }
1860 } finally {
1861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
Wink Saville36469e72014-06-11 15:17:00 -07001865 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 public boolean enableDataConnectivity() {
1868 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869
1870 final long identity = Binder.clearCallingIdentity();
1871 try {
1872 int subId = mSubscriptionController.getDefaultDataSubId();
1873 final Phone phone = getPhone(subId);
1874 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001875 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001876 return true;
1877 } else {
1878 return false;
1879 }
1880 } finally {
1881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Wink Saville36469e72014-06-11 15:17:00 -07001885 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 public boolean disableDataConnectivity() {
1888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889
1890 final long identity = Binder.clearCallingIdentity();
1891 try {
1892 int subId = mSubscriptionController.getDefaultDataSubId();
1893 final Phone phone = getPhone(subId);
1894 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001895 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896 return true;
1897 } else {
1898 return false;
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001906 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001907 final long identity = Binder.clearCallingIdentity();
1908 try {
1909 final Phone phone = getPhone(subId);
1910 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001911 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 } else {
1913 return false;
1914 }
1915 } finally {
1916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 }
1919
1920 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001921 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
pkanwarae03a6b2016-11-06 20:37:09 -08001924 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001925 enforceCallPermission();
1926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1930 return;
1931 }
1932 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1933 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
1936 }
pkanwar32d516d2016-10-14 19:37:38 -07001937 };
1938
Wink Savilleb564aae2014-10-23 10:18:09 -07001939 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001941
1942 final long identity = Binder.clearCallingIdentity();
1943 try {
1944 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1945 return false;
1946 }
1947 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1948 } finally {
1949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001954 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001957 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 final long identity = Binder.clearCallingIdentity();
1959 try {
1960 Phone phone = PhoneFactory.getPhone(slotIndex);
1961 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1962 PhoneConstantConversions.convertCallState(phone.getState());
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001969 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001970 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1971 }
1972
1973 @Override
1974 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 final long identity = Binder.clearCallingIdentity();
1976 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001977 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978 if (phone != null) {
1979 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1980 } else {
1981 return PhoneConstantConversions.convertDataState(
1982 PhoneConstants.DataState.DISCONNECTED);
1983 }
1984 } finally {
1985 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001990 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001991 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1992 }
1993
1994 @Override
1995 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 final long identity = Binder.clearCallingIdentity();
1997 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001998 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 if (phone != null) {
2000 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2001 } else {
2002 return TelephonyManager.DATA_ACTIVITY_NONE;
2003 }
2004 } finally {
2005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
2009 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002010 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002011 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002012 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002013
2014 LocationAccessPolicy.LocationPermissionResult locationResult =
2015 LocationAccessPolicy.checkLocationPermission(mApp,
2016 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2017 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002018 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002019 .setCallingPid(Binder.getCallingPid())
2020 .setCallingUid(Binder.getCallingUid())
2021 .setMethod("getCellLocation")
2022 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2023 .build());
2024 switch (locationResult) {
2025 case DENIED_HARD:
2026 throw new SecurityException("Not allowed to access cell location");
2027 case DENIED_SOFT:
2028 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 }
2030
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002031 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 final long identity = Binder.clearCallingIdentity();
2033 try {
2034 if (DBG_LOC) log("getCellLocation: is active user");
2035 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002036 int subId = mSubscriptionController.getDefaultDataSubId();
2037 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2038 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 return data;
2040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Svetoslav64fad262015-04-14 14:35:21 -07002043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002046 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2047 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002048 if (!TextUtils.isEmpty(callingPackage)) {
2049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2051 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002052 return "";
2053 }
2054 }
2055
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002056 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2057 // registered cell info, so return a NULL country instead.
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002060 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2061 // Get default phone in this case.
2062 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2063 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002064 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002065 // Todo: fix this when we can get the actual cellular network info when the device
2066 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002067 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002068 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2069 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 return "";
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 Phone phone = PhoneFactory.getPhone(phoneId);
2073 if (phone != null) {
2074 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002075 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 if (sst != null) {
2077 LocaleTracker lt = sst.getLocaleTracker();
2078 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002079 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2080 return lt.getCurrentCountry();
2081 } else if (emergencyNumberTracker != null) {
2082 return emergencyNumberTracker.getEmergencyCountryIso();
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 }
2085 }
2086 }
2087 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002091 }
2092
2093 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002095 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002096 }
2097
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mApp.enforceCallingOrSelfPermission(
2101 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.enableLocationUpdates();
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 @Override
2115 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002120 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 mApp.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123
2124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 phone.disableLocationUpdates();
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 /**
2136 * Returns the target SDK version number for a given package name.
2137 *
Nathan Haroldec184742019-07-10 17:04:16 -07002138 * This call MUST be invoked before clearing the calling UID.
2139 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002140 * @return target SDK if the package is found or INT_MAX.
2141 */
2142 private int getTargetSdk(String packageName) {
2143 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002144 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002145 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 if (ai != null) return ai.targetSdkVersion;
2147 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002148 loge("Failed to get package info for pkg="
2149 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002150 }
2151 return Integer.MAX_VALUE;
2152 }
2153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 @Override
2155 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002156 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2157 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002158 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002159 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2160 throw new SecurityException(
2161 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2162 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002163
Jordan Liu1617b712019-07-10 15:06:26 -07002164 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2166 return null;
2167 }
Svetoslav64fad262015-04-14 14:35:21 -07002168
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002169 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002171 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002172 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2175 for (CellInfo ci : info) {
2176 if (ci instanceof CellInfoGsm) {
2177 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2178 } else if (ci instanceof CellInfoWcdma) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002182 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 private List<CellInfo> getCachedCellInfo() {
2186 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2187 for (Phone phone : PhoneFactory.getPhones()) {
2188 List<CellInfo> info = phone.getAllCellInfo();
2189 if (info != null) cellInfos.addAll(info);
2190 }
2191 return cellInfos;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193
2194 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002195 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002196 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002197 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002198
2199 LocationAccessPolicy.LocationPermissionResult locationResult =
2200 LocationAccessPolicy.checkLocationPermission(mApp,
2201 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2202 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002203 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002204 .setCallingPid(Binder.getCallingPid())
2205 .setCallingUid(Binder.getCallingUid())
2206 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002207 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002208 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2209 .build());
2210 switch (locationResult) {
2211 case DENIED_HARD:
2212 throw new SecurityException("Not allowed to access cell info");
2213 case DENIED_SOFT:
2214 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002217 final int targetSdk = getTargetSdk(callingPackage);
2218 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2219 return getCachedCellInfo();
2220 }
2221
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002222 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2227 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002228 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002229 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 if (info != null) cellInfos.addAll(info);
2231 }
2232 return cellInfos;
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236 }
2237
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002238 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002239 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2240 String callingFeatureId) {
2241 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2242 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 }
2244
2245 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002246 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2247 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002248 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002249 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 }
2251
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002252 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2253 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002254 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002255 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002256
2257 LocationAccessPolicy.LocationPermissionResult locationResult =
2258 LocationAccessPolicy.checkLocationPermission(mApp,
2259 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2260 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002261 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002262 .setCallingPid(Binder.getCallingPid())
2263 .setCallingUid(Binder.getCallingUid())
2264 .setMethod("requestCellInfoUpdate")
2265 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2266 .build());
2267 switch (locationResult) {
2268 case DENIED_HARD:
2269 throw new SecurityException("Not allowed to access cell info");
2270 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002271 try {
2272 cb.onCellInfo(new ArrayList<CellInfo>());
2273 } catch (RemoteException re) {
2274 // Drop without consequences
2275 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002276 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002277 }
2278
Nathan Harolda939a962019-05-09 10:13:47 -07002279
2280 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002281 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2282
2283 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2284 }
2285
2286 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002288 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002293 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002300 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002301 Phone phone = PhoneFactory.getPhone(slotIndex);
2302 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 return null;
2304 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002305 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002306 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002307 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 return null;
2309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 return phone.getImei();
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 }
2318
2319 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002320 public String getTypeAllocationCodeForSlot(int slotIndex) {
2321 Phone phone = PhoneFactory.getPhone(slotIndex);
2322 String tac = null;
2323 if (phone != null) {
2324 String imei = phone.getImei();
2325 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2326 }
2327 return tac;
2328 }
2329
2330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002331 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 Phone phone = PhoneFactory.getPhone(slotIndex);
2333 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002334 return null;
2335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002336
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002338 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002339 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002340 return null;
2341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return phone.getMeid();
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Jack Yu2af8d712017-03-15 17:14:14 -07002349 }
2350
2351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002352 public String getManufacturerCodeForSlot(int slotIndex) {
2353 Phone phone = PhoneFactory.getPhone(slotIndex);
2354 String manufacturerCode = null;
2355 if (phone != null) {
2356 String meid = phone.getMeid();
2357 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2358 }
2359 return manufacturerCode;
2360 }
2361
2362 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002363 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2364 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002365 Phone phone = PhoneFactory.getPhone(slotIndex);
2366 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002367 return null;
2368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002369 int subId = phone.getSubId();
2370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002371 mApp, subId, callingPackage, callingFeatureId,
2372 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 return null;
2374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 return phone.getDeviceSvn();
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002382 }
2383
fionaxu43304da2017-11-27 22:51:16 -08002384 @Override
2385 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 final Phone phone = getPhone(subId);
2389 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
fionaxu43304da2017-11-27 22:51:16 -08002393 }
2394
2395 @Override
2396 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 return phone == null ? null : phone.getCarrierName();
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
fionaxu43304da2017-11-27 22:51:16 -08002404 }
2405
calvinpanffe225e2018-11-01 19:43:06 +08002406 @Override
chen xu0026ca62019-03-06 15:28:50 -08002407 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002412 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
2418 @Override
chen xu0026ca62019-03-06 15:28:50 -08002419 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002423 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
2427 }
2428
chen xu651eec72018-11-11 19:03:44 -08002429 @Override
chen xu864e11c2018-12-06 22:10:03 -08002430 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2431 if (!isSubscriptionMccMnc) {
2432 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2433 }
chen xu651eec72018-11-11 19:03:44 -08002434 final Phone phone = PhoneFactory.getPhone(slotIndex);
2435 if (phone == null) {
2436 return TelephonyManager.UNKNOWN_CARRIER_ID;
2437 }
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
2444 }
2445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 //
2447 // Internal helper methods.
2448 //
2449
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002450 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2452 *
2453 * @throws SecurityException if the caller does not have the required permission
2454 */
2455 private void enforceModifyPermission() {
2456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2457 }
2458
2459 /**
2460 * Make sure the caller has the CALL_PHONE permission.
2461 *
2462 * @throws SecurityException if the caller does not have the required permission
2463 */
2464 private void enforceCallPermission() {
2465 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2466 }
2467
Stuart Scott8eef64f2015-04-08 15:13:54 -07002468 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002470 "ConnectivityService");
2471 }
2472
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 private String createTelUrl(String number) {
2474 if (TextUtils.isEmpty(number)) {
2475 return null;
2476 }
2477
Jake Hambye994d462014-02-03 13:10:13 -08002478 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
Ihab Awadf9e92732013-12-05 18:02:52 -08002481 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2483 }
2484
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002485 private static void logv(String msg) {
2486 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2487 }
2488
Ihab Awadf9e92732013-12-05 18:02:52 -08002489 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2491 }
2492
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002493 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002495 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002496 }
2497
Sanket Padawe356d7632015-06-22 14:03:32 -07002498 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002499 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = PhoneFactory.getPhone(slotIndex);
2503 if (phone == null) {
2504 return PhoneConstants.PHONE_TYPE_NONE;
2505 } else {
2506 return phone.getPhoneType();
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
2514 * Returns the CDMA ERI icon index to display
2515 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002517 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2518 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2519 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002523 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2524 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002526 mApp, subId, callingPackage, callingFeatureId,
2527 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002528 return -1;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 final Phone phone = getPhone(subId);
2534 if (phone != null) {
2535 return phone.getCdmaEriIconIndex();
2536 } else {
2537 return -1;
2538 }
2539 } finally {
2540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
2543
2544 /**
2545 * Returns the CDMA ERI icon mode,
2546 * 0 - ON
2547 * 1 - FLASHING
2548 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002550 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2551 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2552 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002553 }
2554
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002556 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2557 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002559 mApp, subId, callingPackage, callingFeatureId,
2560 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002561 return -1;
2562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 final Phone phone = getPhone(subId);
2567 if (phone != null) {
2568 return phone.getCdmaEriIconMode();
2569 } else {
2570 return -1;
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576
2577 /**
2578 * Returns the CDMA ERI text,
2579 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002581 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2582 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2583 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Sanket Padawe356d7632015-06-22 14:03:32 -07002586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002587 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2588 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002590 mApp, subId, callingPackage, callingFeatureId,
2591 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002592 return null;
2593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone != null) {
2599 return phone.getCdmaEriText();
2600 } else {
2601 return null;
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
2607
2608 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002609 * Returns the CDMA MDN.
2610 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002611 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002612 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2614 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002619 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 return phone.getLine1Number();
2621 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 return null;
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002627 }
2628 }
2629
2630 /**
2631 * Returns the CDMA MIN.
2632 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002634 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2636 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2642 return phone.getCdmaMin();
2643 } else {
2644 return null;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002648 }
2649 }
2650
Hall Liud892bec2018-11-30 14:51:45 -08002651 @Override
2652 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2653 INumberVerificationCallback callback, String callingPackage) {
2654 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2655 != PERMISSION_GRANTED) {
2656 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2657 }
2658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2659
2660 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2661 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2662 throw new SecurityException("Calling package must be configured in the device config");
2663 }
2664
2665 if (range == null) {
2666 throw new NullPointerException("Range must be non-null");
2667 }
2668
2669 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002670 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002671
2672 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2673 }
2674
Junda Liuca05d5d2014-08-14 22:36:34 -07002675 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 * Returns true if CDMA provisioning needs to run.
2677 */
2678 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002681 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
2687 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002688 * Sets the voice mail number of a given subId.
2689 */
2690 @Override
2691 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002692 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693
2694 final long identity = Binder.clearCallingIdentity();
2695 try {
2696 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2697 new Pair<String, String>(alphaTag, number), new Integer(subId));
2698 return success;
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002702 }
2703
Ta-wei Yen87c49842016-05-13 21:19:52 -07002704 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002705 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002707 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2708 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 if (!TextUtils.equals(callingPackage, systemDialer)) {
2710 throw new SecurityException("caller must be system dialer");
2711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2716 if (phoneAccountHandle == null) {
2717 return null;
2718 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002719 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002722 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002723 }
2724
2725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002726 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2727 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002730 mApp, subId, callingPackage, callingFeatureId,
2731 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 return null;
2733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002735 final long identity = Binder.clearCallingIdentity();
2736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002738 } finally {
2739 Binder.restoreCallingIdentity(identity);
2740 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002741 }
2742
2743 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002744 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2745 VisualVoicemailSmsFilterSettings settings) {
2746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002755 }
2756
2757 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002758 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002768 }
2769
2770 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002771 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2772 String callingPackage, int subId) {
2773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002778 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002782 }
2783
2784 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002785 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002786 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
2790 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002791 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002795 }
2796
2797 @Override
2798 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2799 String number, int port, String text, PendingIntent sentIntent) {
2800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002801 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002803 SmsController smsController = PhoneFactory.getSmsController();
2804 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2805 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002806 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002808 /**
fionaxu0152e512016-11-14 13:36:14 -08002809 * Sets the voice activation state of a given subId.
2810 */
2811 @Override
2812 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2814 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
2820 phone.setVoiceActivationState(activationState);
2821 } else {
2822 loge("setVoiceActivationState fails with invalid subId: " + subId);
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002826 }
2827 }
2828
2829 /**
2830 * Sets the data activation state of a given subId.
2831 */
2832 @Override
2833 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2835 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 if (phone != null) {
2841 phone.setDataActivationState(activationState);
2842 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002843 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002847 }
2848 }
2849
2850 /**
2851 * Returns the voice activation state of a given subId.
2852 */
2853 @Override
2854 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
fionaxu0152e512016-11-14 13:36:14 -08002857 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 if (phone != null) {
2861 return phone.getVoiceActivationState();
2862 } else {
2863 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002867 }
2868 }
2869
2870 /**
2871 * Returns the data activation state of a given subId.
2872 */
2873 @Override
2874 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002875 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
fionaxu0152e512016-11-14 13:36:14 -08002877 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 if (phone != null) {
2881 return phone.getDataActivationState();
2882 } else {
2883 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002887 }
2888 }
2889
2890 /**
Wink Saville36469e72014-06-11 15:17:00 -07002891 * Returns the unread count of voicemails for a subId
2892 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002894 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2895 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002897 mApp, subId, callingPackage, callingFeatureId,
2898 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002899 return 0;
2900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
2905 return phone.getVoiceMessageCount();
2906 } else {
2907 return 0;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
2914 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002915 * returns true, if the device is in a state where both voice and data
2916 * are supported simultaneously. This can change based on location or network condition.
2917 */
2918 @Override
2919 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 final Phone phone = getPhone(subId);
2923 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002927 }
2928
2929 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002930 * Send the dialer code if called from the current default dialer or the caller has
2931 * carrier privilege.
2932 * @param inputCode The dialer code to send
2933 */
2934 @Override
2935 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002938 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2939 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002940 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2942 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
fionaxu235cc5e2017-03-06 22:25:57 -08002951 }
2952
Pengquan Menga1bb6272018-09-06 09:59:22 -07002953 @Override
2954 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002955 if (!isActiveSubscription(subId)) {
2956 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2957 }
2958
Pengquan Menga1bb6272018-09-06 09:59:22 -07002959 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2960 }
2961
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002963 public boolean isInEmergencySmsMode() {
2964 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 for (Phone phone : PhoneFactory.getPhones()) {
2968 if (phone.isInEmergencySmsMode()) {
2969 return true;
2970 }
2971 }
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 return false;
2976 }
2977
2978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002979 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2980 throws RemoteException {
2981 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2984 "IMS not available on device.");
2985 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 final long token = Binder.clearCallingIdentity();
2987 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002991 } catch (ImsException e) {
2992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(token);
2995 }
2996 }
2997
2998 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002999 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3000 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003001 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3002 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3003 }
Meng Wangafbc5852019-09-19 17:37:13 -07003004 final long token = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3007 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3008 .removeRegistrationCallbackForSubscription(c, subId);
3009 } catch (ImsException e) {
3010 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3011 + "is inactive, ignoring unregister.");
3012 // If the subscription is no longer active, just return, since the callback
3013 // will already have been removed internally.
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 }
3018
Brad Ebingera34a6c22019-10-22 17:36:18 -07003019 /**
3020 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3021 */
3022 @Override
3023 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3024 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3025 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3027 "IMS not available on device.");
3028 }
3029 final long token = Binder.clearCallingIdentity();
3030 try {
3031 Phone phone = getPhone(subId);
3032 if (phone == null) {
3033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3034 + subId + "'");
3035 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3036 }
3037 phone.getImsRegistrationState(regState -> {
3038 try {
3039 consumer.accept((regState == null)
3040 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3041 } catch (RemoteException e) {
3042 // Ignore if the remote process is no longer available to call back.
3043 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3044 }
3045 });
3046 } finally {
3047 Binder.restoreCallingIdentity(token);
3048 }
3049 }
3050
3051 /**
3052 * Get the transport type for the IMS service registration state.
3053 */
3054 @Override
3055 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3056 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3057 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3059 "IMS not available on device.");
3060 }
3061 final long token = Binder.clearCallingIdentity();
3062 try {
3063 Phone phone = getPhone(subId);
3064 if (phone == null) {
3065 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3066 + subId + "'");
3067 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3068 }
3069 phone.getImsRegistrationTech(regTech -> {
3070 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3071 int regTechConverted = (regTech == null)
3072 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3073 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3074 regTechConverted);
3075 try {
3076 consumer.accept(regTechConverted);
3077 } catch (RemoteException e) {
3078 // Ignore if the remote process is no longer available to call back.
3079 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3080 }
3081 });
3082 } finally {
3083 Binder.restoreCallingIdentity(token);
3084 }
3085 }
3086
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003088 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3089 throws RemoteException {
3090 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003091 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3092 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3093 "IMS not available on device.");
3094 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3096 final long token = Binder.clearCallingIdentity();
3097 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003100 } catch (ImsException e) {
3101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 } finally {
3103 Binder.restoreCallingIdentity(token);
3104 }
3105 }
3106
3107 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003108 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3109 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3111 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3112 }
Meng Wangafbc5852019-09-19 17:37:13 -07003113
3114 final long token = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3117 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003118 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003119 } catch (ImsException e) {
3120 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3121 + "is inactive, ignoring unregister.");
3122 // If the subscription is no longer active, just return, since the callback
3123 // will already have been removed internally.
3124 } finally {
3125 Binder.restoreCallingIdentity(token);
3126 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 }
3128
3129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003130 public boolean isCapable(int subId, int capability, int regTech) {
3131 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3133 final long token = Binder.clearCallingIdentity();
3134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003137 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3139 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003140 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003141 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3142 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 } finally {
3144 Binder.restoreCallingIdentity(token);
3145 }
3146 }
3147
3148 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003149 public boolean isAvailable(int subId, int capability, int regTech) {
3150 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 final long token = Binder.clearCallingIdentity();
3152 try {
3153 Phone phone = getPhone(subId);
3154 if (phone == null) return false;
3155 return phone.isImsCapabilityAvailable(capability, regTech);
3156 } finally {
3157 Binder.restoreCallingIdentity(token);
3158 }
3159 }
3160
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003161 /**
3162 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3163 * subscription.
3164 * @param subId The subscription to use to check the configuration.
3165 * @param callback The callback that will be used to send the result.
3166 * @param capability The MmTelFeature capability that will be used to send the result.
3167 * @param transportType The transport type of the MmTelFeature capability.
3168 */
3169 @Override
3170 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3171 int transportType) {
3172 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3175 "IMS not available on device.");
3176 }
3177 final long token = Binder.clearCallingIdentity();
3178 try {
3179 int slotId = getSlotIndex(subId);
3180 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3181 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3182 + subId + "'");
3183 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3184 }
3185 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3186 transportType, aBoolean -> {
3187 try {
3188 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3189 } catch (RemoteException e) {
3190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3191 + "running. Ignore");
3192 }
3193 });
3194 } finally {
3195 Binder.restoreCallingIdentity(token);
3196 }
3197 }
3198
Brad Ebinger35c841c2018-10-01 10:40:55 -07003199 @Override
3200 public boolean isAdvancedCallingSettingEnabled(int subId) {
3201 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3203 final long token = Binder.clearCallingIdentity();
3204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003207 } catch (ImsException e) {
3208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 } finally {
3210 Binder.restoreCallingIdentity(token);
3211 }
3212 }
3213
3214 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003215 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003217 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 } catch (ImsException e) {
3224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003231 public boolean isVtSettingEnabled(int subId) {
3232 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003236 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3237 } catch (ImsException e) {
3238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 }
3243
3244 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003245 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003247 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003251 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003252 } catch (ImsException e) {
3253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 } finally {
3255 Binder.restoreCallingIdentity(identity);
3256 }
3257 }
3258
3259 @Override
3260 public boolean isVoWiFiSettingEnabled(int subId) {
3261 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003265 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (ImsException e) {
3268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
3272 }
3273
3274 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003275 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003277 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003282 } catch (ImsException e) {
3283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
3287 }
3288
3289 @Override
3290 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3291 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003305 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003307 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003313 } catch (ImsException e) {
3314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3323 "setVoWiFiNonPersistent");
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003327 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003328 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003329 } catch (ImsException e) {
3330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
3336 @Override
3337 public int getVoWiFiModeSetting(int subId) {
3338 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003342 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003344 } catch (ImsException e) {
3345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
3351 @Override
3352 public void setVoWiFiModeSetting(int subId, int mode) {
3353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3354 "setVoWiFiModeSetting");
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003358 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003360 } catch (ImsException e) {
3361 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
3365 }
3366
3367 @Override
3368 public int getVoWiFiRoamingModeSetting(int subId) {
3369 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003373 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003375 } catch (ImsException e) {
3376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003377 } finally {
3378 Binder.restoreCallingIdentity(identity);
3379 }
3380 }
3381
3382 @Override
3383 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3385 "setVoWiFiRoamingModeSetting");
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (ImsException e) {
3392 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
3396 }
3397
3398 @Override
3399 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3401 "setRttCapabilityEnabled");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003405 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3406 } catch (ImsException e) {
3407 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
3411 }
3412
3413 @Override
3414 public boolean isTtyOverVolteEnabled(int subId) {
3415 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3416 final long identity = Binder.clearCallingIdentity();
3417 try {
3418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003419 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003421 } catch (ImsException e) {
3422 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 @Override
3429 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3430 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003434 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003435 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003436 } catch (ImsException e) {
3437 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
3443 @Override
3444 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3445 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3446 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003447 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3448 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3449 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003452 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003453 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003454 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003455 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3456 + "is inactive, ignoring unregister.");
3457 // If the subscription is no longer active, just return, since the callback will already
3458 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
3462 }
3463
3464 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3466 boolean isProvisioned) {
3467 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3468 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3469 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3470 }
3471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3472 "setProvisioningStatusForCapability");
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3476 Phone phone = getPhone(subId);
3477 if (phone == null) {
3478 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3479 + subId);
3480 return;
3481 }
3482 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3483 return;
3484 }
3485
3486 // this capability requires provisioning, route to the correct API.
3487 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3488 switch (capability) {
3489 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3490 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3491 ims.setVolteProvisioned(isProvisioned);
3492 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3493 ims.setWfcProvisioned(isProvisioned);
3494 }
3495 break;
3496 }
3497 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3498 // There is currently no difference in VT provisioning type.
3499 ims.setVtProvisioned(isProvisioned);
3500 break;
3501 }
3502 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3503 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3504 // change the capability of the feature instead if needed.
3505 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3506 == isProvisioned) {
3507 // No change in provisioning.
3508 return;
3509 }
3510 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3511 try {
3512 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003513 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003514 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3515 + ", Exception" + e.getMessage());
3516 }
3517 break;
3518 }
3519 default: {
3520 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3521 + capability + "', which does not require provisioning.");
3522 }
3523 }
3524
3525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
3528 }
3529
3530 @Override
3531 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3532 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3533 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3534 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3535 }
3536 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3540 Phone phone = getPhone(subId);
3541 if (phone == null) {
3542 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3543 + subId);
3544 // We will fail with "true" as the provisioning status because this is the default
3545 // if we do not require provisioning.
3546 return true;
3547 }
3548
3549 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3550 return true;
3551 }
3552
3553 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3554 switch (capability) {
3555 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3556 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3557 return ims.isVolteProvisionedOnDevice();
3558 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3559 return ims.isWfcProvisionedOnDevice();
3560 }
3561 // This should never happen, since we are checking tech above to make sure it
3562 // is either LTE or IWLAN.
3563 throw new IllegalArgumentException("Invalid radio technology for voice "
3564 + "capability.");
3565 }
3566 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3567 // There is currently no difference in VT provisioning type.
3568 return ims.isVtProvisionedOnDevice();
3569 }
3570 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3571 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3572 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3573 }
3574 default: {
3575 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3576 + capability + "', which does not require provisioning.");
3577 }
3578 }
3579
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
3583 }
3584
3585 @Override
3586 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3587 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3588 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3589 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3590 }
3591 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3592 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3593 return (provisionedBits & capability) > 0;
3594 }
3595
3596 @Override
3597 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3598 boolean isProvisioned) {
3599 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3600 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3601 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3602 }
3603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3604 "setProvisioningStatusForCapability");
3605 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3606 // If the current provisioning status for capability already matches isProvisioned,
3607 // do nothing.
3608 if (((provisionedBits & capability) > 0) == isProvisioned) {
3609 return;
3610 }
3611 if (isProvisioned) {
3612 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3613 } else {
3614 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3615 }
3616 }
3617
3618 /**
3619 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3620 * technology. The bitfield should mirror the bitfield defined by
3621 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3622 */
3623 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3624 String key = getMmTelProvisioningKey(subId, tech);
3625 // Default is no capabilities are provisioned.
3626 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3627 }
3628
3629 /**
3630 * Sets the MmTel capability provisioning bitfield (defined by
3631 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3632 * technology specified.
3633 *
3634 * Note: This is a synchronous command and should not be called on UI thread.
3635 */
3636 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3637 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3638 String key = getMmTelProvisioningKey(subId, tech);
3639 editor.putInt(key, newField);
3640 editor.commit();
3641 }
3642
3643 private static String getMmTelProvisioningKey(int subId, int tech) {
3644 // resulting key is provision_ims_mmtel_{subId}_{tech}
3645 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3646 }
3647
3648 /**
3649 * Query CarrierConfig to see if the specified capability requires provisioning for the
3650 * carrier associated with the subscription id.
3651 */
3652 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3653 int capability) {
3654 CarrierConfigManager configManager = new CarrierConfigManager(context);
3655 PersistableBundle c = configManager.getConfigForSubId(subId);
3656 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003657 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003658 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3659 false);
3660 boolean requireVoiceVtProvisioning = c.getBoolean(
3661 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3662
3663 // First check to make sure that the capability requires provisioning.
3664 switch (capability) {
3665 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3666 // intentional fallthrough
3667 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3668 if (requireVoiceVtProvisioning) {
3669 // Voice and Video requires provisioning
3670 return true;
3671 }
3672 break;
3673 }
3674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3675 if (requireUtProvisioning) {
3676 // UT requires provisioning
3677 return true;
3678 }
3679 break;
3680 }
3681 }
3682 return false;
3683 }
3684
3685 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003686 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3688 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3689 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003690 enforceReadPrivilegedPermission("getImsProvisioningInt");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 int slotId = getSlotIndex(subId);
3695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3696 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3697 + subId + "' for key:" + key);
3698 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3699 }
3700 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003701 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003702 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3703 + subId + "' for key:" + key);
3704 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
3708 }
3709
3710 @Override
3711 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3713 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3714 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003715 enforceReadPrivilegedPermission("getImsProvisioningString");
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003719 int slotId = getSlotIndex(subId);
3720 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3721 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3722 + subId + "' for key:" + key);
3723 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3724 }
3725 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003727 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3728 + subId + "' for key:" + key);
3729 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
3733 }
3734
3735 @Override
3736 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3738 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3739 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003740 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3741 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003745 int slotId = getSlotIndex(subId);
3746 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3747 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3748 + subId + "' for key:" + key);
3749 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3750 }
3751 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003752 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003753 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3754 + "' for key:" + key);
3755 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
3761 @Override
3762 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3764 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3765 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3767 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003771 int slotId = getSlotIndex(subId);
3772 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3773 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3774 + subId + "' for key:" + key);
3775 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3776 }
3777 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003778 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003779 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3780 + "' for key:" + key);
3781 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
3785 }
3786
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003787 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 int slotId = SubscriptionManager.getSlotIndex(subId);
3789 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003790 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3791 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 }
3793 return slotId;
3794 }
3795
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003796 private int getSlotIndex(int subId) {
3797 int slotId = SubscriptionManager.getSlotIndex(subId);
3798 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3799 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3800 }
3801 return slotId;
3802 }
3803
Wink Saville36469e72014-06-11 15:17:00 -07003804 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003805 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003806 */
3807 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003808 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3809 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003810 final int targetSdk = getTargetSdk(callingPackage);
3811 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003812 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003813 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003814 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003815 mApp, subId, callingPackage, callingFeatureId,
3816 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003817 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3818 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 final Phone phone = getPhone(subId);
3823 if (phone != null) {
3824 return phone.getServiceState().getDataNetworkType();
3825 } else {
3826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003831 }
3832
3833 /**
3834 * Returns the data network type
3835 */
3836 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003837 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3838 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3839 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003840 }
3841
3842 /**
3843 * Returns the data network type for a subId
3844 */
3845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003849 mApp, subId, callingPackage, callingFeatureId,
3850 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003851 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3852 }
3853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 final Phone phone = getPhone(subId);
3857 if (phone != null) {
3858 return phone.getServiceState().getDataNetworkType();
3859 } else {
3860 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3861 }
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003865 }
3866
3867 /**
Wink Saville36469e72014-06-11 15:17:00 -07003868 * Returns the Voice network type for a subId
3869 */
3870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003871 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3872 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003874 mApp, subId, callingPackage, callingFeatureId,
3875 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003876 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3877 }
3878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 final Phone phone = getPhone(subId);
3882 if (phone != null) {
3883 return phone.getServiceState().getVoiceNetworkType();
3884 } else {
3885 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3886 }
3887 } finally {
3888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003890 }
3891
3892 /**
3893 * @return true if a ICC card is present
3894 */
3895 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003896 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003897 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3898 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003899 }
3900
3901 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003902 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003903 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003904 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003905 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 final Phone phone = PhoneFactory.getPhone(slotIndex);
3909 if (phone != null) {
3910 return phone.getIccCard().hasIccCard();
3911 } else {
3912 return false;
3913 }
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003917 }
3918
3919 /**
3920 * Return if the current radio is LTE on CDMA. This
3921 * is a tri-state return value as for a period of time
3922 * the mode may be unknown.
3923 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003924 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003925 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003926 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003927 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003929 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3930 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3931 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003932 }
3933
Sanket Padawe356d7632015-06-22 14:03:32 -07003934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3936 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003938 mApp, subId, callingPackage, callingFeatureId,
3939 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003940 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3941 }
3942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 final Phone phone = getPhone(subId);
3946 if (phone == null) {
3947 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3948 } else {
3949 return phone.getLteOnCdmaMode();
3950 }
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003953 }
Wink Saville36469e72014-06-11 15:17:00 -07003954 }
3955
Wink Saville36469e72014-06-11 15:17:00 -07003956 /**
3957 * {@hide}
3958 * Returns Default subId, 0 in the case of single standby.
3959 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003960 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003961 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003962 }
3963
Shishir Agrawala9f32182016-04-12 12:00:16 -07003964 private int getSlotForDefaultSubscription() {
3965 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3966 }
3967
Wink Savilleb564aae2014-10-23 10:18:09 -07003968 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003969 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003970 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003971
Pengquan Menge92a50d2018-09-21 15:54:48 -07003972 private boolean isActiveSubscription(int subId) {
3973 return mSubscriptionController.isActiveSubId(subId);
3974 }
3975
Ihab Awadf2177b72013-11-25 13:33:23 -08003976 /**
3977 * @see android.telephony.TelephonyManager.WifiCallingChoices
3978 */
3979 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 final long identity = Binder.clearCallingIdentity();
3981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3984 getWhenToMakeWifiCallsDefaultPreference());
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003988 }
3989
3990 /**
3991 * @see android.telephony.TelephonyManager.WifiCallingChoices
3992 */
3993 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003997 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004002 }
4003
Sailesh Nepald1e68152013-12-12 19:08:02 -08004004 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004005 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004006 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004007 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004008
Jordan Liu4c733742019-02-28 12:03:40 -08004009 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4010 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4011 if (phoneId == -1) {
4012 throw new IllegalArgumentException("Given slot index: " + slotIndex
4013 + " does not correspond to an active phone");
4014 }
4015 return PhoneFactory.getPhone(phoneId);
4016 }
4017
Shishir Agrawal566b7612013-10-28 14:41:00 -07004018 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004019 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4020 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4022 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004024 if (DBG) {
4025 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4026 }
4027 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4028 p2);
4029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030
Jordan Liu4c733742019-02-28 12:03:40 -08004031
4032 @Override
4033 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4034 int slotIndex, String callingPackage, String aid, int p2) {
4035 enforceModifyPermission();
4036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4037 if (DBG) {
4038 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4039 }
4040 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4041 callingPackage, aid, p2);
4042 }
4043
4044 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4045 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 if (TextUtils.equals(ISDR_AID, aid)) {
4049 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004050 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4051 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 if (bestComponent == null
4053 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4054 loge("The calling package is not allowed to access ISD-R.");
4055 throw new SecurityException(
4056 "The calling package is not allowed to access ISD-R.");
4057 }
Derek Tan740e1672017-06-27 14:56:27 -07004058 }
Derek Tan740e1672017-06-27 14:56:27 -07004059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004061 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4062 null /* workSource */);
4063 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 return response;
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068 }
4069
4070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004071 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4073 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004074 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4075 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4076 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004077
Jordan Liu4c733742019-02-28 12:03:40 -08004078 @Override
4079 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4080 enforceModifyPermission();
4081 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4082 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4083 channel);
4084 }
4085
4086 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 final long identity = Binder.clearCallingIdentity();
4088 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 if (channel < 0) {
4090 return false;
4091 }
Jordan Liu4c733742019-02-28 12:03:40 -08004092 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4093 null /* workSource */);
4094 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 return success;
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004098 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004099 }
4100
4101 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004102 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004103 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4105 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004106 if (DBG) {
4107 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4108 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4109 + p3 + " data=" + data);
4110 }
4111 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4112 command, p1, p2, p3, data);
4113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004114
Jordan Liu4c733742019-02-28 12:03:40 -08004115 @Override
4116 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4117 int command, int p1, int p2, int p3, String data) {
4118 enforceModifyPermission();
4119 if (DBG) {
4120 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4121 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4122 + p3 + " data=" + data);
4123 }
4124 return iccTransmitApduLogicalChannelWithPermission(
4125 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4126 data);
4127 }
4128
4129 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4130 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131 final long identity = Binder.clearCallingIdentity();
4132 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004133 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 return "";
4135 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004138 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4139 null /* workSource */);
4140 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 // Append the returned status code to the end of the response payload.
4143 String s = Integer.toHexString(
4144 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4145 if (response.payload != null) {
4146 s = IccUtils.bytesToHexString(response.payload) + s;
4147 }
4148 return s;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004151 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004152 }
Jake Hambye994d462014-02-03 13:10:13 -08004153
Evan Charltonc66da362014-05-16 14:06:40 -07004154 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004155 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4156 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4158 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004160 if (DBG) {
4161 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4162 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4163 }
4164 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4165 cla, command, p1, p2, p3, data);
4166 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004167
Jordan Liu4c733742019-02-28 12:03:40 -08004168 @Override
4169 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4170 int command, int p1, int p2, int p3, String data) {
4171 enforceModifyPermission();
4172 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4173 if (DBG) {
4174 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4175 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4176 + " data=" + data);
4177 }
4178
4179 return iccTransmitApduBasicChannelWithPermission(
4180 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4181 p2, p3, data);
4182 }
4183
4184 // open APDU basic channel assuming the caller has sufficient permissions
4185 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4186 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4190 && TextUtils.equals(ISDR_AID, data)) {
4191 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004192 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4193 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 if (bestComponent == null
4195 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4196 loge("The calling package is not allowed to select ISD-R.");
4197 throw new SecurityException(
4198 "The calling package is not allowed to select ISD-R.");
4199 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004200 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004203 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4204 null /* workSource */);
4205 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207 // Append the returned status code to the end of the response payload.
4208 String s = Integer.toHexString(
4209 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4210 if (response.payload != null) {
4211 s = IccUtils.bytesToHexString(response.payload) + s;
4212 }
4213 return s;
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004216 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004217 }
4218
4219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004220 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004221 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4223 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 if (DBG) {
4228 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4229 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4230 }
4231
4232 IccIoResult response =
4233 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4234 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4235 subId);
4236
4237 if (DBG) {
4238 log("Exchange SIM_IO [R]" + response);
4239 }
4240
4241 byte[] result = null;
4242 int length = 2;
4243 if (response.payload != null) {
4244 length = 2 + response.payload.length;
4245 result = new byte[length];
4246 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4247 } else {
4248 result = new byte[length];
4249 }
4250
4251 result[length - 1] = (byte) response.sw2;
4252 result[length - 2] = (byte) response.sw1;
4253 return result;
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004256 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004257 }
4258
Nathan Haroldb3014052017-01-25 15:57:32 -08004259 /**
4260 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4261 * on a particular subscription
4262 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004263 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4264 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004266 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004267 return null;
4268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269
4270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 if (appType != TelephonyManager.APPTYPE_USIM
4273 && appType != TelephonyManager.APPTYPE_SIM) {
4274 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4275 return null;
4276 }
4277 Object response = sendRequest(
4278 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4279 if (response instanceof String[]) {
4280 return (String[]) response;
4281 }
yincheng zhao2737e882019-09-06 17:06:54 -07004282 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004284 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004287 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004288 }
4289
yincheng zhao2737e882019-09-06 17:06:54 -07004290 /**
4291 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4292 * subscription.
4293 *
4294 * @param subId the id of the subscription.
4295 * @param appType the uicc app type, must be USIM or SIM.
4296 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4297 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004298 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004299 * @return number of fplmns that is successfully written to the SIM.
4300 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004301 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4302 String callingFeatureId) {
4303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4304 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004305 if (DBG) logv("no permissions for setForbiddenplmns");
4306 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4307 }
4308 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4309 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4310 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4311 }
4312 if (fplmns == null) {
4313 throw new IllegalArgumentException("Fplmn List provided is null");
4314 }
4315 for (String fplmn : fplmns) {
4316 if (!CellIdentity.isValidPlmn(fplmn)) {
4317 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4318 }
4319 }
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 Object response = sendRequest(
4323 CMD_SET_FORBIDDEN_PLMNS,
4324 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4325 subId);
4326 return (int) response;
4327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004332 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004333 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4335 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4340 if (response.payload == null) {
4341 return "";
4342 }
Evan Charltonc66da362014-05-16 14:06:40 -07004343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 // Append the returned status code to the end of the response payload.
4345 String s = Integer.toHexString(
4346 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4347 s = IccUtils.bytesToHexString(response.payload) + s;
4348 return s;
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
Evan Charltonc66da362014-05-16 14:06:40 -07004352 }
4353
Jake Hambye994d462014-02-03 13:10:13 -08004354 /**
4355 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4356 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4357 *
4358 * @param itemID the ID of the item to read
4359 * @return the NV item as a String, or null on error.
4360 */
4361 @Override
4362 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
4367 final long identity = Binder.clearCallingIdentity();
4368 try {
4369 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004370 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4372 return value;
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Jake Hambye994d462014-02-03 13:10:13 -08004376 }
4377
4378 /**
4379 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4380 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4381 *
4382 * @param itemID the ID of the item to read
4383 * @param itemValue the value to write, as a String
4384 * @return true on success; false on any failure
4385 */
4386 @Override
4387 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4390 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4395 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004396 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4398 return success;
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
Jake Hambye994d462014-02-03 13:10:13 -08004402 }
4403
4404 /**
4405 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4406 * Used for device configuration by some CDMA operators.
4407 *
4408 * @param preferredRoamingList byte array containing the new PRL
4409 * @return true on success; false on any failure
4410 */
4411 @Override
4412 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4414 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
4418 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4419 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4420 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4421 return success;
4422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
Jake Hambye994d462014-02-03 13:10:13 -08004425 }
4426
4427 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004428 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004429 * Used for device configuration by some CDMA operators.
4430 *
chen xu6dac5ab2018-10-26 17:39:23 -07004431 * @param slotIndex - device slot.
4432 *
Jake Hambye994d462014-02-03 13:10:13 -08004433 * @return true on success; false on any failure
4434 */
4435 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004436 public boolean resetModemConfig(int slotIndex) {
4437 Phone phone = PhoneFactory.getPhone(slotIndex);
4438 if (phone != null) {
4439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4440 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441
chen xu6dac5ab2018-10-26 17:39:23 -07004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4445 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4446 return success;
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 }
chen xu6dac5ab2018-10-26 17:39:23 -07004451 return false;
4452 }
4453
4454 /**
4455 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4456 *
4457 * @param slotIndex - device slot.
4458 *
4459 * @return true on success; false on any failure
4460 */
4461 @Override
4462 public boolean rebootModem(int slotIndex) {
4463 Phone phone = PhoneFactory.getPhone(slotIndex);
4464 if (phone != null) {
4465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4466 mApp, phone.getSubId(), "rebootModem");
4467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4471 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4472 return success;
4473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004478 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004479
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004480 public String[] getPcscfAddress(String apnType, String callingPackage,
4481 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004482 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4484 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004485 return new String[0];
4486 }
4487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 final long identity = Binder.clearCallingIdentity();
4489 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004490 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Wink Saville36469e72014-06-11 15:17:00 -07004494 }
4495
Brad Ebinger51f743a2017-01-23 13:50:20 -08004496 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004497 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4498 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004499 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004500 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004505 ImsResolver resolver = PhoneFactory.getImsResolver();
4506 if (resolver == null) {
4507 // may happen if the device does not support IMS.
4508 return;
4509 }
4510 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004514 }
4515
4516 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004517 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4518 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004519 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004520 public void disableIms(int slotId) {
4521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004525 ImsResolver resolver = PhoneFactory.getImsResolver();
4526 if (resolver == null) {
4527 // may happen if the device does not support IMS.
4528 return;
4529 }
4530 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004534 }
4535
4536 /**
4537 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4538 * feature or {@link null} if the service is not available. If the feature is available, the
4539 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4540 */
4541 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004542 IImsServiceFeatureCallback callback) {
4543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
4546 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004547 ImsResolver resolver = PhoneFactory.getImsResolver();
4548 if (resolver == null) {
4549 // may happen if the device does not support IMS.
4550 return null;
4551 }
4552 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004556 }
4557
4558 /**
4559 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4560 * feature during emergency calling or {@link null} if the service is not available. If the
4561 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4562 * listener for feature updates.
4563 */
4564 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
4567 final long identity = Binder.clearCallingIdentity();
4568 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004569 ImsResolver resolver = PhoneFactory.getImsResolver();
4570 if (resolver == null) {
4571 // may happen if the device does not support IMS.
4572 return null;
4573 }
4574 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004578 }
4579
Brad Ebinger5f64b052017-12-14 14:26:15 -08004580 /**
4581 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004582 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 */
4584 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004589 ImsResolver resolver = PhoneFactory.getImsResolver();
4590 if (resolver == null) {
4591 // may happen if the device does not support IMS.
4592 return null;
4593 }
4594 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004598 }
4599
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004600 /**
4601 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004602 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004603 */
4604 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606
4607 final long identity = Binder.clearCallingIdentity();
4608 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 ImsResolver resolver = PhoneFactory.getImsResolver();
4610 if (resolver == null) {
4611 // may happen if the device does not support IMS.
4612 return null;
4613 }
4614 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004618 }
4619
Brad Ebinger884c07b2018-02-15 16:17:40 -08004620 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004621 * Sets the ImsService Package Name that Telephony will bind to.
4622 *
4623 * @param slotId the slot ID that the ImsService should bind for.
4624 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4625 * ImsService is the device default ImsService.
4626 * @param packageName The package name of the application that contains the ImsService to bind
4627 * to.
4628 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4629 * @hide
4630 */
4631 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004632 int[] subIds = SubscriptionManager.getSubId(slotId);
4633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4634 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4635 "setImsService");
4636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004639 ImsResolver resolver = PhoneFactory.getImsResolver();
4640 if (resolver == null) {
4641 // may happen if the device does not support IMS.
4642 return false;
4643 }
4644 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4645 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004649 }
4650
4651 /**
4652 * Return the ImsService configuration.
4653 *
4654 * @param slotId The slot that the ImsService is associated with.
4655 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4656 * the device default.
4657 * @return the package name of the ImsService configuration.
4658 */
4659 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004660 int[] subIds = SubscriptionManager.getSubId(slotId);
4661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4662 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4663 "getImsService");
4664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004667 ImsResolver resolver = PhoneFactory.getImsResolver();
4668 if (resolver == null) {
4669 // may happen if the device does not support IMS.
4670 return "";
4671 }
4672 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004676 }
4677
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004678 /**
4679 * Get the MmTelFeature state associated with the requested subscription id.
4680 * @param subId The subscription that the MmTelFeature is associated with.
4681 * @param callback A callback with an integer containing the
4682 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4683 */
4684 @Override
4685 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4686 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4687 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4689 "IMS not available on device.");
4690 }
4691 final long token = Binder.clearCallingIdentity();
4692 try {
4693 int slotId = getSlotIndex(subId);
4694 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4695 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4696 + subId + "'");
4697 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4698 }
4699 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4700 try {
4701 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4702 } catch (RemoteException e) {
4703 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4704 + "Ignore");
4705 }
4706 });
4707 } finally {
4708 Binder.restoreCallingIdentity(token);
4709 }
4710 }
4711
Wink Saville36469e72014-06-11 15:17:00 -07004712 public void setImsRegistrationState(boolean registered) {
4713 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004714
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004717 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Wink Saville36469e72014-06-11 15:17:00 -07004721 }
4722
4723 /**
Stuart Scott54788802015-03-30 13:18:01 -07004724 * Set the network selection mode to automatic.
4725 *
4726 */
4727 @Override
4728 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4730 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731
Pengquan Menge92a50d2018-09-21 15:54:48 -07004732 if (!isActiveSubscription(subId)) {
4733 return;
4734 }
4735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4739 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
Stuart Scott54788802015-03-30 13:18:01 -07004743 }
4744
Pengquan Mengea84e042018-09-20 14:57:26 -07004745 /**
4746 * Ask the radio to connect to the input network and change selection mode to manual.
4747 *
4748 * @param subId the id of the subscription.
4749 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4750 * the operator to attach to.
4751 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4752 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4753 * normal network selection next time.
4754 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004755 */
4756 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004757 public boolean setNetworkSelectionModeManual(
4758 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4760 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004761
4762 if (!isActiveSubscription(subId)) {
4763 return false;
4764 }
4765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004766 final long identity = Binder.clearCallingIdentity();
4767 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004768 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004770 if (DBG) {
4771 log("setNetworkSelectionModeManual: subId: " + subId
4772 + " operator: " + operatorInfo);
4773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004778 }
4779
4780 /**
4781 * Scans for available networks.
4782 */
4783 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004784 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4785 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004788 LocationAccessPolicy.LocationPermissionResult locationResult =
4789 LocationAccessPolicy.checkLocationPermission(mApp,
4790 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4791 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004792 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004793 .setCallingPid(Binder.getCallingPid())
4794 .setCallingUid(Binder.getCallingUid())
4795 .setMethod("getCellNetworkScanResults")
4796 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4797 .build());
4798 switch (locationResult) {
4799 case DENIED_HARD:
4800 throw new SecurityException("Not allowed to access scan results -- location");
4801 case DENIED_SOFT:
4802 return null;
4803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804
Pengquan Menga1bb6272018-09-06 09:59:22 -07004805 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004806 try {
4807 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004808 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004813 }
4814
4815 /**
yinxub1bed742017-04-17 11:45:04 -07004816 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004817 *
yinxub1bed742017-04-17 11:45:04 -07004818 * @param subId id of the subscription
4819 * @param request contains the radio access networks with bands/channels to scan
4820 * @param messenger callback messenger for scan results or errors
4821 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004822 * @return the id of the requested scan which can be used to stop the scan.
4823 */
4824 @Override
4825 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004826 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4828 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004829 LocationAccessPolicy.LocationPermissionResult locationResult =
4830 LocationAccessPolicy.checkLocationPermission(mApp,
4831 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4832 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004833 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004834 .setCallingPid(Binder.getCallingPid())
4835 .setCallingUid(Binder.getCallingUid())
4836 .setMethod("requestNetworkScan")
4837 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4838 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004839 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004840 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004841 if (e != null) {
4842 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4843 throw e;
4844 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004845 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004846 return TelephonyScanManager.INVALID_SCAN_ID;
4847 }
4848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 }
Hall Liu912dfd32019-04-25 14:02:26 -07004850 int callingUid = Binder.getCallingUid();
4851 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 return mNetworkScanRequestTracker.startNetworkScan(
4855 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004856 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
yinxu504e1392017-04-12 16:03:22 -07004860 }
4861
Hall Liub2ac8ef2019-02-28 15:56:23 -08004862 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004863 NetworkScanRequest request, int subId) {
4864 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4865 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4866 boolean hasNetworkScanPermission =
4867 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4868 == PERMISSION_GRANTED;
4869
4870 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4871 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4872 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004873 }
4874
4875 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4876 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004877 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4878 return new SecurityException("Specific channels must not be"
4879 + " scanned without location access.");
4880 }
4881 }
4882 }
4883
Hall Liub2ac8ef2019-02-28 15:56:23 -08004884 return null;
4885 }
4886
yinxu504e1392017-04-12 16:03:22 -07004887 /**
4888 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004889 *
4890 * @param subId id of the subscription
4891 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004892 */
4893 @Override
4894 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4896 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897
Hall Liu912dfd32019-04-25 14:02:26 -07004898 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 final long identity = Binder.clearCallingIdentity();
4900 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004901 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
yinxu504e1392017-04-12 16:03:22 -07004905 }
4906
4907 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004908 * Get the calculated preferred network type.
4909 * Used for debugging incorrect network type.
4910 *
4911 * @return the preferred network type, defined in RILConstants.java.
4912 */
4913 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004914 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004915 final Phone defaultPhone = getDefaultPhone();
4916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004917 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004918 return RILConstants.PREFERRED_NETWORK_MODE;
4919 }
4920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004924 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
Junda Liu84d15a22014-07-02 11:21:04 -07004928 }
4929
4930 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004931 * Get the preferred network type.
4932 * Used for device configuration by some CDMA operators.
4933 *
4934 * @return the preferred network type, defined in RILConstants.java.
4935 */
4936 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004937 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004938 TelephonyPermissions
4939 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4940 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941
4942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 if (DBG) log("getPreferredNetworkType");
4945 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4946 int networkType = (result != null ? result[0] : -1);
4947 if (DBG) log("getPreferredNetworkType: " + networkType);
4948 return networkType;
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004952 }
4953
4954 /**
4955 * Set the preferred network type.
4956 * Used for device configuration by some CDMA operators.
4957 *
4958 * @param networkType the preferred network type, defined in RILConstants.java.
4959 * @return true on success; false on any failure.
4960 */
4961 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004962 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4964 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965
4966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4969 Boolean success = (Boolean) sendRequest(
4970 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4971 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4972 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004973 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4975 }
4976 return success;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004979 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004980 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004981
4982 /**
Miaoa84611c2019-03-15 09:21:10 +08004983 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004984 *
Miaoa84611c2019-03-15 09:21:10 +08004985 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004986 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004987 * @hide
4988 */
4989 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004990 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004991 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004993 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 try {
Miaoa84611c2019-03-15 09:21:10 +08004995 if (phone != null) {
4996 return phone.hasMatchedTetherApnSetting();
4997 } else {
4998 return false;
4999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005002 }
Junda Liu475951f2014-11-07 16:45:03 -08005003 }
5004
5005 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005006 * Set mobile data enabled
5007 * Used by the user through settings etc to turn on/off mobile data
5008 *
5009 * @param enable {@code true} turn turn data on, else {@code false}
5010 */
5011 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005012 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 int phoneId = mSubscriptionController.getPhoneId(subId);
5019 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5020 Phone phone = PhoneFactory.getPhone(phoneId);
5021 if (phone != null) {
5022 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005023 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005025 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 }
5027 } finally {
5028 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005029 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005030 }
5031
5032 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005033 * Get the user enabled state of Mobile Data.
5034 *
5035 * TODO: remove and use isUserDataEnabled.
5036 * This can't be removed now because some vendor codes
5037 * calls through ITelephony directly while they should
5038 * use TelephonyManager.
5039 *
5040 * @return true on enabled
5041 */
5042 @Override
5043 public boolean getDataEnabled(int subId) {
5044 return isUserDataEnabled(subId);
5045 }
5046
5047 /**
5048 * Get whether mobile data is enabled per user setting.
5049 *
5050 * There are other factors deciding whether mobile data is actually enabled, but they are
5051 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005052 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005053 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005054 *
5055 * @return {@code true} if data is enabled else {@code false}
5056 */
5057 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005058 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005059 try {
5060 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5061 null);
5062 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5064 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066
5067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 int phoneId = mSubscriptionController.getPhoneId(subId);
5070 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5071 Phone phone = PhoneFactory.getPhone(phoneId);
5072 if (phone != null) {
5073 boolean retVal = phone.isUserDataEnabled();
5074 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5075 return retVal;
5076 } else {
5077 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5078 return false;
5079 }
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005082 }
5083 }
5084
5085 /**
5086 * Get whether mobile data is enabled.
5087 *
5088 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5089 * whether mobile data is actually enabled.
5090 *
5091 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5092 *
5093 * @return {@code true} if data is enabled else {@code false}
5094 */
5095 @Override
5096 public boolean isDataEnabled(int subId) {
5097 try {
5098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5099 null);
5100 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104
5105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 int phoneId = mSubscriptionController.getPhoneId(subId);
5108 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5109 Phone phone = PhoneFactory.getPhone(phoneId);
5110 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005111 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5113 return retVal;
5114 } else {
5115 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5116 return false;
5117 }
5118 } finally {
5119 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005120 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005121 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005122
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005123 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5124 Phone phone) {
5125 //load access rules from carrier configs, and check those as well: b/139133814
5126 SubscriptionController subController = SubscriptionController.getInstance();
5127 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5128 || subController == null) return privilegeFromSim;
5129
5130 int uid = Binder.getCallingUid();
5131 PackageManager pkgMgr = phone.getContext().getPackageManager();
5132 String[] packages = pkgMgr.getPackagesForUid(uid);
5133
5134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5137 SubscriptionManager subManager = (SubscriptionManager)
5138 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5139 for (String pkg : packages) {
5140 if (subManager.canManageSubscription(subInfo, pkg)) {
5141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5142 }
5143 }
5144 return privilegeFromSim;
5145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
5148 }
5149
5150 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5151 String pkgName) {
5152 //load access rules from carrier configs, and check those as well: b/139133814
5153 SubscriptionController subController = SubscriptionController.getInstance();
5154 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5155 || subController == null) return privilegeFromSim;
5156
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5160 SubscriptionManager subManager = (SubscriptionManager)
5161 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5162 return subManager.canManageSubscription(subInfo, pkgName)
5163 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
5167 }
5168
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005170 public int getCarrierPrivilegeStatus(int subId) {
5171 final Phone phone = getPhone(subId);
5172 if (phone == null) {
5173 loge("getCarrierPrivilegeStatus: Invalid subId");
5174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5175 }
5176 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005177 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005178 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5180 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005181
5182 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5183 card.getCarrierPrivilegeStatusForCurrentTransaction(
5184 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005185 }
Junda Liu29340342014-07-10 15:23:27 -07005186
5187 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005188 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5189 final Phone phone = getPhone(subId);
5190 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005191 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005192 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5193 }
5194 UiccProfile profile =
5195 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5196 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005197 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5199 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005200 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5201 profile.getCarrierPrivilegeStatusForUid(
5202 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005203 }
5204
5205 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005206 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5207 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005209 }
5210
5211 int phoneId = SubscriptionManager.getPhoneId(subId);
5212 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005213 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005214 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5216 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005217 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5218 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5219 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005220 }
5221
5222 @Override
5223 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005224 if (TextUtils.isEmpty(pkgName))
5225 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005226 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5227 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5228 UiccCard card = UiccController.getInstance().getUiccCard(i);
5229 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005230 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005231 continue;
5232 }
5233
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005234 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5235 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5236 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005237 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5238 break;
5239 }
5240 }
5241
5242 return result;
Junda Liu29340342014-07-10 15:23:27 -07005243 }
Derek Tan89e89d42014-07-08 17:00:10 -07005244
5245 @Override
Junda Liue64de782015-04-16 17:19:16 -07005246 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5247 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5248 loge("phoneId " + phoneId + " is not valid.");
5249 return null;
5250 }
5251 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005252 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005253 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005254 return null ;
5255 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005256 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005257 }
5258
Amith Yamasani6e118872016-02-19 12:53:51 -08005259 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005260 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005261 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005262 List<String> privilegedPackages = new ArrayList<>();
5263 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005264 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5265 // has UICC in that slot.
5266 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005267 if (card.hasCarrierPrivilegeRules()) {
5268 if (packages == null) {
5269 // Only check packages in user 0 for now
5270 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005271 PackageManager.MATCH_DISABLED_COMPONENTS
5272 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005273 | PackageManager.GET_SIGNING_CERTIFICATES,
5274 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005275 }
5276 for (int p = packages.size() - 1; p >= 0; p--) {
5277 PackageInfo pkgInfo = packages.get(p);
5278 if (pkgInfo != null && pkgInfo.packageName != null
5279 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005280 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005281 privilegedPackages.add(pkgInfo.packageName);
5282 }
5283 }
5284 }
5285 }
5286 return privilegedPackages;
5287 }
5288
chen xuf7e9fe82019-05-09 19:31:02 -07005289 @Override
5290 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5291 List<String> privilegedPackages = new ArrayList<>();
5292 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5293 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5294 }
5295 return privilegedPackages;
5296 }
5297
Wink Savilleb564aae2014-10-23 10:18:09 -07005298 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005299 final Phone phone = getPhone(subId);
5300 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005301 if (card == null) {
5302 loge("getIccId: No UICC");
5303 return null;
5304 }
5305 String iccId = card.getIccId();
5306 if (TextUtils.isEmpty(iccId)) {
5307 loge("getIccId: ICC ID is null or empty.");
5308 return null;
5309 }
5310 return iccId;
5311 }
5312
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005313 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005314 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5315 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005316 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5317 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 final String iccId = getIccId(subId);
5322 final Phone phone = getPhone(subId);
5323 if (phone == null) {
5324 return false;
5325 }
5326 final String subscriberId = phone.getSubscriberId();
5327
5328 if (DBG_MERGE) {
5329 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5330 + subscriberId + " to " + number);
5331 }
5332
5333 if (TextUtils.isEmpty(iccId)) {
5334 return false;
5335 }
5336
5337 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5338
5339 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5340 if (alphaTag == null) {
5341 editor.remove(alphaTagPrefKey);
5342 } else {
5343 editor.putString(alphaTagPrefKey, alphaTag);
5344 }
5345
5346 // Record both the line number and IMSI for this ICCID, since we need to
5347 // track all merged IMSIs based on line number
5348 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5349 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5350 if (number == null) {
5351 editor.remove(numberPrefKey);
5352 editor.remove(subscriberPrefKey);
5353 } else {
5354 editor.putString(numberPrefKey, number);
5355 editor.putString(subscriberPrefKey, subscriberId);
5356 }
5357
5358 editor.commit();
5359 return true;
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005362 }
Derek Tan7226c842014-07-02 17:42:23 -07005363 }
5364
5365 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005366 public String getLine1NumberForDisplay(int subId, String callingPackage,
5367 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005368 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005370 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005371 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005372 return null;
5373 }
Derek Tan97ebb422014-09-05 16:55:38 -07005374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 String iccId = getIccId(subId);
5378 if (iccId != null) {
5379 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5380 if (DBG_MERGE) {
5381 log("getLine1NumberForDisplay returning "
5382 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5383 }
5384 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5387 return null;
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005390 }
Derek Tan7226c842014-07-02 17:42:23 -07005391 }
5392
5393 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005394 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5395 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005397 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005398 return null;
5399 }
Derek Tan97ebb422014-09-05 16:55:38 -07005400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 String iccId = getIccId(subId);
5404 if (iccId != null) {
5405 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5406 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5407 }
5408 return null;
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005411 }
Derek Tan7226c842014-07-02 17:42:23 -07005412 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005413
5414 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5416 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005417 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5418 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005420 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005421 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005422 return null;
5423 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005424
Jordan Liub49b04b2019-05-06 14:45:15 -07005425 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5426 // the process, where TelephonyManager was instantiated.
5427 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005428 final long identity = Binder.clearCallingIdentity();
5429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005430 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 final TelephonyManager tele = TelephonyManager.from(context);
5432 final SubscriptionManager sub = SubscriptionManager.from(context);
5433
5434 // Figure out what subscribers are currently active
5435 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436
Jordan Liub49b04b2019-05-06 14:45:15 -07005437 // Only consider subs which match the current subId
5438 // This logic can be simplified. See b/131189269 for progress.
5439 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005440 activeSubscriberIds.add(tele.getSubscriberId(subId));
5441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442
5443 // First pass, find a number override for an active subscriber
5444 String mergeNumber = null;
5445 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5446 for (String key : prefs.keySet()) {
5447 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5448 final String subscriberId = (String) prefs.get(key);
5449 if (activeSubscriberIds.contains(subscriberId)) {
5450 final String iccId = key.substring(
5451 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5452 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5453 mergeNumber = (String) prefs.get(numberKey);
5454 if (DBG_MERGE) {
5455 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5456 + " for active subscriber " + subscriberId);
5457 }
5458 if (!TextUtils.isEmpty(mergeNumber)) {
5459 break;
5460 }
5461 }
5462 }
5463 }
5464
5465 // Shortcut when no active merged subscribers
5466 if (TextUtils.isEmpty(mergeNumber)) {
5467 return null;
5468 }
5469
5470 // Second pass, find all subscribers under that line override
5471 final ArraySet<String> result = new ArraySet<>();
5472 for (String key : prefs.keySet()) {
5473 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5474 final String number = (String) prefs.get(key);
5475 if (mergeNumber.equals(number)) {
5476 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5477 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5478 final String subscriberId = (String) prefs.get(subscriberKey);
5479 if (!TextUtils.isEmpty(subscriberId)) {
5480 result.add(subscriberId);
5481 }
5482 }
5483 }
5484 }
5485
5486 final String[] resultArray = result.toArray(new String[result.size()]);
5487 Arrays.sort(resultArray);
5488 if (DBG_MERGE) {
5489 Slog.d(LOG_TAG,
5490 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5491 }
5492 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005495 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005496 }
5497
5498 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005499 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5500 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 final TelephonyManager telephonyManager = mApp.getSystemService(
5505 TelephonyManager.class);
5506 String subscriberId = telephonyManager.getSubscriberId(subId);
5507 if (subscriberId == null) {
5508 if (DBG) {
5509 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5510 + subId);
5511 }
5512 return null;
5513 }
5514
5515 final SubscriptionInfo info = SubscriptionController.getInstance()
5516 .getSubscriptionInfo(subId);
5517 final ParcelUuid groupUuid = info.getGroupUuid();
5518 // If it doesn't belong to any group, return just subscriberId of itself.
5519 if (groupUuid == null) {
5520 return new String[]{subscriberId};
5521 }
5522
5523 // Get all subscriberIds from the group.
5524 final List<String> mergedSubscriberIds = new ArrayList<>();
5525 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005526 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5527 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005528 for (SubscriptionInfo subInfo : groupInfos) {
5529 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5530 if (subscriberId != null) {
5531 mergedSubscriberIds.add(subscriberId);
5532 }
5533 }
5534
5535 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5536 } finally {
5537 Binder.restoreCallingIdentity(identity);
5538
5539 }
5540 }
5541
5542 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005543 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005544 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5545 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546
5547 final long identity = Binder.clearCallingIdentity();
5548 try {
5549 final Phone phone = getPhone(subId);
5550 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005554 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005555
5556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005557 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005558 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5559 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005560 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 final Phone phone = getPhone(subId);
5565 if (phone == null) {
5566 return false;
5567 }
5568 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5569 cdmaNonRoamingList);
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005573 }
5574
5575 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005576 @Deprecated
5577 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5578 enforceModifyPermission();
5579
5580 int returnValue = 0;
5581 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005583 if(result.exception == null) {
5584 if (result.result != null) {
5585 byte[] responseData = (byte[])(result.result);
5586 if(responseData.length > oemResp.length) {
5587 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5588 responseData.length + "bytes. Buffer Size is " +
5589 oemResp.length + "bytes.");
5590 }
5591 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5592 returnValue = responseData.length;
5593 }
5594 } else {
5595 CommandException ex = (CommandException) result.exception;
5596 returnValue = ex.getCommandError().ordinal();
5597 if(returnValue > 0) returnValue *= -1;
5598 }
5599 } catch (RuntimeException e) {
5600 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5601 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5602 if(returnValue > 0) returnValue *= -1;
5603 }
5604
5605 return returnValue;
5606 }
5607
5608 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005609 public void setRadioCapability(RadioAccessFamily[] rafs) {
5610 try {
5611 ProxyController.getInstance().setRadioCapability(rafs);
5612 } catch (RuntimeException e) {
5613 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5614 }
5615 }
5616
5617 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005618 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005619 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005620 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005621 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005622 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 final long identity = Binder.clearCallingIdentity();
5625 try {
chen xub97461a2018-10-26 14:17:57 -07005626 TelephonyPermissions
5627 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5628 mApp, phone.getSubId(), "getRadioAccessFamily");
5629 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
chen xub97461a2018-10-26 14:17:57 -07005633 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005634 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005635
5636 @Override
5637 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005638 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005639 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 ImsManager.getInstance(defaultPhone.getContext(),
5644 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005648 }
5649
5650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005651 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005652 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5654 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005655 return false;
5656 }
Svet Ganovb320e182015-04-16 12:30:10 -07005657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 // Check the user preference and the system-level IMS setting. Even if the user has
5661 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5662 // In the long run, we may instead need to check if there exists a connection service
5663 // which can support video calling.
5664 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 return imsManager.isVtEnabledByPlatform()
5667 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5668 && imsManager.isVtEnabledByUser();
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005672 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005673
Andrew Leea1239f22015-03-02 17:44:07 -08005674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005675 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5676 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 mApp, subId, callingPackage, callingFeatureId,
5679 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 return false;
5681 }
5682
5683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 CarrierConfigManager configManager =
5686 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005687 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
Andrew Leea1239f22015-03-02 17:44:07 -08005692 }
5693
5694 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005695 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 return false;
5699 }
5700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 CarrierConfigManager configManager =
5704 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Andrew Leea1239f22015-03-02 17:44:07 -08005710 }
5711
Andrew Lee9431b832015-03-09 18:46:45 -07005712 @Override
5713 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005714 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005715 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005716 }
5717
5718 @Override
5719 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005722 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Andrew Lee9431b832015-03-09 18:46:45 -07005726 }
5727
Hall Liuf6668912018-10-31 17:05:23 -07005728 /**
5729 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5730 * support for the feature and device firmware support.
5731 *
5732 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5733 */
5734 @Override
5735 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 final Phone phone = getPhone(subscriptionId);
5738 if (phone == null) {
5739 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5740 return false;
5741 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005743 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5745 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005746 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 return isCarrierSupported && isDeviceSupported;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Hall Liu98187582018-01-22 19:15:32 -08005751 }
5752
Hall Liuf6668912018-10-31 17:05:23 -07005753 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005754 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5755 * RTT setting, will return true if the device and carrier both support RTT.
5756 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005757 */
5758 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 final long identity = Binder.clearCallingIdentity();
5760 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005761 boolean isRttSupported = isRttSupported(subscriptionId);
5762 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005763 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005764 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5765 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5766 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005770 }
5771
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005772 @Deprecated
5773 @Override
5774 public String getDeviceId(String callingPackage) {
5775 return getDeviceIdWithFeature(callingPackage, null);
5776 }
5777
Sanket Padawe7310cc72015-01-14 09:53:20 -08005778 /**
5779 * Returns the unique device ID of phone, for example, the IMEI for
5780 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5781 *
5782 * <p>Requires Permission:
5783 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5784 */
5785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005786 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005787 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005788 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005789 return null;
5790 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005791 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005792 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005793 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005794 return null;
5795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 return phone.getDeviceId();
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
5802 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005803 }
5804
Ping Sunc67b7c22016-03-02 19:16:45 +08005805 /**
5806 * {@hide}
5807 * Returns the IMS Registration Status on a particular subid
5808 *
5809 * @param subId
5810 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005811 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005812 Phone phone = getPhone(subId);
5813 if (phone != null) {
5814 return phone.isImsRegistered();
5815 } else {
5816 return false;
5817 }
5818 }
5819
Santos Cordon7a1885b2015-02-03 11:15:19 -08005820 @Override
5821 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005828 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005829
Tyler Gunnf70ed162019-04-03 15:28:53 -07005830 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005831 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005832 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005834 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005835 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5836 }
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
5842 }
5843 }
5844
5845 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005846 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 Phone phone = getPhone(subscriptionId);
5850 if (phone == null) {
5851 return null;
5852 }
5853 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
5857 }
5858
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005859 /**
5860 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005861 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005862 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 Phone phone = getPhone(subId);
5866 if (phone != null) {
5867 return phone.isWifiCallingEnabled();
5868 } else {
5869 return false;
5870 }
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005873 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005874 }
5875
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005876 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005877 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005878 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005879 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 Phone phone = getPhone(subId);
5883 if (phone != null) {
5884 return phone.isVideoEnabled();
5885 } else {
5886 return false;
5887 }
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005890 }
5891 }
5892
5893 /**
5894 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5895 * defined in {@link ImsRegistrationImplBase}.
5896 */
5897 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 Phone phone = getPhone(subId);
5901 if (phone != null) {
5902 return phone.getImsRegistrationTech();
5903 } else {
5904 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5905 }
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005908 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005909 }
5910
Stuart Scott8eef64f2015-04-08 15:13:54 -07005911 @Override
5912 public void factoryReset(int subId) {
5913 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005914 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5915 return;
5916 }
5917
Svet Ganovcc087f82015-05-12 20:35:54 -07005918 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005919
Svet Ganovcc087f82015-05-12 20:35:54 -07005920 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005921 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5922 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005923 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005924 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005925 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005926 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5927 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005928 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005929 // There has been issues when Sms raw table somehow stores orphan
5930 // fragments. They lead to garbled message when new fragments come
5931 // in and combined with those stale ones. In case this happens again,
5932 // user can reset all network settings which will clean up this table.
5933 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005934 // Clean up IMS settings as well here.
5935 int slotId = getSlotIndex(subId);
5936 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5937 ImsManager.getInstance(mApp, slotId).factoryReset();
5938 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005939
5940 // Erase modem config if erase modem on network setting is enabled.
5941 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5942 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5943 if (configValue != null && Boolean.parseBoolean(configValue)) {
5944 sendEraseModemConfig(getDefaultPhone());
5945 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005946 } finally {
5947 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005948 }
5949 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005950
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005951 private void cleanUpSmsRawTable(Context context) {
5952 ContentResolver resolver = context.getContentResolver();
5953 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5954 resolver.delete(uri, null, null);
5955 }
5956
Narayan Kamath1c496c22015-04-16 14:40:19 +01005957 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005958 public String getSimLocaleForSubscriber(int subId) {
5959 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5960 final Phone phone = getPhone(subId);
5961 if (phone == null) {
5962 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005963 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
chen xu5d3637b2019-01-21 23:31:38 -08005967 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005968 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005969 if (info == null) {
5970 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5971 return null;
5972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005973 // Try and fetch the locale from the carrier properties or from the SIM language
5974 // preferences (EF-PL and EF-LI)...
5975 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005977 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5978 if (localeFromDefaultSim != null) {
5979 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5980 if (DBG) log("Using locale from subId: " + subId + " locale: "
5981 + localeFromDefaultSim);
5982 return localeFromDefaultSim.toLanguageTag();
5983 } else {
5984 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 }
5986 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 // The SIM language preferences only store a language (e.g. fr = French), not an
5989 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5990 // the SIM and carrier preferences does not include a country we add the country
5991 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005992 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005994 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 return mccLocale.toLanguageTag();
5996 }
5997
5998 if (DBG) log("No locale found - returning null");
5999 return null;
6000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006003 }
6004
6005 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006006 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6007 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006008 }
6009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 /**
6011 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6012 */
6013 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006014 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6015 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006016 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006017
Chenjie Yu1ba97252018-01-11 18:16:20 -08006018 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006019 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006020
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006021 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006022 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6023 * representing the state of the modem.
6024 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006025 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6026 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006027 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006028 */
6029 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006030 public void requestModemActivityInfo(ResultReceiver result) {
6031 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 ModemActivityInfo ret = null;
6037 synchronized (mLastModemActivityInfo) {
6038 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6039 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006040 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006041 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006043 int[] txTimeMs = info.getTransmitTimeMillis();
6044 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006046 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 }
6048 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006049 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6050 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 mLastModemActivityInfo.setIdleTimeMillis(
6052 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006053 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6054 mLastModemActivityInfo.setReceiveTimeMillis(
6055 info.getReceiveTimeMillis() + mLastModemActivityInfo
6056 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006057 }
Chen Xud78231e2019-09-10 18:49:52 -07006058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6060 mLastModemActivityInfo.getSleepTimeMillis(),
6061 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006062 mLastModemActivityInfo.getTransmitTimeMillis(),
6063 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 Bundle bundle = new Bundle();
6066 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6067 result.send(0, bundle);
6068 } finally {
6069 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006070 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006071 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006072
Siddharth Rayb8114062018-06-17 15:02:38 -07006073 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6074 // less than total activity duration.
6075 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6076 if (info == null) {
6077 return false;
6078 }
6079 int activityDurationMs =
6080 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6081 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006082 int[] txTimeMs = info.getTransmitTimeMillis();
6083 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6084 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006085 }
6086 return (info.isValid()
6087 && (info.getSleepTimeMillis() <= activityDurationMs)
6088 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006089 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006090 && (totalTxTimeMs <= activityDurationMs));
6091 }
6092
Jack Yu85bd38a2015-11-09 11:34:32 -08006093 /**
6094 * {@hide}
6095 * Returns the service state information on specified subscription.
6096 */
6097 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006098 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6099 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006101 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006102 return null;
6103 }
6104
Hall Liuf19c44f2018-11-27 14:38:17 -08006105 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6106 LocationAccessPolicy.checkLocationPermission(mApp,
6107 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6108 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006109 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006110 .setCallingPid(Binder.getCallingPid())
6111 .setCallingUid(Binder.getCallingUid())
6112 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006113 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006114 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6115 .build());
6116
6117 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6118 LocationAccessPolicy.checkLocationPermission(mApp,
6119 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6120 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006121 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006122 .setCallingPid(Binder.getCallingPid())
6123 .setCallingUid(Binder.getCallingUid())
6124 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006125 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006126 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6127 .build());
6128 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6129 boolean hasFinePermission =
6130 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6131 boolean hasCoarsePermission =
6132 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 final Phone phone = getPhone(subId);
6137 if (phone == null) {
6138 return null;
6139 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006140
Hall Liuf19c44f2018-11-27 14:38:17 -08006141 ServiceState ss = phone.getServiceState();
6142
6143 // Scrub out the location info in ServiceState depending on what level of access
6144 // the caller has.
6145 if (hasFinePermission) return ss;
6146 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6147 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006151 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006152
6153 /**
6154 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6155 *
6156 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6157 * voicemail ringtone.
6158 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6159 * PhoneAccount.
6160 */
6161 @Override
6162 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6166 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006167 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006174 }
6175
6176 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006177 * Sets the per-account voicemail ringtone.
6178 *
6179 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6180 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6181 *
6182 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6183 * voicemail ringtone.
6184 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6185 * PhoneAccount.
6186 */
6187 @Override
6188 public void setVoicemailRingtoneUri(String callingPackage,
6189 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006192 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6193 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6195 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6196 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198
6199 final long identity = Binder.clearCallingIdentity();
6200 try {
6201 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6202 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 }
6205 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006208 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006209 }
6210
6211 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006212 * Returns whether vibration is set for voicemail notification in Phone settings.
6213 *
6214 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6215 * voicemail vibration setting.
6216 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6217 */
6218 @Override
6219 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6223 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006224 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006231 }
6232
Youhan Wange64578a2016-05-02 15:32:42 -07006233 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006234 * Sets the per-account voicemail vibration.
6235 *
6236 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6237 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6238 *
6239 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6240 * voicemail vibration setting.
6241 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6242 * specific PhoneAccount.
6243 */
6244 @Override
6245 public void setVoicemailVibrationEnabled(String callingPackage,
6246 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006247 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006249 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6250 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6252 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6253 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006254 }
6255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 final long identity = Binder.clearCallingIdentity();
6257 try {
6258 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6259 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006260 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 }
6262 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006265 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006266 }
6267
6268 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006269 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6270 *
6271 * @throws SecurityException if the caller does not have the required permission
6272 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006273 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006274 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006275 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006276 }
6277
6278 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006279 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6280 * permission.
6281 *
6282 * @throws SecurityException if the caller does not have the required permission
6283 */
6284 private void enforceSendSmsPermission() {
6285 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6286 }
6287
6288 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006289 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006290 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006291 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006292 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006293 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 final long identity = Binder.clearCallingIdentity();
6295 try {
6296 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006297 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 if (componentName == null) {
6299 throw new SecurityException(
6300 "Caller not current active visual voicemail package[null]");
6301 }
6302 String vvmPackage = componentName.getPackageName();
6303 if (!callingPackage.equals(vvmPackage)) {
6304 throw new SecurityException("Caller not current active visual voicemail package["
6305 + vvmPackage + "]");
6306 }
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006309 }
6310 }
6311
6312 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006313 * Return the application ID for the app type.
6314 *
6315 * @param subId the subscription ID that this request applies to.
6316 * @param appType the uicc app type.
6317 * @return Application ID for specificied app type, or null if no uicc.
6318 */
6319 @Override
6320 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006321 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006322 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323
6324 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006325 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 if (phone == null) {
6327 return null;
6328 }
6329 String aid = null;
6330 try {
6331 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6332 .getApplicationByType(appType).getAid();
6333 } catch (Exception e) {
6334 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6335 }
6336 return aid;
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006339 }
Youhan Wange64578a2016-05-02 15:32:42 -07006340 }
6341
Youhan Wang4001d252016-05-11 10:29:41 -07006342 /**
6343 * Return the Electronic Serial Number.
6344 *
6345 * @param subId the subscription ID that this request applies to.
6346 * @return ESN or null if error.
6347 */
6348 @Override
6349 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006350 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006351 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006354 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 if (phone == null) {
6356 return null;
6357 }
6358 String esn = null;
6359 try {
6360 esn = phone.getEsn();
6361 } catch (Exception e) {
6362 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6363 }
6364 return esn;
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006367 }
Youhan Wang4001d252016-05-11 10:29:41 -07006368 }
6369
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006370 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006371 * Return the Preferred Roaming List Version.
6372 *
6373 * @param subId the subscription ID that this request applies to.
6374 * @return PRLVersion or null if error.
6375 */
6376 @Override
6377 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006378 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006379 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380
6381 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006382 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 if (phone == null) {
6384 return null;
6385 }
6386 String cdmaPrlVersion = null;
6387 try {
6388 cdmaPrlVersion = phone.getCdmaPrlVersion();
6389 } catch (Exception e) {
6390 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6391 }
6392 return cdmaPrlVersion;
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006395 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006396 }
6397
6398 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006399 * Get snapshot of Telephony histograms
6400 * @return List of Telephony histograms
6401 * @hide
6402 */
6403 @Override
6404 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6406 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 return RIL.getTelephonyRILTimingHistograms();
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006414 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006415
6416 /**
6417 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006418 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6419 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006420 * Require system privileges. In the future we may add this to carrier APIs.
6421 *
Michele Berionne482f8202018-11-27 18:57:59 -08006422 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006423 */
6424 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006425 @TelephonyManager.SetCarrierRestrictionResult
6426 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006427 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006428 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006429
Michele Berionne482f8202018-11-27 18:57:59 -08006430 if (carrierRestrictionRules == null) {
6431 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006432 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 final long identity = Binder.clearCallingIdentity();
6435 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006436 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006437 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006441 }
6442
6443 /**
6444 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006445 * Get the allowed carrier list and the excluded carrier list, including the priority between
6446 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006447 * Require system privileges. In the future we may add this to carrier APIs.
6448 *
Michele Berionne482f8202018-11-27 18:57:59 -08006449 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006450 */
6451 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006452 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006453 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006454 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455
6456 final long identity = Binder.clearCallingIdentity();
6457 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006458 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6459 if (response instanceof CarrierRestrictionRules) {
6460 return (CarrierRestrictionRules) response;
6461 }
6462 // Response is an Exception of some kind,
6463 // which is signalled to the user as a NULL retval
6464 return null;
6465 } catch (Exception e) {
6466 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6467 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006471 }
6472
fionaxu59545b42016-05-25 15:53:37 -07006473 /**
6474 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6475 * @param subId the subscription ID that this action applies to.
6476 * @param enabled control enable or disable metered apns.
6477 * {@hide}
6478 */
6479 @Override
6480 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6481 enforceModifyPermission();
6482 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
6484 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006485 if (phone == null) {
6486 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6487 return;
6488 }
6489 try {
6490 phone.carrierActionSetMeteredApnsEnabled(enabled);
6491 } catch (Exception e) {
6492 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 } finally {
6494 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006495 }
6496 }
6497
6498 /**
6499 * Action set from carrier signalling broadcast receivers to enable/disable radio
6500 * @param subId the subscription ID that this action applies to.
6501 * @param enabled control enable or disable radio.
6502 * {@hide}
6503 */
6504 @Override
6505 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6506 enforceModifyPermission();
6507 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508
6509 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006510 if (phone == null) {
6511 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6512 return;
6513 }
6514 try {
6515 phone.carrierActionSetRadioEnabled(enabled);
6516 } catch (Exception e) {
6517 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518 } finally {
6519 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006520 }
6521 }
6522
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006523 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006524 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6525 * network status based on which carrier apps could apply actions accordingly,
6526 * enable/disable default url handler for example.
6527 *
6528 * @param subId the subscription ID that this action applies to.
6529 * @param report control start/stop reporting the default network status.
6530 * {@hide}
6531 */
6532 @Override
6533 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6534 enforceModifyPermission();
6535 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536
6537 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006538 if (phone == null) {
6539 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6540 return;
6541 }
6542 try {
6543 phone.carrierActionReportDefaultNetworkStatus(report);
6544 } catch (Exception e) {
6545 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 } finally {
6547 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006548 }
6549 }
6550
6551 /**
fionaxud9622282017-07-17 17:51:30 -07006552 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6553 * @param subId the subscription ID that this action applies to.
6554 * {@hide}
6555 */
6556 @Override
6557 public void carrierActionResetAll(int subId) {
6558 enforceModifyPermission();
6559 final Phone phone = getPhone(subId);
6560 if (phone == null) {
6561 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6562 return;
6563 }
6564 try {
6565 phone.carrierActionResetAll();
6566 } catch (Exception e) {
6567 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6568 }
6569 }
6570
6571 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006572 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6573 * bug report is being generated.
6574 */
6575 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006576 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006577 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6578 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006579 writer.println("Permission Denial: can't dump Phone from pid="
6580 + Binder.getCallingPid()
6581 + ", uid=" + Binder.getCallingUid()
6582 + "without permission "
6583 + android.Manifest.permission.DUMP);
6584 return;
6585 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006586 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006587 }
Jack Yueb89b242016-06-22 13:27:47 -07006588
Brad Ebingerdac2f002018-04-03 15:17:52 -07006589 @Override
6590 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6591 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6592 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006593 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6594 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006595 }
6596
Jack Yueb89b242016-06-22 13:27:47 -07006597 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006598 * Get aggregated video call data usage since boot.
6599 *
6600 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6601 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006602 * {@hide}
6603 */
6604 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006605 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006606 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6607 null);
6608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 final long identity = Binder.clearCallingIdentity();
6610 try {
6611 // NetworkStatsService keeps tracking the active network interface and identity. It
6612 // records the delta with the corresponding network identity.
6613 // We just return the total video call data usage snapshot since boot.
6614 Phone phone = getPhone(subId);
6615 if (phone != null) {
6616 return phone.getVtDataUsage(perUidStats);
6617 }
6618 return null;
6619 } finally {
6620 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006621 }
Jack Yueb89b242016-06-22 13:27:47 -07006622 }
Jack Yu75ab2952016-07-08 14:29:33 -07006623
6624 /**
6625 * Policy control of data connection. Usually used when data limit is passed.
6626 * @param enabled True if enabling the data, otherwise disabling.
6627 * @param subId Subscription index
6628 * {@hide}
6629 */
6630 @Override
6631 public void setPolicyDataEnabled(boolean enabled, int subId) {
6632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 Phone phone = getPhone(subId);
6637 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006638 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 }
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006642 }
6643 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006644
6645 /**
6646 * Get Client request stats
6647 * @return List of Client Request Stats
6648 * @hide
6649 */
6650 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006651 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6652 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006653 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006654 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006655 return null;
6656 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006657 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 final long identity = Binder.clearCallingIdentity();
6660 try {
6661 if (phone != null) {
6662 return phone.getClientRequestStats();
6663 }
6664
6665 return null;
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006669 }
6670
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006671 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006672 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006673 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006674 }
Jack Yueb4124c2017-02-16 15:32:43 -08006675
6676 /**
Grace Chen70990072017-03-24 17:21:30 -07006677 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006678 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006679 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006680 * @param state State of SIM (power down, power up, pass through)
6681 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6682 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6683 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006684 *
6685 **/
6686 @Override
Grace Chen70990072017-03-24 17:21:30 -07006687 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006688 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006689 Phone phone = PhoneFactory.getPhone(slotIndex);
6690
vagdeviaf9a5b92018-08-15 16:01:53 -07006691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006696 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006700 }
6701 }
Shuo Qiandd210312017-04-12 22:11:33 +00006702
Tyler Gunn65d45c22017-06-05 11:22:26 -07006703 private boolean isUssdApiAllowed(int subId) {
6704 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006705 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006706 if (configManager == null) {
6707 return false;
6708 }
6709 PersistableBundle pb = configManager.getConfigForSubId(subId);
6710 if (pb == null) {
6711 return false;
6712 }
6713 return pb.getBoolean(
6714 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6715 }
6716
Shuo Qiandd210312017-04-12 22:11:33 +00006717 /**
6718 * Check if phone is in emergency callback mode
6719 * @return true if phone is in emergency callback mode
6720 * @param subId sub id
6721 */
goneil9c5f4872017-12-05 14:07:56 -08006722 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006723 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006724 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006725 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726
6727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 if (phone != null) {
6730 return phone.isInEcm();
6731 } else {
6732 return false;
6733 }
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006736 }
6737 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006738
6739 /**
6740 * Get the current signal strength information for the given subscription.
6741 * Because this information is not updated when the device is in a low power state
6742 * it should not be relied-upon to be current.
6743 * @param subId Subscription index
6744 * @return the most recent cached signal strength info from the modem
6745 */
6746 @Override
6747 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 Phone p = getPhone(subId);
6751 if (p == null) {
6752 return null;
6753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755 return p.getSignalStrength();
6756 } finally {
6757 Binder.restoreCallingIdentity(identity);
6758 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006759 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006760
Pengquan Meng77b7f132018-08-22 14:49:57 -07006761 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006762 * Get the current modem radio state for the given slot.
6763 * @param slotIndex slot index.
6764 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006765 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006766 * @return the current radio power state from the modem
6767 */
6768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006769 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006770 Phone phone = PhoneFactory.getPhone(slotIndex);
6771 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6773 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006774 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6775 }
6776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 return phone.getRadioPowerState();
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6785 }
6786
6787 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006788 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6789 *
6790 * <p>Requires one of the following permissions:
6791 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6792 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6793 * privileges.
6794 *
6795 * @param subId subscription id
6796 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6797 * {@code false}.
6798 */
6799 @Override
6800 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006801 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6802 null /* message */);
6803
Pengquan Menga1bb6272018-09-06 09:59:22 -07006804 boolean isEnabled = false;
6805 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006806 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006807 Phone phone = getPhone(subId);
6808 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006809 } catch (Exception e) {
6810 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6811 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006812 } finally {
6813 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006814 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006815 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006816 }
6817
6818
6819 /**
6820 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6821 *
6822 * <p> Requires permission:
6823 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6824 * privileges.
6825 *
6826 * @param subId subscription id
6827 * @param isEnabled {@code true} means enable, {@code false} means disable.
6828 */
6829 @Override
6830 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6832 mApp, subId, "setDataRoamingEnabled");
6833
Pengquan Menga1bb6272018-09-06 09:59:22 -07006834 final long identity = Binder.clearCallingIdentity();
6835 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006836 Phone phone = getPhone(subId);
6837 if (phone != null) {
6838 phone.setDataRoamingEnabled(isEnabled);
6839 }
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006842 }
6843 }
6844
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006845 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006846 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006847 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6848 mApp, subId, "isManualNetworkSelectionAllowed");
6849
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006850 boolean isAllowed = true;
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006853 Phone phone = getPhone(subId);
6854 if (phone != null) {
6855 isAllowed = phone.isCspPlmnEnabled();
6856 }
6857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
6860 return isAllowed;
6861 }
6862
6863 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006864 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006865 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006866 try {
6867 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006868 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006869 } catch (SecurityException e) {
6870 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6871 // has carrier privileges on an active UICC
6872 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6873 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006874 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006875 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006876 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006877
6878 final long identity = Binder.clearCallingIdentity();
6879 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006880 UiccController uiccController = UiccController.getInstance();
6881 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006882 if (hasReadPermission) {
6883 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006884 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006885
6886 // Remove private info if the caller doesn't have access
6887 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6888 for (UiccCardInfo cardInfo : cardInfos) {
6889 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6890 // is available
6891 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6892 if (card == null || card.getUiccProfile() == null) {
6893 // assume no access if the card or profile is unavailable
6894 filteredInfos.add(cardInfo.getUnprivileged());
6895 continue;
6896 }
6897 UiccProfile profile = card.getUiccProfile();
6898 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6899 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6900 filteredInfos.add(cardInfo);
6901 } else {
6902 filteredInfos.add(cardInfo.getUnprivileged());
6903 }
6904 }
6905 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
6909 }
6910
6911 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006912 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006913 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 final long identity = Binder.clearCallingIdentity();
6916 try {
6917 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6918 if (slots == null) {
6919 Rlog.i(LOG_TAG, "slots is null.");
6920 return null;
6921 }
6922
6923 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6924 for (int i = 0; i < slots.length; i++) {
6925 UiccSlot slot = slots[i];
6926 if (slot == null) {
6927 continue;
6928 }
6929
Jordan Liu7be7e652019-05-06 18:55:02 +00006930 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 UiccCard card = slot.getUiccCard();
6932 if (card != null) {
6933 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006934 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006935 cardId = slot.getEid();
6936 if (TextUtils.isEmpty(cardId)) {
6937 cardId = slot.getIccId();
6938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 }
6940
Jordan Liu857451f2019-05-09 16:35:35 -07006941 if (cardId != null) {
6942 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6943 // if cardId is an EID, it's all digits so this is fine
6944 cardId = IccUtils.stripTrailingFs(cardId);
6945 }
6946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 int cardState = 0;
6948 switch (slot.getCardState()) {
6949 case CARDSTATE_ABSENT:
6950 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6951 break;
6952 case CARDSTATE_PRESENT:
6953 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6954 break;
6955 case CARDSTATE_ERROR:
6956 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6957 break;
6958 case CARDSTATE_RESTRICTED:
6959 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6960 break;
6961 default:
6962 break;
6963
6964 }
6965
6966 infos[i] = new UiccSlotInfo(
6967 slot.isActive(),
6968 slot.isEuicc(),
6969 cardId,
6970 cardState,
6971 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006972 slot.isExtendedApduSupported(),
6973 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 }
6975 return infos;
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006978 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006979 }
6980
6981 @Override
6982 public boolean switchSlots(int[] physicalSlots) {
6983 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
6990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006991 }
Jack Yu4c988042018-02-27 15:30:01 -08006992
6993 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006994 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 return UiccController.getInstance().getCardIdForDefaultEuicc();
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
7003 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007004 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7005 enforceModifyPermission();
7006 final Phone phone = getPhone(subId);
7007 if (phone == null) {
7008 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7009 return;
7010 }
7011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 final long identity = Binder.clearCallingIdentity();
7013 try {
7014 phone.setRadioIndicationUpdateMode(filters, mode);
7015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
Jack Yu4c988042018-02-27 15:30:01 -08007018 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007019
7020 /**
goneil47ffb6e2018-04-06 15:40:58 -07007021 * A test API to reload the UICC profile.
7022 *
7023 * <p>Requires that the calling app has permission
7024 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7025 * @hide
7026 */
7027 @Override
7028 public void refreshUiccProfile(int subId) {
7029 enforceModifyPermission();
7030
7031 final long identity = Binder.clearCallingIdentity();
7032 try {
7033 Phone phone = getPhone(subId);
7034 if (phone == null) {
7035 return;
7036 }
7037 UiccCard uiccCard = phone.getUiccCard();
7038 if (uiccCard == null) {
7039 return;
7040 }
7041 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7042 if (uiccProfile == null) {
7043 return;
7044 }
7045 uiccProfile.refresh();
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
7049 }
7050
7051 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007052 * Returns false if the mobile data is disabled by default, otherwise return true.
7053 */
7054 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007055 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007056 }
7057
7058 /**
7059 * Returns true if the data roaming is enabled by default, i.e the system property
7060 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7061 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7062 */
7063 private boolean getDefaultDataRoamingEnabled(int subId) {
7064 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007066 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007067 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7068 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7069 return isDataRoamingEnabled;
7070 }
7071
7072 /**
7073 * Returns the default network type for the given {@code subId}, if the default network type is
7074 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7075 */
7076 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007077 List<Integer> list = TelephonyProperties.default_network();
7078 int phoneId = mSubscriptionController.getPhoneId(subId);
7079 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7080 return list.get(phoneId);
7081 }
7082 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007083 }
fionaxua13278b2018-03-21 00:08:13 -07007084
7085 @Override
7086 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007087 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007088 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089
7090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 final Phone phone = getPhone(subId);
7093 if (phone == null) {
7094 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7095 return;
7096 }
chen xueaba88a2019-03-15 13:15:10 -07007097 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7098 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 } finally {
7100 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007101 }
fionaxua13278b2018-03-21 00:08:13 -07007102 }
7103
7104 @Override
7105 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007106 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 final Phone phone = getPhone(subId);
7111 if (phone == null) {
7112 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7113 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7114 }
7115 return phone.getCarrierIdListVersion();
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007118 }
fionaxua13278b2018-03-21 00:08:13 -07007119 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007120
7121 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7123 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007125 mApp, subId, callingPackage, callingFeatureId,
7126 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007127 return -1;
7128 }
7129
7130 final long identity = Binder.clearCallingIdentity();
7131 try {
7132 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7133 } finally {
7134 Binder.restoreCallingIdentity(identity);
7135 }
7136 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007137
7138 @Override
7139 public int getCdmaRoamingMode(int subId) {
7140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7141 mApp, subId, "getCdmaRoamingMode");
7142
7143 final long identity = Binder.clearCallingIdentity();
7144 try {
7145 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
7149 }
7150
7151 @Override
7152 public boolean setCdmaRoamingMode(int subId, int mode) {
7153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7154 mApp, subId, "setCdmaRoamingMode");
7155
7156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
7162 }
7163
7164 @Override
7165 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7167 mApp, subId, "setCdmaSubscriptionMode");
7168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
7175 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007176
sqianc5eccab2018-10-19 18:46:41 -07007177 @Override
sqian8c685422019-02-22 15:55:18 -08007178 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007179 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007181 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7182 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007183 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7184 }
7185 final long identity = Binder.clearCallingIdentity();
7186 try {
sqian854d44b2018-12-12 16:48:18 -08007187 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7188 for (Phone phone: PhoneFactory.getPhones()) {
7189 if (phone.getEmergencyNumberTracker() != null
7190 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7191 emergencyNumberListInternal.put(
7192 phone.getSubId(),
7193 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7194 }
sqian11b7a0e2018-12-05 18:48:28 -08007195 }
sqian854d44b2018-12-12 16:48:18 -08007196 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
sqianc5eccab2018-10-19 18:46:41 -07007200 }
7201
7202 @Override
sqian8c685422019-02-22 15:55:18 -08007203 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007204 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007205 if (!exactMatch) {
7206 TelephonyPermissions
7207 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007208 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007209 }
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
sqian854d44b2018-12-12 16:48:18 -08007212 for (Phone phone: PhoneFactory.getPhones()) {
7213 if (phone.getEmergencyNumberTracker() != null
7214 && phone.getEmergencyNumberTracker() != null) {
7215 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7216 number, exactMatch)) {
7217 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007218 }
7219 }
sqian11b7a0e2018-12-05 18:48:28 -08007220 }
7221 return false;
7222 } finally {
7223 Binder.restoreCallingIdentity(identity);
7224 }
7225 }
7226
sqianf4ca7ed2019-01-15 18:32:07 -08007227 /**
7228 * Update emergency number list for test mode.
7229 */
7230 @Override
7231 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7232 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7233 "updateEmergencyNumberListTestMode");
7234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 for (Phone phone: PhoneFactory.getPhones()) {
7238 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7239 if (tracker != null) {
7240 tracker.executeEmergencyNumberTestModeCommand(action, num);
7241 }
7242 }
7243 } finally {
7244 Binder.restoreCallingIdentity(identity);
7245 }
7246 }
7247
7248 /**
7249 * Get the full emergency number list for test mode.
7250 */
7251 @Override
7252 public List<String> getEmergencyNumberListTestMode() {
7253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7254 "getEmergencyNumberListTestMode");
7255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 Set<String> emergencyNumbers = new HashSet<>();
7259 for (Phone phone: PhoneFactory.getPhones()) {
7260 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7261 if (tracker != null) {
7262 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7263 emergencyNumbers.add(num.getNumber());
7264 }
7265 }
7266 }
7267 return new ArrayList<>(emergencyNumbers);
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270 }
7271 }
7272
chen xud6b45bd2018-10-30 22:27:10 -07007273 @Override
7274 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7275 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7276 Phone phone = getPhone(subId);
7277 if (phone == null) {
7278 return null;
7279 }
7280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 UiccProfile profile = UiccController.getInstance()
7283 .getUiccProfileForPhone(phone.getPhoneId());
7284 if (profile != null) {
7285 return profile.getCertsFromCarrierPrivilegeAccessRules();
7286 }
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 return null;
7291 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007292
7293 /**
7294 * Enable or disable a modem stack.
7295 */
7296 @Override
7297 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7298 enforceModifyPermission();
7299
7300 final long identity = Binder.clearCallingIdentity();
7301 try {
7302 Phone phone = PhoneFactory.getPhone(slotIndex);
7303 if (phone == null) {
7304 return false;
7305 } else {
7306 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7307 }
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310 }
7311 }
Michelecea4cf22018-12-21 15:00:11 -08007312
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007313 /**
7314 * Whether a modem stack is enabled or not.
7315 */
7316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007317 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7318 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007319 Phone phone = PhoneFactory.getPhone(slotIndex);
7320 if (phone == null) return false;
7321
7322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007323 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7324 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007325 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7326 }
7327
7328 final long identity = Binder.clearCallingIdentity();
7329 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007330 try {
7331 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7332 } catch (NoSuchElementException ex) {
7333 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7334 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
7338 }
7339
Michelecea4cf22018-12-21 15:00:11 -08007340 @Override
Michele0ea7d782019-03-19 14:58:42 -07007341 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007342 enforceModifyPermission();
7343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007347 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007348 .commit();
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 }
7353
7354 @Override
Michele0ea7d782019-03-19 14:58:42 -07007355 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007356 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007358 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7359 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007360 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007361 }
Michelecea4cf22018-12-21 15:00:11 -08007362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
Michele0ea7d782019-03-19 14:58:42 -07007365 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
7368 }
7369 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007370
Michele0ea7d782019-03-19 14:58:42 -07007371 @TelephonyManager.IsMultiSimSupportedResult
7372 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007373 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7374 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7375 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007376 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7377 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007378 }
7379 // Check if the hardware supports multisim functionality. If usage of multisim is not
7380 // supported by the modem, indicate that it is restricted.
7381 PhoneCapability staticCapability =
7382 mPhoneConfigurationManager.getStaticPhoneCapability();
7383 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007384 loge("isMultiSimSupportedInternal: no static configuration available");
7385 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007386 }
7387 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007388 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7389 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007390 }
7391 // Check if support of multiple SIMs is restricted by carrier
7392 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007393 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007394 }
7395
Michele0ea7d782019-03-19 14:58:42 -07007396 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007397 }
7398
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007399 /**
7400 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007401 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7402 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7403 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007404 * @param numOfSims number of active sims we want to switch to
7405 */
7406 @Override
7407 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007408 if (numOfSims == 1) {
7409 enforceModifyPermission();
7410 } else {
7411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7412 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7413 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007414 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007415
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007416 try {
Michele30b57b22019-03-01 12:01:14 -08007417 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007418 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007419 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7420 return;
7421 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007422 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
7426 }
7427
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007428 @Override
7429 public boolean isApplicationOnUicc(int subId, int appType) {
7430 enforceReadPrivilegedPermission("isApplicationOnUicc");
7431 Phone phone = getPhone(subId);
7432 if (phone == null) {
7433 return false;
7434 }
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
7437 UiccCard uiccCard = phone.getUiccCard();
7438 if (uiccCard == null) {
7439 return false;
7440 }
7441 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7442 if (uiccProfile == null) {
7443 return false;
7444 }
7445 if (TelephonyManager.APPTYPE_SIM <= appType
7446 && appType <= TelephonyManager.APPTYPE_ISIM) {
7447 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7448 }
7449 return false;
7450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 }
7454
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007455 /**
chen xub4baa772019-04-03 10:23:41 -07007456 * Get whether making changes to modem configurations will trigger reboot.
7457 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007458 */
7459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7461 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007463 mApp, subId, callingPackage, callingFeatureId,
7464 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007465 return false;
7466 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
7473 }
7474
Nathan Harold29f5f052019-02-15 13:41:57 -08007475 private void updateModemStateMetrics() {
7476 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7477 // TODO: check the state for each modem if the api is ready.
7478 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7479 }
7480
Pengquan Meng3889a572019-01-23 11:16:29 -08007481 @Override
7482 public int[] getSlotsMapping() {
7483 enforceReadPrivilegedPermission("getSlotsMapping");
7484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7488 // All logical slots should have a mapping to a physical slot.
7489 int[] logicalSlotsMapping = new int[phoneCount];
7490 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7491 for (int i = 0; i < slotInfos.length; i++) {
7492 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7493 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7494 }
7495 }
7496 return logicalSlotsMapping;
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
7500 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007501
7502 /**
7503 * Get the IRadio HAL Version
7504 */
7505 @Override
7506 public int getRadioHalVersion() {
7507 Phone phone = getDefaultPhone();
7508 if (phone == null) return -1;
7509 HalVersion hv = phone.getHalVersion();
7510 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7511 return hv.major * 100 + hv.minor;
7512 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007513
7514 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007515 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7516 * corresponding network requests on a subId.
7517 *
7518 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007519 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007520 * 2) APN is un-metered for this subscription, or
7521 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7522 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7523 *
7524 * @return whether data is allowed for a apn type.
7525 *
7526 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007527 */
7528 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007529 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007530 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7531 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007532
7533 // Now that all security checks passes, perform the operation as ourselves.
7534 final long identity = Binder.clearCallingIdentity();
7535 try {
7536 Phone phone = getPhone(subId);
7537 if (phone == null) return false;
7538
Jack Yu41407ee2019-05-13 16:54:09 -07007539 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007540 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
7544 }
7545
7546 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007547 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007548 enforceReadPrivilegedPermission("isApnMetered");
7549
7550 // Now that all security checks passes, perform the operation as ourselves.
7551 final long identity = Binder.clearCallingIdentity();
7552 try {
7553 Phone phone = getPhone(subId);
7554 if (phone == null) return true; // By default return true.
7555
Jack Yu41407ee2019-05-13 16:54:09 -07007556 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
7560 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007561
7562 @Override
7563 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7564 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7565 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7566 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7567 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7568 }
7569 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7570 Intent intent = new Intent();
7571 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7572 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7573 // Bring up choose default SMS subscription dialog right now
7574 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7575 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7576 mApp.startActivity(intent);
7577 }
chen xud5ca2d52019-05-28 15:20:57 -07007578
7579 @Override
7580 public String getMmsUAProfUrl(int subId) {
7581 //TODO investigate if this API should require proper permission check in R b/133791609
7582 final long identity = Binder.clearCallingIdentity();
7583 try {
7584 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7585 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
7588 }
7589 }
7590
7591 @Override
7592 public String getMmsUserAgent(int subId) {
7593 //TODO investigate if this API should require proper permission check in R b/133791609
7594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7597 .getString(com.android.internal.R.string.config_mms_user_agent);
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
7600 }
7601 }
Jack Yub07d4972019-05-28 16:12:25 -07007602
7603 @Override
7604 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7605 enforceModifyPermission();
7606
7607 // Now that all security checks passes, perform the operation as ourselves.
7608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 Phone phone = getPhone(subId);
7611 if (phone == null) return false;
7612
7613 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
7617 }
7618
7619 @Override
7620 public boolean isDataAllowedInVoiceCall(int subId) {
7621 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7622
7623 // Now that all security checks passes, perform the operation as ourselves.
7624 final long identity = Binder.clearCallingIdentity();
7625 try {
7626 Phone phone = getPhone(subId);
7627 if (phone == null) return false;
7628
7629 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
7633 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007634
7635 /**
7636 * Updates whether conference event pacakge handling is enabled.
7637 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7638 * otherwise.
7639 */
7640 @Override
7641 public void setCepEnabled(boolean isCepEnabled) {
7642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7643
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7647 for (Phone phone : PhoneFactory.getPhones()) {
7648 Phone defaultPhone = phone.getImsPhone();
7649 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7650 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7651 ImsPhoneCallTracker imsPhoneCallTracker =
7652 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7653 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7654 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7655 + imsPhone.getMsisdn());
7656 }
7657 }
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007662}